This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 224328
Collapse All | Expand All

(-)a/api.search/apichanges.xml (+51 lines)
Lines 105-110 Link Here
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
106
107
    <changes>
107
    <changes>
108
        <change id="SearchPattern_MatchType">
109
            <api name="api.search"/>
110
            <summary>Search pattern supports three match types (literal, basic wildcards, regexp)</summary>
111
            <version major="1" minor="11"/>
112
            <date day="29" month="1" year="2013"/>
113
            <author login="jhavlin"/>
114
            <compatibility addition="yes"/>
115
            <description>
116
                <p>
117
                    Before, the search pattern distinguished two match types:
118
                    Regular Expression and Standard. The standard meant that the
119
                    text was searched literally in editor search, and that the
120
                    searched text could contain basic wildcards (* and ?) in
121
                    Find in Projects.
122
                </p>
123
                <p>
124
                    Now, the Search pattern can specify exact match type:
125
                    Regular Expression, Basic Wildcards and Literal. Basic
126
                    wildcards are not supported by Editor search, but the
127
                    fallback to Literal Search is transparent for the editor.
128
                </p>
129
                <p>
130
                    To support extra match types, a few parts have to be added
131
                    to the API:
132
                </p>
133
                <ul>
134
                    <li>Enumeration SearchPattern.MatchType which contains
135
                        all supported match types
136
                    </li>
137
                    <li>Method SearchPattern.create(String searchExpression,
138
                        boolean wholeWords, boolean matchCase,
139
                        MatchType matchType)
140
                    </li>
141
                    <li>Method SearchPattern.getMatchType() and
142
                        SearchPattern.changeMatchType(MatchType)
143
                    </li>
144
                    <li>Enumeration SearchPatternController.MultiOption for
145
                        listing SearchPattern properties that can be bound
146
                        to  combo boxes.
147
                    </li>
148
                    <li>Method SearchPatternController.bind(MultiOption,
149
                        JComboBox) for binding SearchPattern properties to
150
                        combo boxes.
151
                    </li>
152
                </ul>
153
            </description>
154
            <class package="org.netbeans.api.search" name="SearchPattern"/>
155
            <class package="org.netbeans.api.search.ui" name="SearchPatternController"/>
156
            <issue number="224328"/>
157
        </change>
158
108
        <change id="SearchScopeDefinition_getIcon">
159
        <change id="SearchScopeDefinition_getIcon">
109
            <api name="api.search"/>
160
            <api name="api.search"/>
110
            <summary>Added method getIcon to class SearchScopeDefinition</summary>
161
            <summary>Added method getIcon to class SearchScopeDefinition</summary>
(-)a/api.search/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.search
2
OpenIDE-Module: org.netbeans.api.search
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/search/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/search/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.10
4
OpenIDE-Module-Specification-Version: 1.11
5
5
(-)a/api.search/src/org/netbeans/api/search/SearchPattern.java (-16 / +120 lines)
Lines 43-48 Link Here
43
 */
43
 */
44
package org.netbeans.api.search;
44
package org.netbeans.api.search;
45
45
46
import org.openide.util.NbBundle;
47
46
/**
48
/**
47
 * Pattern describes the search conditions
49
 * Pattern describes the search conditions
48
 *
50
 *
Lines 51-56 Link Here
51
public final class SearchPattern {
53
public final class SearchPattern {
52
54
53
    /**
55
    /**
56
     * Specifies how the pattern is matched to the searched text.
57
     *
58
     * Please note that more items can be added to the enum in the future.
59
     *
60
     * @since api.search/1.11
61
     */
62
    @NbBundle.Messages({
63
        "LBL_MatchType_Literal=Literal",
64
        "LBL_MatchType_Basic_Wildcards=Basic Wildcards",
65
        "LBL_MatchType_Regular_Expression=Regular Expression"
66
    })
67
    public static enum MatchType {
68
69
        /**
70
         * Match the pattern literally.
71
         */
72
        LITERAL(Bundle.LBL_MatchType_Literal(), 'r'),
73
        /**
74
         * The pattern can contain basic wildcards, star (*) for any string and
75
         * questionaire (?) for any character. The escape character for these
76
         * wildcards is backslash (\).
77
         */
78
        BASIC(Bundle.LBL_MatchType_Basic_Wildcards(), 'B'),
79
        /**
80
         * The pattern follows java.util.regex.Pattern syntax.
81
         */
82
        REGEXP(Bundle.LBL_MatchType_Regular_Expression(), 'R');
83
        private String displayName;
84
        private char canonicalPatternFlag;
85
86
        private MatchType(String displayName, char canonicalPatternFlag) {
87
            this.displayName = displayName;
88
            this.canonicalPatternFlag = canonicalPatternFlag;
89
        }
90
91
        @Override
92
        public String toString() {
93
            return displayName;
94
        }
95
96
        private char getCanonicalPatternFlag() {
97
            return canonicalPatternFlag;
98
        }
99
100
        private static MatchType fromCanonicalPatternFlag(char ch) {
101
            switch (ch) {
102
                case 'R':
103
                    return REGEXP;
104
                case 'r':
105
                    return LITERAL;
106
                case 'B':
107
                    return BASIC;
108
                default:
109
                    return LITERAL;
110
            }
111
        }
112
    }
113
114
    /**
54
     * SearchExpression - a text to search
115
     * SearchExpression - a text to search
55
     */
116
     */
56
    private String searchExpression;
117
    private String searchExpression;
Lines 63-71 Link Here
63
     */
124
     */
64
    private boolean matchCase;
125
    private boolean matchCase;
65
    /**
126
    /**
66
     * if true, regular expression search was performed
127
     * match type of this pattern
67
     */
128
     */
68
    private boolean regExp;
129
    private MatchType matchType;
69
130
70
    /**
131
    /**
71
     * Creates a new instance of SearchPattern
132
     * Creates a new instance of SearchPattern
Lines 76-86 Link Here
76
     * @param regExp if true, regular expression search was performed
137
     * @param regExp if true, regular expression search was performed
77
     */
138
     */
78
    private SearchPattern(String searchExpression, boolean wholeWords,
139
    private SearchPattern(String searchExpression, boolean wholeWords,
79
            boolean matchCase, boolean regExp) {
140
            boolean matchCase, MatchType matchType) {
80
        this.searchExpression = searchExpression;
141
        this.searchExpression = searchExpression;
81
        this.wholeWords = wholeWords;
142
        this.wholeWords = wholeWords;
82
        this.matchCase = matchCase;
143
        this.matchCase = matchCase;
83
        this.regExp = regExp;
144
        this.matchType = matchType;
84
    }
145
    }
85
146
86
    /**
147
    /**
Lines 94-100 Link Here
94
     */
155
     */
95
    public static SearchPattern create(String searchExpression, boolean wholeWords,
156
    public static SearchPattern create(String searchExpression, boolean wholeWords,
96
            boolean matchCase, boolean regExp) {
157
            boolean matchCase, boolean regExp) {
97
        return new SearchPattern(searchExpression, wholeWords, matchCase, regExp);
158
        return new SearchPattern(searchExpression, wholeWords, matchCase,
159
                regExp ? MatchType.REGEXP : MatchType.LITERAL);
160
    }
161
162
    /**
163
     * Creates a new SearchPattern in accordance with given parameters
164
     *
165
     * @param searchExpression non-null String of a searched text
166
     * @param wholeWords if true, only whole words were searched
167
     * @param matchCase if true, case sensitive search was preformed
168
     * @param matchType match type
169
     * @return a new SearchPattern in accordance with given parameters
170
     *
171
     * @since api.search/1.11
172
     */
173
    public static SearchPattern create(String searchExpression,
174
            boolean wholeWords, boolean matchCase, MatchType matchType) {
175
        return new SearchPattern(searchExpression, wholeWords, matchCase,
176
                matchType);
98
    }
177
    }
99
178
100
    /**
179
    /**
Lines 123-129 Link Here
123
     * @return true if the regExp parameter was used during search performing
202
     * @return true if the regExp parameter was used during search performing
124
     */
203
     */
125
    public boolean isRegExp() {
204
    public boolean isRegExp() {
126
        return regExp;
205
        return matchType == MatchType.REGEXP;
206
    }
207
208
    /**
209
     * Get type of this pattern.
210
     *
211
     * @since api.search/1.11
212
     */
213
    public MatchType getMatchType() {
214
        return matchType;
127
    }
215
    }
128
216
129
    @Override
217
    @Override
Lines 135-141 Link Here
135
        return (this.searchExpression.equals(sp.getSearchExpression())
223
        return (this.searchExpression.equals(sp.getSearchExpression())
136
                && this.wholeWords == sp.isWholeWords()
224
                && this.wholeWords == sp.isWholeWords()
137
                && this.matchCase == sp.isMatchCase()
225
                && this.matchCase == sp.isMatchCase()
138
                && this.regExp == sp.isRegExp());
226
                && this.matchType == sp.matchType);
139
    }
227
    }
140
228
141
    @Override
229
    @Override
Lines 143-149 Link Here
143
        int result = 17;
231
        int result = 17;
144
        result = 37 * result + (this.wholeWords ? 1 : 0);
232
        result = 37 * result + (this.wholeWords ? 1 : 0);
145
        result = 37 * result + (this.matchCase ? 1 : 0);
233
        result = 37 * result + (this.matchCase ? 1 : 0);
146
        result = 37 * result + (this.regExp ? 1 : 0);
234
        result = 37 * result + (this.matchType.hashCode());
147
        result = 37 * result + this.searchExpression.hashCode();
235
        result = 37 * result + this.searchExpression.hashCode();
148
        return result;
236
        return result;
149
    }
237
    }
Lines 160-166 Link Here
160
            return this;
248
            return this;
161
        } else {
249
        } else {
162
            return SearchPattern.create(expression, wholeWords,
250
            return SearchPattern.create(expression, wholeWords,
163
                    matchCase, regExp);
251
                    matchCase, matchType);
164
        }
252
        }
165
    }
253
    }
166
254
Lines 174-180 Link Here
174
            return this;
262
            return this;
175
        } else {
263
        } else {
176
            return SearchPattern.create(searchExpression, wholeWords,
264
            return SearchPattern.create(searchExpression, wholeWords,
177
                    matchCase, regExp);
265
                    matchCase, matchType);
178
        }
266
        }
179
    }
267
    }
180
268
Lines 188-194 Link Here
188
            return this;
276
            return this;
189
        } else {
277
        } else {
190
            return SearchPattern.create(searchExpression, wholeWords,
278
            return SearchPattern.create(searchExpression, wholeWords,
191
                    matchCase, regExp);
279
                    matchCase, matchType);
192
        }
280
        }
193
    }
281
    }
194
282
Lines 198-214 Link Here
198
     *
286
     *
199
     */
287
     */
200
    public SearchPattern changeRegExp(boolean regExp) {
288
    public SearchPattern changeRegExp(boolean regExp) {
201
        if (this.regExp == regExp) {
289
        if (this.isRegExp() == regExp) {
202
            return this;
290
            return this;
203
        } else {
291
        } else {
204
            return SearchPattern.create(searchExpression, wholeWords,
292
            return SearchPattern.create(searchExpression, wholeWords,
205
                    matchCase, regExp);
293
                    matchCase, regExp);
206
        }
294
        }
207
    }
295
    }
208
    
296
297
    /**
298
     * Create new instance with "match type" set to passed value, and other
299
     * values copied from this instance.
300
     *
301
     * @since api.search/1.11
302
     */
303
    public SearchPattern changeMatchType(MatchType matchType) {
304
        if (this.matchType == matchType) {
305
            return this;
306
        } else {
307
            return SearchPattern.create(searchExpression, wholeWords, matchCase,
308
                    matchType);
309
        }
310
    }
311
209
    String toCanonicalString() {
312
    String toCanonicalString() {
210
        char m = isMatchCase() ? 'M' : 'm';
313
        char m = isMatchCase() ? 'M' : 'm';
211
        char r = isRegExp() ? 'R' : 'r';
314
        char r = matchType.getCanonicalPatternFlag();
212
        char w = isWholeWords() ? 'W' : 'w';
315
        char w = isWholeWords() ? 'W' : 'w';
213
        return "" + m + r + w + "-" + getSearchExpression(); //NOI18N
316
        return "" + m + r + w + "-" + getSearchExpression(); //NOI18N
214
    }
317
    }
Lines 223-232 Link Here
223
            return null;
326
            return null;
224
        }
327
        }
225
        boolean matchCase = Character.isUpperCase(canonicalString.charAt(0));
328
        boolean matchCase = Character.isUpperCase(canonicalString.charAt(0));
226
        boolean regExp = Character.isUpperCase(canonicalString.charAt(1));
329
        MatchType matchType = MatchType.fromCanonicalPatternFlag(
330
                canonicalString.charAt(1));
227
        boolean wholeWords = Character.isUpperCase(canonicalString.charAt(2));
331
        boolean wholeWords = Character.isUpperCase(canonicalString.charAt(2));
228
        String findWhat = canonicalString.substring(4);
332
        String findWhat = canonicalString.substring(4);
229
        return new SearchPattern(findWhat, wholeWords, matchCase, regExp);
333
        return new SearchPattern(findWhat, wholeWords, matchCase, matchType);
230
    }
334
    }
231
335
232
}
336
}
(-)a/api.search/src/org/netbeans/api/search/ui/ScopeOptionsController.java (-1 / +2 lines)
Lines 153-159 Link Here
153
        if (searchAndReplace) {
153
        if (searchAndReplace) {
154
            jp.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
154
            jp.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
155
            jp.add(ignoreListOptionPanel);
155
            jp.add(ignoreListOptionPanel);
156
            jp.add(chkFileNameRegex);
156
            jp.add(new CheckBoxWithButtonPanel(
157
                    chkFileNameRegex, btnTestFileNamePattern));
157
            jp.setMaximumSize(jp.getMinimumSize());
158
            jp.setMaximumSize(jp.getMinimumSize());
158
        } else {
159
        } else {
159
            FormLayoutHelper flh = new FormLayoutHelper(jp,
160
            FormLayoutHelper flh = new FormLayoutHelper(jp,
(-)a/api.search/src/org/netbeans/api/search/ui/SearchPatternController.java (-2 / +92 lines)
Lines 60-65 Link Here
60
import org.netbeans.api.annotations.common.NullAllowed;
60
import org.netbeans.api.annotations.common.NullAllowed;
61
import org.netbeans.api.search.SearchHistory;
61
import org.netbeans.api.search.SearchHistory;
62
import org.netbeans.api.search.SearchPattern;
62
import org.netbeans.api.search.SearchPattern;
63
import org.netbeans.api.search.SearchPattern.MatchType;
63
import org.netbeans.modules.search.FindDialogMemory;
64
import org.netbeans.modules.search.FindDialogMemory;
64
import org.netbeans.modules.search.ui.PatternChangeListener;
65
import org.netbeans.modules.search.ui.PatternChangeListener;
65
import org.netbeans.modules.search.ui.ShorteningCellRenderer;
66
import org.netbeans.modules.search.ui.ShorteningCellRenderer;
Lines 84-93 Link Here
84
    public enum Option {
85
    public enum Option {
85
        MATCH_CASE, WHOLE_WORDS, REGULAR_EXPRESSION
86
        MATCH_CASE, WHOLE_WORDS, REGULAR_EXPRESSION
86
    }
87
    }
88
89
    /**
90
     * Options of search patterns that are not boolean, but can have more than
91
     * two values, e.g. {@link MatchType}.
92
     *
93
     * Please note that more items can be added to the enum in the future.
94
     *
95
     * @since api.search/1.11
96
     */
97
    public enum MultiOption {
98
99
        MATCH_TYPE
100
    }
101
87
    private final Map<Option, AbstractButton> bindings =
102
    private final Map<Option, AbstractButton> bindings =
88
            new EnumMap<Option, AbstractButton>(Option.class);
103
            new EnumMap<Option, AbstractButton>(Option.class);
104
    private final Map<MultiOption, JComboBox> comboBindings =
105
            new EnumMap<MultiOption, JComboBox>(MultiOption.class);
89
    private final Map<Option, Boolean> options =
106
    private final Map<Option, Boolean> options =
90
            new EnumMap<Option, Boolean>(Option.class);
107
            new EnumMap<Option, Boolean>(Option.class);
108
    private final Map<MultiOption, Object> multiOptions =
109
            new EnumMap<MultiOption, Object>(MultiOption.class);
91
    private final ItemListener listener;
110
    private final ItemListener listener;
92
    private boolean valid;
111
    private boolean valid;
93
    private Color defaultTextColor = null;
112
    private Color defaultTextColor = null;
Lines 142-150 Link Here
142
                                break;
161
                                break;
143
                        }
162
                        }
144
                    }
163
                    }
164
                    for (Map.Entry<MultiOption, JComboBox> be
165
                            : comboBindings.entrySet()) {
166
                        switch (be.getKey()) {
167
                            case MATCH_TYPE:
168
                                be.getValue().setSelectedItem(sp.getMatchType());
169
                                break;
170
                        }
171
                    }
145
                    options.put(Option.MATCH_CASE, sp.isMatchCase());
172
                    options.put(Option.MATCH_CASE, sp.isMatchCase());
146
                    options.put(Option.WHOLE_WORDS, sp.isWholeWords());
173
                    options.put(Option.WHOLE_WORDS, sp.isWholeWords());
147
                    options.put(Option.REGULAR_EXPRESSION, sp.isRegExp());
174
                    options.put(Option.REGULAR_EXPRESSION, sp.isRegExp());
175
                    multiOptions.put(MultiOption.MATCH_TYPE, sp.getMatchType());
148
                }
176
                }
149
            }
177
            }
150
        });
178
        });
Lines 225-230 Link Here
225
            button.setSelected(value);
253
            button.setSelected(value);
226
        }
254
        }
227
        if (option == Option.REGULAR_EXPRESSION) {
255
        if (option == Option.REGULAR_EXPRESSION) {
256
            if ((getOption(MultiOption.MATCH_TYPE) == MatchType.REGEXP)
257
                    != value) {
258
                setOption(MultiOption.MATCH_TYPE,
259
                        value ? MatchType.REGEXP : MatchType.LITERAL);
260
            }
261
            updateValidity();
262
        }
263
        fireChange();
264
    }
265
266
    /**
267
     * Get current value of an option of the search pattern.
268
     */
269
    private Object getOption(MultiOption option) {
270
        Parameters.notNull("option", option);                           //NOI18N
271
        return multiOptions.get(option);
272
    }
273
274
    /**
275
     * Set value of a search pattern option. The correct item in corresponding
276
     * combo box will be selected accordingly.
277
     */
278
    private void setOption(MultiOption option, Object value) {
279
        Parameters.notNull("option", option);                           //NOI18N
280
        multiOptions.put(option, value);
281
        JComboBox combo = comboBindings.get(option);
282
        if (combo != null && combo.getSelectedItem() != value) {
283
            combo.setSelectedItem(value);
284
        }
285
        if (option == MultiOption.MATCH_TYPE) {
286
            if (getOption(Option.REGULAR_EXPRESSION)
287
                    != (MatchType.REGEXP == value)) {
288
                setOption(Option.REGULAR_EXPRESSION, value == MatchType.REGEXP);
289
            }
228
            updateValidity();
290
            updateValidity();
229
        }
291
        }
230
        fireChange();
292
        fireChange();
Lines 237-243 Link Here
237
        return SearchPattern.create(getText(),
299
        return SearchPattern.create(getText(),
238
                getOption(Option.WHOLE_WORDS),
300
                getOption(Option.WHOLE_WORDS),
239
                getOption(Option.MATCH_CASE),
301
                getOption(Option.MATCH_CASE),
240
                getOption(Option.REGULAR_EXPRESSION));
302
                (MatchType) getOption(MultiOption.MATCH_TYPE));
241
    }
303
    }
242
304
243
    /**
305
    /**
Lines 248-254 Link Here
248
        setText(searchPattern.getSearchExpression());
310
        setText(searchPattern.getSearchExpression());
249
        setOption(Option.WHOLE_WORDS, searchPattern.isWholeWords());
311
        setOption(Option.WHOLE_WORDS, searchPattern.isWholeWords());
250
        setOption(Option.MATCH_CASE, searchPattern.isMatchCase());
312
        setOption(Option.MATCH_CASE, searchPattern.isMatchCase());
251
        setOption(Option.REGULAR_EXPRESSION, searchPattern.isRegExp());
313
        setOption(MultiOption.MATCH_TYPE, searchPattern.getMatchType());
252
    }
314
    }
253
315
254
    /**
316
    /**
Lines 278-283 Link Here
278
    }
340
    }
279
341
280
    /**
342
    /**
343
     * Bind a combo box to a SearchPattern option.
344
     *
345
     * @param option Option whose value the button should represent.
346
     * @param comboBox Combo box to control and display the option.
347
     *
348
     * @since api.search/1.11
349
     */
350
    public void bind(@NonNull final MultiOption option,
351
            @NonNull final JComboBox comboBox) {
352
        Parameters.notNull("option", option);                           //NOI18N
353
        Parameters.notNull("comboBox", comboBox);                       //NOI18N
354
355
        if (comboBindings.containsKey(option)) {
356
            throw new IllegalStateException(
357
                    "Already bound with option " + option);            // NOI18N
358
        }
359
360
        comboBindings.put(option, comboBox);
361
        comboBox.setSelectedItem(getOption(option));
362
        comboBox.addItemListener(new ItemListener() {
363
            @Override
364
            public void itemStateChanged(ItemEvent e) {
365
                setOption(option, comboBox.getSelectedItem());
366
            }
367
        });
368
    }
369
370
    /**
281
     * Unbind a button from a SearchPattern option.
371
     * Unbind a button from a SearchPattern option.
282
     */
372
     */
283
    public void unbind(@NonNull Option option, @NonNull AbstractButton button) {
373
    public void unbind(@NonNull Option option, @NonNull AbstractButton button) {
(-)a/api.search/src/org/netbeans/modules/search/BasicSearchCriteria.java (-5 / +9 lines)
Lines 51-56 Link Here
51
import javax.swing.event.ChangeListener;
51
import javax.swing.event.ChangeListener;
52
import org.netbeans.api.search.RegexpUtil;
52
import org.netbeans.api.search.RegexpUtil;
53
import org.netbeans.api.search.SearchPattern;
53
import org.netbeans.api.search.SearchPattern;
54
import org.netbeans.api.search.SearchPattern.MatchType;
54
import org.netbeans.api.search.SearchScopeOptions;
55
import org.netbeans.api.search.SearchScopeOptions;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
56
import org.openide.loaders.DataObject;
57
import org.openide.loaders.DataObject;
Lines 113-119 Link Here
113
         */
114
         */
114
        setCaseSensitive(template.searchPattern.isMatchCase());
115
        setCaseSensitive(template.searchPattern.isMatchCase());
115
        setWholeWords(template.searchPattern.isWholeWords());
116
        setWholeWords(template.searchPattern.isWholeWords());
116
        setRegexp(template.searchPattern.isRegExp());
117
        setMatchType(template.searchPattern.getMatchType());
117
        setPreserveCase(template.preserveCase);
118
        setPreserveCase(template.preserveCase);
118
        setSearchInArchives(template.searcherOptions.isSearchInArchives());
119
        setSearchInArchives(template.searcherOptions.isSearchInArchives());
119
        setSearchInGenerated(template.searcherOptions.isSearchInGenerated());
120
        setSearchInGenerated(template.searcherOptions.isSearchInGenerated());
Lines 243-250 Link Here
243
        return true;
244
        return true;
244
    }
245
    }
245
246
246
    boolean isRegexp() {
247
    /**
247
        return searchPattern.isRegExp();
248
     * Get text pattern match type.
249
     */
250
    MatchType getMatchType() {
251
        return searchPattern.getMatchType();
248
    }
252
    }
249
253
250
    boolean isPreserveCase() {
254
    boolean isPreserveCase() {
Lines 305-313 Link Here
305
        this.useIgnoreList = useIgnoreList;
309
        this.useIgnoreList = useIgnoreList;
306
    }
310
    }
307
311
308
    void setRegexp(boolean regexp) {
312
    void setMatchType(MatchType matchType) {
309
313
310
        searchPattern = searchPattern.changeRegExp(regexp);
314
        searchPattern = searchPattern.changeMatchType(matchType);
311
        updateTextPattern();
315
        updateTextPattern();
312
        replacePatternValid = validateReplacePattern();
316
        replacePatternValid = validateReplacePattern();
313
        updateUsability(true);
317
        updateUsability(true);
(-)a/api.search/src/org/netbeans/modules/search/BasicSearchForm.java (-34 / +113 lines)
Lines 69-83 Link Here
69
import org.netbeans.api.search.ReplacePattern;
69
import org.netbeans.api.search.ReplacePattern;
70
import org.netbeans.api.search.SearchHistory;
70
import org.netbeans.api.search.SearchHistory;
71
import org.netbeans.api.search.SearchPattern;
71
import org.netbeans.api.search.SearchPattern;
72
import org.netbeans.api.search.SearchPattern.MatchType;
72
import org.netbeans.api.search.provider.SearchInfo;
73
import org.netbeans.api.search.provider.SearchInfo;
73
import org.netbeans.api.search.ui.ComponentUtils;
74
import org.netbeans.api.search.ui.ComponentUtils;
74
import org.netbeans.api.search.ui.FileNameController;
75
import org.netbeans.api.search.ui.FileNameController;
75
import org.netbeans.api.search.ui.ScopeController;
76
import org.netbeans.api.search.ui.ScopeController;
76
import org.netbeans.api.search.ui.ScopeOptionsController;
77
import org.netbeans.api.search.ui.ScopeOptionsController;
77
import org.netbeans.api.search.ui.SearchPatternController;
78
import org.netbeans.api.search.ui.SearchPatternController;
79
import org.netbeans.api.search.ui.SearchPatternController.MultiOption;
78
import org.netbeans.api.search.ui.SearchPatternController.Option;
80
import org.netbeans.api.search.ui.SearchPatternController.Option;
79
import org.netbeans.modules.search.ui.CheckBoxWithButtonPanel;
80
import org.netbeans.modules.search.ui.FormLayoutHelper;
81
import org.netbeans.modules.search.ui.FormLayoutHelper;
82
import org.netbeans.modules.search.ui.LinkButtonPanel;
81
import org.netbeans.modules.search.ui.PatternChangeListener;
83
import org.netbeans.modules.search.ui.PatternChangeListener;
82
import org.netbeans.modules.search.ui.ShorteningCellRenderer;
84
import org.netbeans.modules.search.ui.ShorteningCellRenderer;
83
import org.netbeans.modules.search.ui.TextFieldFocusListener;
85
import org.netbeans.modules.search.ui.TextFieldFocusListener;
Lines 256-269 Link Here
256
        
258
        
257
        chkWholeWords = new JCheckBox();
259
        chkWholeWords = new JCheckBox();
258
        chkCaseSensitive = new JCheckBox();
260
        chkCaseSensitive = new JCheckBox();
259
        chkRegexp = new JCheckBox();
261
        textToFindType = new TextToFindTypeComboBox();
260
262
261
        TextPatternCheckBoxGroup.bind(
263
        TextPatternCheckBoxGroup.bind(
262
                chkCaseSensitive, chkWholeWords, chkRegexp, chkPreserveCase);
264
                chkCaseSensitive, chkWholeWords, textToFindType, chkPreserveCase);
263
265
264
        setMnemonics(searchAndReplace);
266
        setMnemonics(searchAndReplace);
265
        
267
        
266
        initFormPanel(searchAndReplace);
268
        initFormPanel(searchAndReplace);
269
        updateTextToFindInfo();
267
        this.add(formPanel);
270
        this.add(formPanel);
268
271
269
        /* find the editor components of combo-boxes: */
272
        /* find the editor components of combo-boxes: */
Lines 282-288 Link Here
282
285
283
        formPanel = new SearchFormPanel();
286
        formPanel = new SearchFormPanel();
284
        formPanel.addRow(lblTextToFind, cboxTextToFind.getComponent());
287
        formPanel.addRow(lblTextToFind, cboxTextToFind.getComponent());
285
        formPanel.addRow(new JLabel(), lblTextToFindHint);
288
        JPanel hintAndButtonPanel = initHintAndButtonPanel();
289
        formPanel.addRow(new JLabel(), hintAndButtonPanel);
286
        initContainingTextOptionsRow(searchAndReplace);
290
        initContainingTextOptionsRow(searchAndReplace);
287
        if (searchAndReplace) {
291
        if (searchAndReplace) {
288
            formPanel.addRow(lblReplacement, cboxReplacement);
292
            formPanel.addRow(lblReplacement, cboxReplacement);
Lines 304-316 Link Here
304
    private void initContainingTextOptionsRow(boolean searchAndReplace) {
308
    private void initContainingTextOptionsRow(boolean searchAndReplace) {
305
309
306
        JPanel jp = new JPanel();
310
        JPanel jp = new JPanel();
311
        JPanel typeWithLabelPanel = new JPanel();
312
        typeWithLabelPanel.setLayout(new BoxLayout(typeWithLabelPanel,
313
                BoxLayout.LINE_AXIS));
314
        JLabel typeLabel = new JLabel();
315
        typeLabel.setLabelFor(textToFindType);
316
        lclz(typeLabel, "BasicSearchForm.textToFindType.label.text");   //NOI18N
317
        typeLabel.setBorder(new EmptyBorder(0, 10, 0, 5));
318
        typeWithLabelPanel.add(typeLabel);
319
        typeWithLabelPanel.add(textToFindType);
307
        if (searchAndReplace) {
320
        if (searchAndReplace) {
308
            FormLayoutHelper flh = new FormLayoutHelper(jp,
321
            FormLayoutHelper flh = new FormLayoutHelper(jp,
309
                    FormLayoutHelper.DEFAULT_COLUMN,
322
                    FormLayoutHelper.DEFAULT_COLUMN,
310
                    FormLayoutHelper.DEFAULT_COLUMN);
323
                    FormLayoutHelper.DEFAULT_COLUMN);
311
            flh.addRow(chkCaseSensitive, chkPreserveCase);
324
            flh.addRow(chkCaseSensitive, chkPreserveCase);
312
            flh.addRow(chkWholeWords,
325
            flh.addRow(chkWholeWords, typeWithLabelPanel);
313
                    new CheckBoxWithButtonPanel(chkRegexp, btnTestTextToFind));
314
            jp.setMaximumSize(jp.getMinimumSize());
326
            jp.setMaximumSize(jp.getMinimumSize());
315
327
316
            formPanel.addRow(new JLabel(), jp);
328
            formPanel.addRow(new JLabel(), jp);
Lines 318-324 Link Here
318
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
330
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
319
            jp.add(chkCaseSensitive);
331
            jp.add(chkCaseSensitive);
320
            jp.add(chkWholeWords);
332
            jp.add(chkWholeWords);
321
            jp.add(new CheckBoxWithButtonPanel(chkRegexp, btnTestTextToFind));
333
            jp.add(typeWithLabelPanel);
322
            formPanel.addRow(new JLabel(), jp);
334
            formPanel.addRow(new JLabel(), jp);
323
        }
335
        }
324
    }
336
    }
Lines 336-344 Link Here
336
                UiUtils.getText(
348
                UiUtils.getText(
337
                "BasicSearchForm.chkCaseSensitive."                     //NOI18N
349
                "BasicSearchForm.chkCaseSensitive."                     //NOI18N
338
                + "AccessibleDescription"));                            //NOI18N
350
                + "AccessibleDescription"));                            //NOI18N
339
        chkRegexp.getAccessibleContext().setAccessibleDescription(
351
        textToFindType.getAccessibleContext().setAccessibleDescription(
340
                UiUtils.getText(
352
                UiUtils.getText(
341
                "BasicSearchForm.chkRegexp."                            //NOI18N
353
                "BasicSearchForm.textToFindType."                       //NOI18N
342
                + "AccessibleDescription"));                            //NOI18N
354
                + "AccessibleDescription"));                            //NOI18N
343
        chkWholeWords.getAccessibleContext().setAccessibleDescription(
355
        chkWholeWords.getAccessibleContext().setAccessibleDescription(
344
                UiUtils.getText(
356
                UiUtils.getText(
Lines 404-415 Link Here
404
                    new ReplacementPatternListener());
416
                    new ReplacementPatternListener());
405
        }
417
        }
406
        
418
        
407
        chkRegexp.addItemListener(this);
419
        textToFindType.addItemListener(this);
408
        cboxTextToFind.bind(Option.REGULAR_EXPRESSION, chkRegexp);
420
        cboxTextToFind.bind(MultiOption.MATCH_TYPE, textToFindType);
409
        cboxTextToFind.bind(Option.MATCH_CASE, chkCaseSensitive);
421
        cboxTextToFind.bind(Option.MATCH_CASE, chkCaseSensitive);
410
        cboxTextToFind.bind(Option.WHOLE_WORDS, chkWholeWords);
422
        cboxTextToFind.bind(Option.WHOLE_WORDS, chkWholeWords);
423
        textToFindType.addActionListener(new ActionListener() {
411
424
412
        boolean regexp = chkRegexp.isSelected();
425
            @Override
426
            public void actionPerformed(ActionEvent e) {
427
            }
428
        });
429
430
        boolean regexp = textToFindType.isRegexp();
413
        boolean caseSensitive = chkCaseSensitive.isSelected();
431
        boolean caseSensitive = chkCaseSensitive.isSelected();
414
        chkWholeWords.setEnabled(!regexp);
432
        chkWholeWords.setEnabled(!regexp);
415
        if (searchAndReplace) {
433
        if (searchAndReplace) {
Lines 448-454 Link Here
448
            public void stateChanged(ChangeEvent e) {
466
            public void stateChanged(ChangeEvent e) {
449
                SearchPattern sp = cboxTextToFind.getSearchPattern();
467
                SearchPattern sp = cboxTextToFind.getSearchPattern();
450
                searchCriteria.setTextPattern(sp.getSearchExpression());
468
                searchCriteria.setTextPattern(sp.getSearchExpression());
451
                searchCriteria.setRegexp(sp.isRegExp());
469
                searchCriteria.setMatchType(sp.getMatchType());
452
                searchCriteria.setWholeWords(sp.isWholeWords());
470
                searchCriteria.setWholeWords(sp.isWholeWords());
453
                searchCriteria.setCaseSensitive(sp.isMatchCase());
471
                searchCriteria.setCaseSensitive(sp.isMatchCase());
454
            }
472
            }
Lines 519-525 Link Here
519
537
520
        chkWholeWords.setSelected(memory.isWholeWords());
538
        chkWholeWords.setSelected(memory.isWholeWords());
521
        chkCaseSensitive.setSelected(memory.isCaseSensitive());
539
        chkCaseSensitive.setSelected(memory.isCaseSensitive());
522
        chkRegexp.setSelected(memory.isRegularExpression());
540
        textToFindType.setSelectedItem(memory.getMatchType());
523
541
524
        scopeSettingsPanel.setFileNameRegexp(memory.isFilePathRegex());
542
        scopeSettingsPanel.setFileNameRegexp(memory.isFilePathRegex());
525
        scopeSettingsPanel.setUseIgnoreList(memory.IsUseIgnoreList());
543
        scopeSettingsPanel.setUseIgnoreList(memory.IsUseIgnoreList());
Lines 535-541 Link Here
535
    private void setSearchCriteriaValues() {
553
    private void setSearchCriteriaValues() {
536
        searchCriteria.setWholeWords(chkWholeWords.isSelected());
554
        searchCriteria.setWholeWords(chkWholeWords.isSelected());
537
        searchCriteria.setCaseSensitive(chkCaseSensitive.isSelected());
555
        searchCriteria.setCaseSensitive(chkCaseSensitive.isSelected());
538
        searchCriteria.setRegexp(chkRegexp.isSelected());
556
        searchCriteria.setMatchType(textToFindType.getSelectedMatchType());
539
        searchCriteria.setFileNameRegexp(scopeSettingsPanel.isFileNameRegExp());
557
        searchCriteria.setFileNameRegexp(scopeSettingsPanel.isFileNameRegExp());
540
        searchCriteria.setUseIgnoreList(scopeSettingsPanel.isUseIgnoreList());
558
        searchCriteria.setUseIgnoreList(scopeSettingsPanel.isUseIgnoreList());
541
        searchCriteria.setSearchInArchives(
559
        searchCriteria.setSearchInArchives(
Lines 621-627 Link Here
621
    public void itemStateChanged(ItemEvent e) {
639
    public void itemStateChanged(ItemEvent e) {
622
        final ItemSelectable toggle = e.getItemSelectable();
640
        final ItemSelectable toggle = e.getItemSelectable();
623
        final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
641
        final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
624
        if (toggle == chkRegexp) {
642
        if (toggle == textToFindType) {
625
            if (cboxReplacement != null){
643
            if (cboxReplacement != null){
626
                updateReplacePatternColor();
644
                updateReplacePatternColor();
627
            }
645
            }
Lines 634-645 Link Here
634
    }
652
    }
635
653
636
    private void updateTextToFindInfo() {
654
    private void updateTextToFindInfo() {
637
        String bungleKey = (searchCriteria.isRegexp())
655
        String key;
638
                ? "BasicSearchForm.cboxTextToFind.info.re" //NOI18N
656
        switch (cboxTextToFind.getSearchPattern().getMatchType()) {
639
                : "BasicSearchForm.cboxTextToFind.info";   //NOI18N
657
            case LITERAL:
640
        String text = UiUtils.getText(bungleKey);
658
                key = "BasicSearchForm.cboxTextToFind.info.literal";    //NOI18N
659
                break;
660
            case BASIC:
661
                key = "BasicSearchForm.cboxTextToFind.info";            //NOI18N
662
                break;
663
            case REGEXP:
664
                key = "BasicSearchForm.cboxTextToFind.info.re";         //NOI18N
665
                break;
666
            default:
667
                key = "BasicSearchForm.cboxTextToFind.info";            //NOI18N
668
        }
669
        String text = UiUtils.getText(key);
641
        cboxTextToFind.getComponent().setToolTipText(text);
670
        cboxTextToFind.getComponent().setToolTipText(text);
642
        lblTextToFindHint.setText(text);
671
        lblTextToFindHint.setText(text);
672
        btnTestTextToFindPanel.setButtonEnabled(
673
                searchCriteria.getSearchPattern().isRegExp());
643
    }
674
    }
644
675
645
    private void updateFileNamePatternInfo() {
676
    private void updateFileNamePatternInfo() {
Lines 677-683 Link Here
677
        }
708
        }
678
        memory.setWholeWords(chkWholeWords.isSelected());
709
        memory.setWholeWords(chkWholeWords.isSelected());
679
        memory.setCaseSensitive(chkCaseSensitive.isSelected());
710
        memory.setCaseSensitive(chkCaseSensitive.isSelected());
680
        memory.setRegularExpression(chkRegexp.isSelected());
711
        memory.setMatchType(textToFindType.getSelectedMatchType());
681
        if (searchCriteria.isSearchAndReplace()) {
712
        if (searchCriteria.isSearchAndReplace()) {
682
            memory.setPreserveCase(chkPreserveCase.isSelected());
713
            memory.setPreserveCase(chkPreserveCase.isSelected());
683
        } else {
714
        } else {
Lines 733-742 Link Here
733
                "BasicSearchForm.lblFileNamePattern.text");             //NOI18N
764
                "BasicSearchForm.lblFileNamePattern.text");             //NOI18N
734
        lclz(chkWholeWords, "BasicSearchForm.chkWholeWords.text");      //NOI18N
765
        lclz(chkWholeWords, "BasicSearchForm.chkWholeWords.text");      //NOI18N
735
        lclz(chkCaseSensitive, "BasicSearchForm.chkCaseSensitive.text");//NOI18N
766
        lclz(chkCaseSensitive, "BasicSearchForm.chkCaseSensitive.text");//NOI18N
736
        lclz(chkRegexp, "BasicSearchForm.chkRegexp.text");              //NOI18N
767
737
        
738
        btnTestTextToFind.setText(UiUtils.getHtmlLink(
768
        btnTestTextToFind.setText(UiUtils.getHtmlLink(
739
                "BasicSearchForm.btnTestTextToFind.text"));             //NOI18N
769
                "BasicSearchForm.btnTestTextToFind.text"));             //NOI18N
770
        btnTestTextToFind.setToolTipText(UiUtils.getText(
771
                "BasicSearchForm.btnTestTextToFind.tooltip"));          //NOI18N
740
       
772
       
741
773
742
        if (searchAndReplace) {
774
        if (searchAndReplace) {
Lines 746-752 Link Here
746
        } else {
778
        } else {
747
          
779
          
748
        }
780
        }
749
        updateTextToFindInfo();
750
    }
781
    }
751
782
752
    private void lclz(AbstractButton ab, String msg) {
783
    private void lclz(AbstractButton ab, String msg) {
Lines 765-775 Link Here
765
    private FileNameController cboxFileNamePattern;
796
    private FileNameController cboxFileNamePattern;
766
    private JCheckBox chkWholeWords;
797
    private JCheckBox chkWholeWords;
767
    private JCheckBox chkCaseSensitive;
798
    private JCheckBox chkCaseSensitive;
768
    private JCheckBox chkRegexp;
799
    private TextToFindTypeComboBox textToFindType;
769
    private JCheckBox chkPreserveCase;
800
    private JCheckBox chkPreserveCase;
770
    private JTextComponent replacementPatternEditor;
801
    private JTextComponent replacementPatternEditor;
771
    protected SearchFormPanel formPanel;
802
    protected SearchFormPanel formPanel;
772
    private JButton btnTestTextToFind;
803
    private JButton btnTestTextToFind;
804
    private LinkButtonPanel btnTestTextToFindPanel;
773
    private JLabel lblTextToFind;
805
    private JLabel lblTextToFind;
774
    private JLabel lblTextToFindHint;
806
    private JLabel lblTextToFindHint;
775
    private ScopeController cboxScope;
807
    private ScopeController cboxScope;
Lines 782-787 Link Here
782
    private boolean invalidReplacePattern = false;
814
    private boolean invalidReplacePattern = false;
783
    private ScopeOptionsController scopeSettingsPanel;
815
    private ScopeOptionsController scopeSettingsPanel;
784
816
817
    private JPanel initHintAndButtonPanel() {
818
        btnTestTextToFindPanel = new LinkButtonPanel(btnTestTextToFind);
819
        btnTestTextToFindPanel.setButtonEnabled(
820
                searchCriteria.getSearchPattern().isRegExp());
821
        lblTextToFindHint.setMaximumSize(new Dimension(Integer.MAX_VALUE,
822
                (int) btnTestTextToFindPanel.getPreferredSize().getHeight()));
823
        JPanel hintAndButtonPanel = new JPanel();
824
        hintAndButtonPanel.setLayout(
825
                new BoxLayout(hintAndButtonPanel, BoxLayout.LINE_AXIS));
826
        hintAndButtonPanel.add(lblTextToFindHint);
827
        hintAndButtonPanel.add(btnTestTextToFindPanel);
828
        return hintAndButtonPanel;
829
    }
830
785
    /**
831
    /**
786
     * Form panel to which rows can be added.
832
     * Form panel to which rows can be added.
787
     */
833
     */
Lines 853-859 Link Here
853
899
854
        private JCheckBox matchCase;
900
        private JCheckBox matchCase;
855
        private JCheckBox wholeWords;
901
        private JCheckBox wholeWords;
856
        private JCheckBox regexp;
902
        private TextToFindTypeComboBox textToFindType;
857
        private JCheckBox preserveCase;
903
        private JCheckBox preserveCase;
858
        private boolean lastPreserveCaseValue;
904
        private boolean lastPreserveCaseValue;
859
        private boolean lastWholeWordsValue;
905
        private boolean lastWholeWordsValue;
Lines 861-879 Link Here
861
        private TextPatternCheckBoxGroup(
907
        private TextPatternCheckBoxGroup(
862
                JCheckBox matchCase,
908
                JCheckBox matchCase,
863
                JCheckBox wholeWords,
909
                JCheckBox wholeWords,
864
                JCheckBox regexp,
910
                TextToFindTypeComboBox textToFindType,
865
                JCheckBox preserveCase) {
911
                JCheckBox preserveCase) {
866
912
867
            this.matchCase = matchCase;
913
            this.matchCase = matchCase;
868
            this.wholeWords = wholeWords;
914
            this.wholeWords = wholeWords;
869
            this.regexp = regexp;
915
            this.textToFindType = textToFindType;
870
            this.preserveCase = preserveCase;
916
            this.preserveCase = preserveCase;
871
        }
917
        }
872
918
873
        private void initListeners() {
919
        private void initListeners() {
874
            this.matchCase.addItemListener(this);
920
            this.matchCase.addItemListener(this);
875
            this.wholeWords.addItemListener(this);
921
            this.wholeWords.addItemListener(this);
876
            this.regexp.addItemListener(this);
922
            this.textToFindType.addItemListener(this);
877
            if (this.preserveCase != null) {
923
            if (this.preserveCase != null) {
878
                this.preserveCase.addItemListener(this);
924
                this.preserveCase.addItemListener(this);
879
            }
925
            }
Lines 889-896 Link Here
889
        }
935
        }
890
936
891
        private void updateWholeWordsAllowed() {
937
        private void updateWholeWordsAllowed() {
892
            if (regexp.isSelected() == wholeWords.isEnabled()) {
938
            if (textToFindType.isRegexp() == wholeWords.isEnabled()) {
893
                if (regexp.isSelected()) {
939
                if (textToFindType.isRegexp()) {
894
                    lastWholeWordsValue = wholeWords.isSelected();
940
                    lastWholeWordsValue = wholeWords.isSelected();
895
                    wholeWords.setSelected(false);
941
                    wholeWords.setSelected(false);
896
                    wholeWords.setEnabled(false);
942
                    wholeWords.setEnabled(false);
Lines 906-912 Link Here
906
                return;
952
                return;
907
            }
953
            }
908
            if (preserveCase.isEnabled()
954
            if (preserveCase.isEnabled()
909
                    == (regexp.isSelected() || matchCase.isSelected())) {
955
                    == (textToFindType.isRegexp() || matchCase.isSelected())) {
910
                if (preserveCase.isEnabled()) {
956
                if (preserveCase.isEnabled()) {
911
                    lastPreserveCaseValue = preserveCase.isSelected();
957
                    lastPreserveCaseValue = preserveCase.isSelected();
912
                    preserveCase.setSelected(false);
958
                    preserveCase.setSelected(false);
Lines 923-936 Link Here
923
            ItemSelectable is = e.getItemSelectable();
969
            ItemSelectable is = e.getItemSelectable();
924
            if (is == matchCase) {
970
            if (is == matchCase) {
925
                matchCaseChanged();
971
                matchCaseChanged();
926
            } else if (is == regexp) {
972
            } else if (is == textToFindType) {
927
                regexpChanged();
973
                regexpChanged();
928
            }
974
            }
929
        }
975
        }
930
976
931
        static void bind(JCheckBox matchCase,
977
        static void bind(JCheckBox matchCase,
932
                JCheckBox wholeWords,
978
                JCheckBox wholeWords,
933
                JCheckBox regexp,
979
                TextToFindTypeComboBox regexp,
934
                JCheckBox preserveCase) {
980
                JCheckBox preserveCase) {
935
981
936
            TextPatternCheckBoxGroup tpcbg = new TextPatternCheckBoxGroup(
982
            TextPatternCheckBoxGroup tpcbg = new TextPatternCheckBoxGroup(
Lines 970-973 Link Here
970
            return replacePattern.getReplaceExpression();
1016
            return replacePattern.getReplaceExpression();
971
        }
1017
        }
972
    }
1018
    }
1019
1020
    private static class TextToFindTypeComboBox extends JComboBox {
1021
1022
        public TextToFindTypeComboBox() {
1023
            super(new Object[]{MatchType.LITERAL,
1024
                MatchType.BASIC, MatchType.REGEXP});
1025
        }
1026
1027
        public boolean isRegexp() {
1028
            return isSelected(MatchType.REGEXP);
1029
        }
1030
1031
        public boolean isBasic() {
1032
            return isSelected(MatchType.BASIC);
1033
        }
1034
1035
        public boolean isLiteral() {
1036
            return isSelected(MatchType.LITERAL);
1037
        }
1038
1039
        public boolean isSelected(MatchType type) {
1040
            return getSelectedItem() == type;
1041
        }
1042
1043
        private MatchType getSelectedMatchType() {
1044
            Object selected = getSelectedItem();
1045
            if (selected instanceof MatchType) {
1046
                return (MatchType) selected;
1047
            } else {
1048
                throw new IllegalStateException("MatchType expected");  //NOI18N
1049
            }
1050
        }
1051
    }
973
}
1052
}
(-)a/api.search/src/org/netbeans/modules/search/BasicSearchProvider.java (-1 / +1 lines)
Lines 338-344 Link Here
338
        bsc.setTextPattern(searchPattern.getSearchExpression());
338
        bsc.setTextPattern(searchPattern.getSearchExpression());
339
        bsc.setCaseSensitive(searchPattern.isMatchCase());
339
        bsc.setCaseSensitive(searchPattern.isMatchCase());
340
        bsc.setWholeWords(searchPattern.isWholeWords());
340
        bsc.setWholeWords(searchPattern.isWholeWords());
341
        bsc.setRegexp(searchPattern.isRegExp());
341
        bsc.setMatchType(searchPattern.getMatchType());
342
        if (preserveCase != null) {
342
        if (preserveCase != null) {
343
            bsc.setPreserveCase(preserveCase);
343
            bsc.setPreserveCase(preserveCase);
344
        }
344
        }
(-)a/api.search/src/org/netbeans/modules/search/Bundle.properties (-3 / +5 lines)
Lines 211-217 Link Here
211
BasicSearchForm.lblTextToFind.text=Containing &Text\:
211
BasicSearchForm.lblTextToFind.text=Containing &Text\:
212
212
213
BasicSearchForm.cboxTextToFind.info=(* \= any string, ? \= any character, \\ \= escape for * ?)
213
BasicSearchForm.cboxTextToFind.info=(* \= any string, ? \= any character, \\ \= escape for * ?)
214
BasicSearchForm.cboxTextToFind.info.re=(Use java.util.regex.Pattern regular expression syntax)
214
BasicSearchForm.cboxTextToFind.info.re=(Use java.util.regex.Pattern syntax)
215
BasicSearchForm.cboxTextToFind.info.literal=(The text will be used literally)
215
216
216
BasicSearchForm.lblReplacement.text=&Replace With\:
217
BasicSearchForm.lblReplacement.text=&Replace With\:
217
218
Lines 235-247 Link Here
235
236
236
BasicSearchForm.chkCaseSensitive.AccessibleDescription=Whether the fulltext search should be case-sensitive.
237
BasicSearchForm.chkCaseSensitive.AccessibleDescription=Whether the fulltext search should be case-sensitive.
237
238
238
BasicSearchForm.chkRegexp.text=Regular &Expression
239
BasicSearchForm.textToFindType.label.text=T&ype:
239
240
240
BasicSearchForm.chkPreserveCase.text=Preser&ve Case when Replacing
241
BasicSearchForm.chkPreserveCase.text=Preser&ve Case when Replacing
241
242
242
BasicSearchForm.chkPreserveCase.AccessibleDescription=Preserve case according to found instance of word.
243
BasicSearchForm.chkPreserveCase.AccessibleDescription=Preserve case according to found instance of word.
243
244
244
BasicSearchForm.chkRegexp.AccessibleDescription=If checked, the search pattern will be used as a regular expression.
245
BasicSearchForm.textToFindType.AccessibleDescription=Choose whether you want to use the Text to Find value as literal text, text with basic wildcards, or regular expression.
245
246
246
BasicSearchForm.chkArchives.text=Search in &Archives
247
BasicSearchForm.chkArchives.text=Search in &Archives
247
248
Lines 251-256 Link Here
251
BasicSearchForm.chkFileNameRegex.tooltip=Use regular expression for the file path
252
BasicSearchForm.chkFileNameRegex.tooltip=Use regular expression for the file path
252
253
253
BasicSearchForm.btnTestTextToFind.text=test
254
BasicSearchForm.btnTestTextToFind.text=test
255
BasicSearchForm.btnTestTextToFind.tooltip=Open window for testing of regular expressions
254
256
255
BasicSearchForm.btnTestFileNamePattern.text=test
257
BasicSearchForm.btnTestFileNamePattern.text=test
256
258
(-)a/api.search/src/org/netbeans/modules/search/FindDialogMemory.java (-9 / +15 lines)
Lines 48-53 Link Here
48
import java.util.Collections;
48
import java.util.Collections;
49
import java.util.List;
49
import java.util.List;
50
import java.util.prefs.Preferences;
50
import java.util.prefs.Preferences;
51
import org.netbeans.api.search.SearchPattern.MatchType;
51
import org.openide.util.NbBundle;
52
import org.openide.util.NbBundle;
52
import org.openide.util.NbPreferences;
53
import org.openide.util.NbPreferences;
53
54
Lines 89-97 Link Here
89
    private boolean preserveCase;
90
    private boolean preserveCase;
90
    
91
    
91
    /**
92
    /**
92
     * Storage of last used Regular Expression option.
93
     * Storage of last used search pattern match type.
93
     */
94
     */
94
    private boolean regularExpression;
95
    private MatchType matchType;
95
96
96
    /**
97
    /**
97
     * whether a full text pattern was used last time
98
     * whether a full text pattern was used last time
Lines 164-170 Link Here
164
    private static final String PROP_WHOLE_WORDS = "whole_words";  //NOI18N
165
    private static final String PROP_WHOLE_WORDS = "whole_words";  //NOI18N
165
    private static final String PROP_CASE_SENSITIVE = "case_sensitive";  //NOI18N
166
    private static final String PROP_CASE_SENSITIVE = "case_sensitive";  //NOI18N
166
    private static final String PROP_PRESERVE_CASE = "preserve_case";  //NOI18N
167
    private static final String PROP_PRESERVE_CASE = "preserve_case";  //NOI18N
167
    private static final String PROP_REGULAR_EXPRESSION = "regular_expression";  //NOI18N
168
    private static final String PROP_MATCH_TYPE = "match_type";  //NOI18N
168
    private static final String PROP_SCOPE_TYPE_ID = "scope_type_id"; //NOI18N
169
    private static final String PROP_SCOPE_TYPE_ID = "scope_type_id"; //NOI18N
169
    private static final String PROP_FILENAME_PATTERN_SPECIFIED = "filename_specified";  //NOI18N
170
    private static final String PROP_FILENAME_PATTERN_SPECIFIED = "filename_specified";  //NOI18N
170
    private static final String PROP_FILENAME_PATTERN_PREFIX = "filename_pattern_";  //NOI18N
171
    private static final String PROP_FILENAME_PATTERN_PREFIX = "filename_pattern_";  //NOI18N
Lines 204-210 Link Here
204
    private void load () {
205
    private void load () {
205
        wholeWords = prefs.getBoolean(PROP_WHOLE_WORDS, false);
206
        wholeWords = prefs.getBoolean(PROP_WHOLE_WORDS, false);
206
        caseSensitive = prefs.getBoolean(PROP_CASE_SENSITIVE, false);
207
        caseSensitive = prefs.getBoolean(PROP_CASE_SENSITIVE, false);
207
        regularExpression = prefs.getBoolean(PROP_REGULAR_EXPRESSION, false);
208
        try {
209
            String name = prefs.get(PROP_MATCH_TYPE, MatchType.BASIC.name());
210
            matchType = MatchType.valueOf(name);
211
        } catch (Exception e) {
212
            matchType = MatchType.BASIC;
213
        }
208
        preserveCase = prefs.getBoolean(PROP_PRESERVE_CASE, false);
214
        preserveCase = prefs.getBoolean(PROP_PRESERVE_CASE, false);
209
        scopeTypeId = prefs.get(PROP_SCOPE_TYPE_ID, "open projects");   //NOI18N
215
        scopeTypeId = prefs.get(PROP_SCOPE_TYPE_ID, "open projects");   //NOI18N
210
        fileNamePatternSpecified = prefs.getBoolean(PROP_FILENAME_PATTERN_SPECIFIED, false);
216
        fileNamePatternSpecified = prefs.getBoolean(PROP_FILENAME_PATTERN_SPECIFIED, false);
Lines 311-323 Link Here
311
        prefs.putBoolean(PROP_PRESERVE_CASE, preserveCase);
317
        prefs.putBoolean(PROP_PRESERVE_CASE, preserveCase);
312
    }
318
    }
313
    
319
    
314
    public boolean isRegularExpression() {
320
    public MatchType getMatchType() {
315
        return regularExpression;
321
        return matchType;
316
    }
322
    }
317
323
318
    public void setRegularExpression(boolean regularExpression) {
324
    public void setMatchType(MatchType matchType) {
319
        this.regularExpression = regularExpression;
325
        this.matchType = matchType;
320
        prefs.putBoolean(PROP_REGULAR_EXPRESSION, regularExpression);
326
        prefs.put(PROP_MATCH_TYPE, matchType.name());
321
    }
327
    }
322
328
323
    public String getScopeTypeId() {
329
    public String getScopeTypeId() {
(-)a/api.search/src/org/netbeans/modules/search/MatchingObject.java (-1 / +1 lines)
Lines 844-850 Link Here
844
            }
844
            }
845
845
846
            String replacedString = resultModel.basicCriteria.getReplaceExpr();
846
            String replacedString = resultModel.basicCriteria.getReplaceExpr();
847
            if (resultModel.basicCriteria.isRegexp()){
847
            if (resultModel.basicCriteria.getSearchPattern().isRegExp()){
848
                Matcher m = resultModel.basicCriteria.getTextPattern().matcher(matchedSubstring);
848
                Matcher m = resultModel.basicCriteria.getTextPattern().matcher(matchedSubstring);
849
                replacedString = m.replaceFirst(resultModel.basicCriteria.getReplaceString());
849
                replacedString = m.replaceFirst(resultModel.basicCriteria.getReplaceString());
850
            } else if (resultModel.basicCriteria.isPreserveCase()) {
850
            } else if (resultModel.basicCriteria.isPreserveCase()) {
(-)a/api.search/src/org/netbeans/modules/search/PatternSandbox.java (-1 / +1 lines)
Lines 477-483 Link Here
477
            this.regexp = regexp;
477
            this.regexp = regexp;
478
            this.matchCase = matchCase;
478
            this.matchCase = matchCase;
479
            initComponents();
479
            initComponents();
480
            searchCriteria.setRegexp(true);
480
            searchCriteria.setMatchType(SearchPattern.MatchType.REGEXP);
481
        }
481
        }
482
482
483
        @Override
483
        @Override
(-)a/api.search/src/org/netbeans/modules/search/RegexpMaker.java (-356 lines)
Lines 1-356 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
30
 */
31
32
package org.netbeans.modules.search;
33
34
import java.util.regex.Pattern;
35
36
/**
37
 * Parser of simple regular expressions with only three supported special
38
 * characters {@code '*'} (zero or more), {@code '?'} (zero or one)
39
 * and {@code '\\'} (quotes the following character).
40
 *
41
 * @author  Marian Petras
42
 */
43
final class RegexpMaker {
44
45
    /** regular expression representing a set of word characters */
46
    private static final String wordCharsExpr
47
                                = "[\\p{javaLetterOrDigit}_]";          //NOI18N
48
    /**
49
     * regular expression representing negative lookbehind
50
     * for a {@linkplain #wordCharsExpr word character}
51
     */
52
    private static final String checkNotAfterWordChar
53
                                = "(?<!" + wordCharsExpr + ")";         //NOI18N
54
    /**
55
     * regular expression representing negative lookahead
56
     * for a {@linkplain #wordCharsExpr word character}
57
     */
58
    private static final String checkNotBeforeWordChar
59
                                = "(?!" + wordCharsExpr + ")";          //NOI18N
60
    
61
    private static String MULTILINE_REGEXP_PATTERN =
62
            ".*(\\\\n|\\\\r|\\\\f|\\\\u|\\\\0|\\\\x|\\(\\?[idmux]*s).*";//NOI18N
63
64
    private RegexpMaker() {
65
    }
66
67
    /**
68
     * Translates the given simple pattern to a regular expression.
69
     * 
70
     * @param  simplePattern  pattern to be translated
71
     * @return  regular expression corresponding to the simple pattern
72
     */
73
    static String makeRegexp(String simplePattern) {
74
75
        /* This method is currently used only in tests. */
76
77
        return makeRegexp(simplePattern, false);
78
    }
79
80
    /**
81
     * Translates the given simple pattern to a regular expression.
82
     * 
83
     * @param  simplePattern  pattern to be translated
84
     * @param  wholeWords  whether the <i>Whole Words</i> option is selected
85
     * @return  regular expression corresponding to the simple pattern
86
     */
87
    static String makeRegexp(String simplePattern, boolean wholeWords) {
88
        if (simplePattern.length() == 0) {              //trivial case
89
            return simplePattern;
90
        }
91
        
92
        if (!wholeWords
93
                && Pattern.matches("[a-zA-Z0-9 ]*", simplePattern)) {   //NOI18N
94
            return simplePattern;                       //trivial case
95
        }
96
        
97
        StringBuilder buf = new StringBuilder(simplePattern.length() + 16);
98
        boolean quoted = false;
99
        boolean starPresent = false;
100
        int minCount = 0;
101
102
        boolean bufIsEmpty = true;
103
        char lastInputChar = '*';       //might be any other non-word character
104
        for (char c : simplePattern.toCharArray()) {
105
            if (quoted && (c == '?' || c == '*')) {
106
                assert !starPresent && (minCount == 0);
107
                if (wholeWords && bufIsEmpty) {
108
                    buf.append(checkNotAfterWordChar);
109
                }                
110
                buf.append('\\');                
111
                buf.append(c);
112
                lastInputChar = c;
113
                bufIsEmpty = false;
114
                quoted = false;
115
            } else if (c == '?') {
116
                assert !quoted;
117
                minCount++;
118
            } else if (c == '*') {
119
                assert !quoted;
120
                starPresent = true;
121
            } else {
122
                if (starPresent || (minCount != 0)) {
123
                    if (wholeWords && bufIsEmpty && !starPresent) {
124
                        buf.append(checkNotAfterWordChar);
125
                    }
126
                    bufIsEmpty &= !addMetachars(buf, starPresent, minCount, wholeWords, !bufIsEmpty);
127
                    starPresent = false;
128
                    minCount = 0;
129
                }
130
                if(quoted) { // backslash was not used for escaping
131
                    buf.append("\\\\");
132
                    quoted = false;
133
                }
134
                if (c == '\\') {
135
                    quoted = true;
136
                } else {
137
                    if (wholeWords && bufIsEmpty && isWordChar(c)) {
138
                        buf.append(checkNotAfterWordChar);
139
                    }
140
                    if (isSpecialCharacter(c)) {
141
                        buf.append('\\');
142
                    }
143
                    buf.append(c);
144
                    lastInputChar = c;
145
                    bufIsEmpty = false;
146
                }
147
            }
148
        }
149
        if (quoted) {
150
            assert !starPresent && (minCount == 0);
151
            buf.append('\\').append('\\');
152
            lastInputChar = '\\';
153
            bufIsEmpty = false;
154
            quoted = false;
155
        } else if (starPresent || (minCount != 0)) {
156
            if (wholeWords && !starPresent && bufIsEmpty) {
157
                buf.append(checkNotAfterWordChar);
158
            }
159
            bufIsEmpty &= !addMetachars(buf, starPresent, minCount, wholeWords, false);
160
            if (wholeWords && !starPresent) {
161
                buf.append(checkNotBeforeWordChar);
162
            }
163
            lastInputChar = '*';    //might be any other non-word character
164
            starPresent = false;
165
            minCount = 0;
166
        }
167
        if (wholeWords && isWordChar(lastInputChar)) {
168
            buf.append(checkNotBeforeWordChar);
169
        }
170
        return buf.toString();
171
    }
172
173
    /**
174
     * Checks whether the given character is a word character.
175
     * @param  c  character to be checked
176
     * @return  {@code true} if the character is a word character,
177
     *          {@code false} otherwise
178
     * @see  #wordCharsExpr
179
     */
180
    private static boolean isWordChar(char c) {
181
        /* not necessary - just for performance */
182
        if ((c == '*') || (c == '\\')) {
183
            return false;
184
        }
185
186
        assert "[\\p{javaLetterOrDigit}_]".equals(wordCharsExpr)        //NOI18N
187
               : "update implementation of method isWordChar(char)";    //NOI18N
188
        return (c == '_') || Character.isLetterOrDigit(c);
189
    }
190
191
    /**
192
     * Generates the part of a regular expression, that represents a sequence
193
     * of simple expression's metacharacters {@code '*'} and {@code '?'},
194
     * and adds it to the given string buffer.
195
     * 
196
     * @param  buf  string buffer to which the new part is to be added
197
     * @param  starPresent  whether the sequence contained at least one
198
     *                      {@code '*'} character
199
     * @param  minCount  number of {@code '?'} characters in the sequence
200
     * @param  wholeWords  whether the <i>Whole Words</i> option is selected
201
     * @param  middle  whether the metachars are to be placed in the middle
202
     *                 (i.e. not in the beginning or at the end) of the search
203
     *                 expression
204
     * @return  {@code true} if something was added to the string buffer,
205
     *          {@code false} if the buffer was not modified
206
     */
207
    private static boolean addMetachars(final StringBuilder buf,
208
                                     boolean starPresent,
209
                                     final int minCount,
210
                                     final boolean wholeWords,
211
                                     final boolean middle) {
212
        assert starPresent || (minCount != 0);
213
214
        /*
215
         * If 'Whole Words' is not activated, ignore stars in the beginning
216
         * and at the end of the expression:
217
         */
218
        if (starPresent && !wholeWords && !middle) {
219
            starPresent = false;
220
        }
221
222
        if ((minCount == 0) && !starPresent) {
223
            return false;
224
        }
225
226
        if (wholeWords) {
227
            buf.append(wordCharsExpr);
228
        } else {
229
            buf.append('.');
230
        }
231
        switch (minCount) {
232
        case 0:
233
            assert starPresent;
234
            buf.append('*');
235
            break;
236
        case 1:
237
            if (starPresent) {
238
                buf.append('+');
239
            }
240
            break;
241
        default:
242
            if (wholeWords) {
243
                buf.append('{').append(minCount);
244
                if (starPresent) {
245
                    buf.append(',');
246
                }
247
                buf.append('}');
248
            } else {
249
                for (int i = 1; i < minCount; i++) {
250
                    buf.append('.');
251
                }
252
                if (starPresent) {
253
                    buf.append('+');
254
                }
255
            }
256
        }
257
        if (starPresent && middle) {
258
            buf.append('?');    //use reluctant variant of the quantifier
259
        }
260
        return true;
261
    }
262
    
263
    /**
264
     * Translates the given simple pattern (or several patterns) to a single
265
     * regular expression.
266
     * 
267
     * @param  simplePatternList  pattern list to be translated
268
     * @return  regular expression corresponding to the simple pattern
269
     *          (or to the list of simple patterns)
270
     */
271
    static String makeMultiRegexp(String simplePatternList) {
272
        if (simplePatternList.length() == 0) {              //trivial case
273
            return simplePatternList;
274
        }
275
        
276
        if (Pattern.matches("[a-zA-Z0-9]*", simplePatternList)) {       //NOI18N
277
            return simplePatternList;                       //trivial case
278
        }
279
        
280
        StringBuilder buf = new StringBuilder(simplePatternList.length() + 16);
281
        boolean lastWasSeparator = false;
282
        boolean quoted = false;
283
        boolean starPresent = false;
284
        for (char c : simplePatternList.toCharArray()) {
285
            if (quoted) {
286
                if ((c == 'n') || isSpecialCharacter(c)) {
287
                    buf.append('\\');
288
                }
289
                buf.append(c);
290
                quoted = false;
291
            } else if ((c == ',') || (c == ' ')) {
292
                if (starPresent) {
293
                    buf.append('.').append('*');
294
                    starPresent = false;
295
                }
296
                lastWasSeparator = true;
297
            } else {
298
                if (lastWasSeparator && (buf.length() != 0)) {
299
                    buf.append('|');
300
                }
301
                if (c == '?') {
302
                    buf.append('.');
303
                } else if (c == '*') {
304
                    starPresent = true;
305
                } else {
306
                    if (starPresent) {
307
                        buf.append('.').append('*');
308
                        starPresent = false;
309
                    }
310
                    if (c == '\\') {
311
                        quoted = true;
312
                    } else {
313
                        if (isSpecialCharacter(c)) {
314
                            buf.append('\\');
315
                        }
316
                        buf.append(c);
317
                    }
318
                }
319
                lastWasSeparator = false;
320
            }
321
        }
322
        if (quoted) {
323
            buf.append('\\').append('\\');
324
            quoted = false;
325
        } else if (starPresent) {
326
            buf.append('.').append('*');
327
            starPresent = false;
328
        }
329
        return buf.toString();
330
    }
331
    
332
    private static boolean isSpecialCharacter(char c) {
333
        return (c > 0x20) && (c < 0x80) && !isAlnum(c);
334
    }
335
336
    private static boolean isAlnum(char c) {
337
        return isAlpha(c) || isDigit(c);
338
}
339
340
    private static boolean isAlpha(char c) {
341
        c |= 0x20;  //to lower case
342
        return (c >= 'a') && (c <= 'z');
343
    }
344
345
    private static boolean isDigit(char c) {
346
        return (c >= '0') && (c <= '9');
347
    }
348
349
    /**
350
     * Line-by-line is not sufficient and whole-file matching must be performed
351
     * for a pattern.
352
     */
353
    static boolean canBeMultilinePattern(String expr) {
354
        return expr.matches(MULTILINE_REGEXP_PATTERN);
355
    }
356
}
(-)a/api.search/src/org/netbeans/modules/search/TextRegexpUtil.java (-2 / +27 lines)
Lines 79-84 Link Here
79
    private TextRegexpUtil() {
79
    private TextRegexpUtil() {
80
    }
80
    }
81
81
82
    private static String makeLiteralRegexp(String literalPattern,
83
            boolean wholeWords) {
84
85
        StringBuilder sb = new StringBuilder();
86
        if (wholeWords) {
87
            sb.append(checkNotAfterWordChar);
88
        }
89
        sb.append(Pattern.quote(literalPattern));
90
        if (wholeWords) {
91
            sb.append(checkNotBeforeWordChar);
92
        }
93
        return sb.toString();
94
    }
95
82
    /**
96
    /**
83
     * Translates the given simple pattern to a regular expression.
97
     * Translates the given simple pattern to a regular expression.
84
     *
98
     *
Lines 194-201 Link Here
194
            LOG.log(Level.FINEST, " - textPatternExpr = \"{0}{1}",
208
            LOG.log(Level.FINEST, " - textPatternExpr = \"{0}{1}",
195
                    new Object[]{sp.getSearchExpression(), '"'});       //NOI18N
209
                    new Object[]{sp.getSearchExpression(), '"'});       //NOI18N
196
        }
210
        }
197
        String searchRegexp = makeRegexp(sp.getSearchExpression(),
211
        String searchRegexp;
198
                sp.isWholeWords());
212
        switch (sp.getMatchType()) {
213
            case BASIC:
214
                searchRegexp = makeRegexp(
215
                        sp.getSearchExpression(), sp.isWholeWords());
216
                break;
217
            case LITERAL:
218
                searchRegexp = makeLiteralRegexp(
219
                        sp.getSearchExpression(), sp.isWholeWords());
220
                break;
221
            default:
222
                throw new IllegalStateException();
223
        }
199
224
200
        if (LOG.isLoggable(Level.FINEST)) {
225
        if (LOG.isLoggable(Level.FINEST)) {
201
            LOG.log(Level.FINEST, " - regexp = \"{0}{1}",
226
            LOG.log(Level.FINEST, " - regexp = \"{0}{1}",
(-)a/api.search/src/org/netbeans/modules/search/ui/CheckBoxWithButtonPanel.java (-97 / +7 lines)
Lines 41-59 Link Here
41
 */
41
 */
42
package org.netbeans.modules.search.ui;
42
package org.netbeans.modules.search.ui;
43
43
44
import java.awt.Cursor;
45
import java.awt.FlowLayout;
44
import java.awt.FlowLayout;
46
import java.awt.event.ActionListener;
47
import java.awt.event.ItemEvent;
45
import java.awt.event.ItemEvent;
48
import java.awt.event.ItemListener;
46
import java.awt.event.ItemListener;
49
import java.awt.event.MouseAdapter;
50
import java.awt.event.MouseEvent;
51
import java.awt.event.MouseListener;
52
import javax.swing.JButton;
47
import javax.swing.JButton;
53
import javax.swing.JCheckBox;
48
import javax.swing.JCheckBox;
54
import javax.swing.JLabel;
55
import javax.swing.JPanel;
49
import javax.swing.JPanel;
56
import javax.swing.border.EmptyBorder;
57
50
58
/**
51
/**
59
 * Panel for a checkbox and a button that is enbled if and only if the checkbox
52
 * Panel for a checkbox and a button that is enbled if and only if the checkbox
Lines 63-73 Link Here
63
        implements ItemListener {
56
        implements ItemListener {
64
57
65
    private JCheckBox checkbox;
58
    private JCheckBox checkbox;
66
    private JButton button;
59
    private LinkButtonPanel buttonPanel;
67
    private JLabel leftParenthesis;
68
    private JLabel rightParenthesis;
69
    private String enabledText;
70
    private String disabledText;
71
60
72
    /**
61
    /**
73
     * Constructor.
62
     * Constructor.
Lines 79-86 Link Here
79
     */
68
     */
80
    public CheckBoxWithButtonPanel(JCheckBox checkbox, JButton button) {
69
    public CheckBoxWithButtonPanel(JCheckBox checkbox, JButton button) {
81
        this.checkbox = checkbox;
70
        this.checkbox = checkbox;
82
        this.button = button;
71
        this.buttonPanel = new LinkButtonPanel(button);
83
        initTexts();
84
        init();
72
        init();
85
    }
73
    }
86
74
Lines 91-193 Link Here
91
        this.setLayout(new FlowLayout(
79
        this.setLayout(new FlowLayout(
92
                FlowLayout.LEADING, 0, 0));
80
                FlowLayout.LEADING, 0, 0));
93
        this.add(checkbox);
81
        this.add(checkbox);
94
        setLinkLikeButton(button);
82
        this.add(buttonPanel);
95
        leftParenthesis = new JLabel("(");                              //NOI18N
96
        rightParenthesis = new JLabel(")");                             //NOI18N
97
        add(leftParenthesis);
98
        add(button);
99
        add(rightParenthesis);
100
        MouseListener ml = createLabelMouseListener();
101
        leftParenthesis.addMouseListener(ml);
102
        rightParenthesis.addMouseListener(ml);
103
        button.setEnabled(false);
104
83
105
        this.setMaximumSize(
84
        this.setMaximumSize(
106
                this.getMinimumSize());
85
                this.getMinimumSize());
107
        checkbox.addItemListener(this);
86
        checkbox.addItemListener(this);
108
        if (checkbox.isSelected()) {
87
        if (checkbox.isSelected()) {
109
            enableButton();
88
            buttonPanel.enableButton();
110
        } else {
89
        } else {
111
            disableButton();
90
            buttonPanel.disableButton();
112
        }
91
        }
113
    }
92
    }
114
93
115
    /**
116
     * Init values of enabled and disabled button texts.
117
     */
118
    private void initTexts() {
119
        enabledText = button.getText();
120
        if (enabledText.startsWith(UiUtils.HTML_LINK_PREFIX)
121
                && enabledText.endsWith(UiUtils.HTML_LINK_SUFFIX)) {
122
            disabledText = enabledText.substring(
123
                    UiUtils.HTML_LINK_PREFIX.length(),
124
                    enabledText.length() - UiUtils.HTML_LINK_SUFFIX.length());
125
        } else {
126
            disabledText = enabledText;
127
        }
128
    }
129
130
    /**
131
     * Create listener that delegates mouse clicks on parenthesis to the button.
132
     */
133
    private MouseListener createLabelMouseListener() {
134
        return new MouseAdapter() {
135
136
            @Override
137
            public void mouseClicked(MouseEvent e) {
138
                if (button.isEnabled()) {
139
                    for (ActionListener al : button.getActionListeners()) {
140
                        al.actionPerformed(null);
141
                    }
142
                }
143
            }
144
        };
145
    }
146
147
    /**
148
     * Set button border and background to look like a label with link.
149
     */
150
    private void setLinkLikeButton(JButton button) {
151
        button.setBorderPainted(false);
152
        button.setContentAreaFilled(false);
153
        button.setBorder(new EmptyBorder(0, 0, 0, 0));
154
        button.setCursor(Cursor.getPredefinedCursor(
155
                Cursor.HAND_CURSOR));
156
    }
157
158
    @Override
94
    @Override
159
    public void itemStateChanged(ItemEvent e) {
95
    public void itemStateChanged(ItemEvent e) {
160
        if (checkbox.isSelected()) {
96
        if (checkbox.isSelected()) {
161
            enableButton();
97
            buttonPanel.enableButton();
162
        } else {
98
        } else {
163
            disableButton();
99
            buttonPanel.disableButton();
164
        }
100
        }
165
        this.setMinimumSize(this.getPreferredSize()); // #214745
101
        this.setMinimumSize(this.getPreferredSize()); // #214745
166
    }
102
    }
167
168
    /**
169
     * Enable button and parentheses around it.
170
     */
171
    private void enableButton() {
172
        button.setText(enabledText);
173
        button.setEnabled(true);
174
        leftParenthesis.setCursor(
175
                Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
176
        rightParenthesis.setCursor(
177
                Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
178
        leftParenthesis.setEnabled(true);
179
        rightParenthesis.setEnabled(true);
180
    }
181
182
    /**
183
     * Disable button and parentheses around it.
184
     */
185
    private void disableButton() {
186
        button.setText(disabledText);
187
        button.setEnabled(false);
188
        leftParenthesis.setCursor(Cursor.getDefaultCursor());
189
        rightParenthesis.setCursor(Cursor.getDefaultCursor());
190
        leftParenthesis.setEnabled(false);
191
        rightParenthesis.setEnabled(false);
192
    }
193
}
103
}
(-)a/api.search/src/org/netbeans/modules/search/ui/LinkButtonPanel.java (+167 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.search.ui;
43
44
import java.awt.Cursor;
45
import java.awt.FlowLayout;
46
import java.awt.event.ActionListener;
47
import java.awt.event.MouseAdapter;
48
import java.awt.event.MouseEvent;
49
import java.awt.event.MouseListener;
50
import javax.swing.JButton;
51
import javax.swing.JLabel;
52
import javax.swing.JPanel;
53
import javax.swing.border.EmptyBorder;
54
55
/**
56
 *
57
 * @author jhavlin
58
 */
59
public class LinkButtonPanel extends JPanel {
60
61
    private JButton button;
62
    private JLabel leftParenthesis;
63
    private JLabel rightParenthesis;
64
    private String enabledText;
65
    private String disabledText;
66
67
    public LinkButtonPanel(JButton button) {
68
        this.button = button;
69
        initTexts();
70
        init();
71
    }
72
73
    private void init() {
74
        this.setLayout(new FlowLayout(
75
                FlowLayout.LEADING, 0, 0));
76
        setLinkLikeButton(button);
77
        leftParenthesis = new JLabel("(");                              //NOI18N
78
        rightParenthesis = new JLabel(")");                             //NOI18N
79
        add(leftParenthesis);
80
        add(button);
81
        add(rightParenthesis);
82
        MouseListener ml = createLabelMouseListener();
83
        leftParenthesis.addMouseListener(ml);
84
        rightParenthesis.addMouseListener(ml);
85
        button.setEnabled(false);
86
        this.setMaximumSize(
87
                this.getPreferredSize());
88
    }
89
90
    /**
91
     * Init values of enabled and disabled button texts.
92
     */
93
    private void initTexts() {
94
        enabledText = button.getText();
95
        if (enabledText.startsWith(UiUtils.HTML_LINK_PREFIX)
96
                && enabledText.endsWith(UiUtils.HTML_LINK_SUFFIX)) {
97
            disabledText = enabledText.substring(
98
                    UiUtils.HTML_LINK_PREFIX.length(),
99
                    enabledText.length() - UiUtils.HTML_LINK_SUFFIX.length());
100
        } else {
101
            disabledText = enabledText;
102
        }
103
    }
104
105
    /**
106
     * Create listener that delegates mouse clicks on parenthesis to the button.
107
     */
108
    private MouseListener createLabelMouseListener() {
109
        return new MouseAdapter() {
110
            @Override
111
            public void mouseClicked(MouseEvent e) {
112
                if (button.isEnabled()) {
113
                    for (ActionListener al : button.getActionListeners()) {
114
                        al.actionPerformed(null);
115
                    }
116
                }
117
            }
118
        };
119
    }
120
121
    /**
122
     * Set button border and background to look like a label with link.
123
     */
124
    private void setLinkLikeButton(JButton button) {
125
        button.setBorderPainted(false);
126
        button.setContentAreaFilled(false);
127
        button.setBorder(new EmptyBorder(0, 0, 0, 0));
128
        button.setCursor(Cursor.getPredefinedCursor(
129
                Cursor.HAND_CURSOR));
130
    }
131
132
    /**
133
     * Enable button and parentheses around it.
134
     */
135
    public void enableButton() {
136
        button.setText(enabledText);
137
        button.setEnabled(true);
138
        leftParenthesis.setCursor(
139
                Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
140
        rightParenthesis.setCursor(
141
                Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
142
        leftParenthesis.setEnabled(true);
143
        rightParenthesis.setEnabled(true);
144
        this.setMinimumSize(this.getPreferredSize());
145
    }
146
147
    /**
148
     * Disable button and parentheses around it.
149
     */
150
    public void disableButton() {
151
        button.setText(disabledText);
152
        button.setEnabled(false);
153
        leftParenthesis.setCursor(Cursor.getDefaultCursor());
154
        rightParenthesis.setCursor(Cursor.getDefaultCursor());
155
        leftParenthesis.setEnabled(false);
156
        rightParenthesis.setEnabled(false);
157
        this.setMinimumSize(this.getPreferredSize());
158
    }
159
160
    public void setButtonEnabled(boolean enabled) {
161
        if (enabled) {
162
            enableButton();
163
        } else {
164
            disableButton();
165
        }
166
    }
167
}
(-)a/api.search/test/unit/src/org/netbeans/api/search/RegexpUtilTest.java (+191 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.search;
43
44
import org.junit.Test;
45
import static org.junit.Assert.*;
46
47
/**
48
 *
49
 * @author jhavlin
50
 */
51
public class RegexpUtilTest {
52
53
    @Test
54
    public void testMakeMultiRegexp() {
55
        assertEquals("", makeMultiRegexp(""));
56
        assertEquals("a", makeMultiRegexp("a"));
57
        assertEquals("ab", makeMultiRegexp("ab"));
58
        assertEquals("abc", makeMultiRegexp("abc"));
59
        assertEquals("a.", makeMultiRegexp("a?"));
60
        assertEquals("a.*", makeMultiRegexp("a*"));
61
        assertEquals(".a", makeMultiRegexp("?a"));
62
        assertEquals(".*a", makeMultiRegexp("*a"));
63
        assertEquals("a.b", makeMultiRegexp("a?b"));
64
        assertEquals(".a.", makeMultiRegexp("?a?"));
65
        assertEquals("a.*b.c", makeMultiRegexp("a*b?c"));
66
        assertEquals("a...*b", makeMultiRegexp("a?*?b"));
67
        assertEquals("a..*b", makeMultiRegexp("a*?*b"));
68
69
        assertEquals("a|b", makeMultiRegexp("a b"));
70
        assertEquals("a\\!b", makeMultiRegexp("a!b"));
71
        assertEquals("a\\\"b", makeMultiRegexp("a\"b"));
72
        assertEquals("a\\#b", makeMultiRegexp("a#b"));
73
        assertEquals("a\\$b", makeMultiRegexp("a$b"));
74
        assertEquals("a\\%b", makeMultiRegexp("a%b"));
75
        assertEquals("a\\&b", makeMultiRegexp("a&b"));
76
        assertEquals("a\\'b", makeMultiRegexp("a'b"));
77
        assertEquals("a\\(b", makeMultiRegexp("a(b"));
78
        assertEquals("a\\)b", makeMultiRegexp("a)b"));
79
        assertEquals("a\\+b", makeMultiRegexp("a+b"));
80
        assertEquals("a|b", makeMultiRegexp("a,b"));
81
        assertEquals("a\\-b", makeMultiRegexp("a-b"));
82
        assertEquals("a\\.b", makeMultiRegexp("a.b"));
83
        assertEquals("a\\/b", makeMultiRegexp("a/b"));
84
85
        assertEquals("a0b", makeMultiRegexp("a0b"));
86
        assertEquals("a1b", makeMultiRegexp("a1b"));
87
        assertEquals("a2b", makeMultiRegexp("a2b"));
88
        assertEquals("a3b", makeMultiRegexp("a3b"));
89
        assertEquals("a4b", makeMultiRegexp("a4b"));
90
        assertEquals("a5b", makeMultiRegexp("a5b"));
91
        assertEquals("a6b", makeMultiRegexp("a6b"));
92
        assertEquals("a7b", makeMultiRegexp("a7b"));
93
        assertEquals("a8b", makeMultiRegexp("a8b"));
94
        assertEquals("a9b", makeMultiRegexp("a9b"));
95
96
        assertEquals("a\\:b", makeMultiRegexp("a:b"));
97
        assertEquals("a\\;b", makeMultiRegexp("a;b"));
98
        assertEquals("a\\<b", makeMultiRegexp("a<b"));
99
        assertEquals("a\\=b", makeMultiRegexp("a=b"));
100
        assertEquals("a\\>b", makeMultiRegexp("a>b"));
101
        assertEquals("a\\@b", makeMultiRegexp("a@b"));
102
        assertEquals("a\\[b", makeMultiRegexp("a[b"));
103
        assertEquals("ab", makeMultiRegexp("a\\b"));
104
        assertEquals("a\\]b", makeMultiRegexp("a]b"));
105
        assertEquals("a\\^b", makeMultiRegexp("a^b"));
106
        assertEquals("a\\_b", makeMultiRegexp("a_b"));
107
        assertEquals("a\\`b", makeMultiRegexp("a`b"));
108
        assertEquals("a\\{b", makeMultiRegexp("a{b"));
109
        assertEquals("a\\|b", makeMultiRegexp("a|b"));
110
        assertEquals("a\\}b", makeMultiRegexp("a}b"));
111
        assertEquals("a\\~b", makeMultiRegexp("a~b"));
112
        assertEquals("a\\\u007fb", makeMultiRegexp("a\u007fb"));
113
114
        assertEquals("a\u0080b", makeMultiRegexp("a\u0080b"));
115
        assertEquals("a\u00c1b", makeMultiRegexp("a\u00c1b"));
116
117
        assertEquals("abc\\\\", makeMultiRegexp("abc\\"));
118
119
        assertEquals("", makeMultiRegexp(""));
120
        assertEquals("", makeMultiRegexp(" "));
121
        assertEquals("", makeMultiRegexp(","));
122
        assertEquals("", makeMultiRegexp(", "));
123
        assertEquals("", makeMultiRegexp(" ,"));
124
        assertEquals("a", makeMultiRegexp("a,"));
125
        assertEquals("a", makeMultiRegexp("a "));
126
        assertEquals("a", makeMultiRegexp("a, "));
127
        assertEquals("a", makeMultiRegexp("a ,"));
128
        assertEquals("a", makeMultiRegexp(",a"));
129
        assertEquals("a", makeMultiRegexp(" a"));
130
        assertEquals("a", makeMultiRegexp(", a"));
131
        assertEquals("a", makeMultiRegexp(" ,a"));
132
        assertEquals("a|b", makeMultiRegexp("a b"));
133
        assertEquals("a|b", makeMultiRegexp("a,b"));
134
        assertEquals("a|b", makeMultiRegexp("a, b"));
135
        assertEquals("a|b", makeMultiRegexp("a ,b"));
136
        assertEquals(" ", makeMultiRegexp("\\ "));
137
        assertEquals("\\,", makeMultiRegexp("\\,"));
138
        assertEquals("\\,", makeMultiRegexp("\\, "));
139
        assertEquals(" ", makeMultiRegexp(",\\ "));
140
        assertEquals("\\, ", makeMultiRegexp("\\,\\ "));
141
        assertEquals(" ", makeMultiRegexp("\\ ,"));
142
        assertEquals("\\,", makeMultiRegexp(" \\,"));
143
        assertEquals(" \\,", makeMultiRegexp("\\ \\,"));
144
        assertEquals("a", makeMultiRegexp("\\a,"));
145
        assertEquals("a\\,", makeMultiRegexp("a\\,"));
146
        assertEquals("a\\,", makeMultiRegexp("\\a\\,"));
147
        assertEquals("a", makeMultiRegexp("\\a "));
148
        assertEquals("a ", makeMultiRegexp("a\\ "));
149
        assertEquals("a ", makeMultiRegexp("\\a\\ "));
150
        assertEquals("a|\\\\", makeMultiRegexp("a, \\"));
151
        assertEquals("a| ", makeMultiRegexp("a,\\ "));
152
        assertEquals("a| \\\\", makeMultiRegexp("a,\\ \\"));
153
        assertEquals("a\\,", makeMultiRegexp("a\\, "));
154
        assertEquals("a\\,|\\\\", makeMultiRegexp("a\\, \\"));
155
        assertEquals("a\\, ", makeMultiRegexp("a\\,\\ "));
156
        assertEquals("a\\, \\\\", makeMultiRegexp("a\\,\\ \\"));
157
        assertEquals("a", makeMultiRegexp("\\a, "));
158
        assertEquals("a|\\\\", makeMultiRegexp("\\a, \\"));
159
        assertEquals("a| ", makeMultiRegexp("\\a,\\ "));
160
        assertEquals("a| \\\\", makeMultiRegexp("\\a,\\ \\"));
161
        assertEquals("a\\,", makeMultiRegexp("\\a\\, "));
162
        assertEquals("a\\,|\\\\", makeMultiRegexp("\\a\\, \\"));
163
        assertEquals("a\\, ", makeMultiRegexp("\\a\\,\\ "));
164
        assertEquals("a\\, \\\\", makeMultiRegexp("\\a\\,\\ \\"));
165
        assertEquals("a|\\\\", makeMultiRegexp("a ,\\"));
166
        assertEquals("a|\\,", makeMultiRegexp("a \\,"));
167
        assertEquals("a|\\,\\\\", makeMultiRegexp("a \\,\\"));
168
        assertEquals("a ", makeMultiRegexp("a\\ ,"));
169
        assertEquals("a |\\\\", makeMultiRegexp("a\\ ,\\"));
170
        assertEquals("a \\,", makeMultiRegexp("a\\ \\,"));
171
        assertEquals("a \\,\\\\", makeMultiRegexp("a\\ \\,\\"));
172
        assertEquals("a", makeMultiRegexp("\\a ,"));
173
        assertEquals("a|\\\\", makeMultiRegexp("\\a ,\\"));
174
        assertEquals("a|\\,", makeMultiRegexp("\\a \\,"));
175
        assertEquals("a|\\,\\\\", makeMultiRegexp("\\a \\,\\"));
176
        assertEquals("a ", makeMultiRegexp("\\a\\ ,"));
177
        assertEquals("a |\\\\", makeMultiRegexp("\\a\\ ,\\"));
178
        assertEquals("a \\,", makeMultiRegexp("\\a\\ \\,"));
179
        assertEquals("a \\,\\\\", makeMultiRegexp("\\a\\ \\,\\"));
180
181
        assertEquals("a|b", makeMultiRegexp("a, b"));
182
        assertEquals("a|.*b.", makeMultiRegexp("a,*b?"));
183
        assertEquals("a|\\*b.", makeMultiRegexp("a,\\*b?"));
184
        assertEquals("a|.*b\\?", makeMultiRegexp("a,*b\\?"));
185
    }
186
187
    private String makeMultiRegexp(String string) {
188
        return RegexpUtil.makeFileNamePattern(
189
                SearchScopeOptions.create(string, false)).pattern();
190
    }
191
}
(-)a/api.search/test/unit/src/org/netbeans/api/search/SearchHistoryTest.java (-1 / +1 lines)
Lines 76-82 Link Here
76
    /**
76
    /**
77
     */
77
     */
78
    public void testSearchPatternSize() throws Exception {
78
    public void testSearchPatternSize() throws Exception {
79
        assertSize("SearchPattern size", 80, SearchPattern.create("searchText",true,true,false));
79
        assertSize("SearchPattern size", 256, SearchPattern.create("searchText",true,true,false));
80
    }
80
    }
81
81
82
    public void testSearchHistoryListSize() throws Exception{
82
    public void testSearchHistoryListSize() throws Exception{
(-)a/api.search/test/unit/src/org/netbeans/api/search/SearchPatternTest.java (+36 lines)
Lines 43-48 Link Here
43
43
44
import org.junit.Test;
44
import org.junit.Test;
45
import static org.junit.Assert.*;
45
import static org.junit.Assert.*;
46
import org.netbeans.api.search.SearchPattern.MatchType;
46
47
47
public class SearchPatternTest {
48
public class SearchPatternTest {
48
    
49
    
Lines 63-66 Link Here
63
        
64
        
64
        assertEquals("mRW-ta", canString);
65
        assertEquals("mRW-ta", canString);
65
    }
66
    }
67
68
    @Test
69
    public void testMatchType() {
70
71
        assertFalse("Literal match type shoudn't be a regexp pattern",
72
                SearchPattern.create("test", false, false,
73
                MatchType.LITERAL).isRegExp());
74
75
        assertFalse("Basic match type shoudn't be a regexp pattern",
76
                SearchPattern.create("test", false, false,
77
                MatchType.BASIC).isRegExp());
78
79
        assertTrue("Regexp match type should be a regexp pattern",
80
                SearchPattern.create("test", false, false,
81
                MatchType.REGEXP).isRegExp());
82
83
        assertTrue("Chaning match type to REGEXP should create regexp pattern",
84
                SearchPattern.create("test", false, false,
85
                MatchType.LITERAL).changeMatchType(MatchType.REGEXP)
86
                .isRegExp());
87
88
        assertEquals("Changing match type to LITERAL should work",
89
                MatchType.LITERAL, SearchPattern.create("test",
90
                false, false, true).changeMatchType(MatchType.LITERAL)
91
                .getMatchType());
92
93
        assertEquals("Chaning match type to BASIC should work",
94
                MatchType.BASIC, SearchPattern.create("test",
95
                false, false, true).changeMatchType(MatchType.BASIC)
96
                .getMatchType());
97
98
        assertEquals("If not specified exactly, match type should be LITERAL",
99
                MatchType.LITERAL, SearchPattern.create("test",
100
                false, false, false).getMatchType());
101
    }
66
}
102
}
(-)a/api.search/test/unit/src/org/netbeans/api/search/ui/SearchPatternControllerTest.java (+102 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.search.ui;
43
44
import javax.swing.JComboBox;
45
import org.junit.Test;
46
import static org.junit.Assert.*;
47
import org.netbeans.api.search.SearchPattern;
48
import org.netbeans.api.search.SearchPattern.MatchType;
49
import org.netbeans.api.search.ui.SearchPatternController.MultiOption;
50
51
/**
52
 *
53
 * @author jhavlin
54
 */
55
public class SearchPatternControllerTest {
56
57
    public SearchPatternControllerTest() {
58
    }
59
60
    @Test
61
    public void testBindComboBox() {
62
        JComboBox cb = new JComboBox();
63
        SearchPatternController controller =
64
                ComponentUtils.adjustComboForSearchPattern(cb);
65
        JComboBox matchTypeCb = new JComboBox(new Object[]{
66
            MatchType.BASIC, MatchType.LITERAL, MatchType.REGEXP});
67
        assertEquals(MatchType.BASIC, matchTypeCb.getSelectedItem());
68
        controller.bind(MultiOption.MATCH_TYPE, matchTypeCb);
69
        boolean thrown = false;
70
        try {
71
            controller.bind(MultiOption.MATCH_TYPE, matchTypeCb);
72
        } catch (Exception e) {
73
            thrown = true;
74
        }
75
        assertTrue("Exception should be thrown when trying to bind "
76
                + "a property twice", thrown);
77
78
        controller.setSearchPattern(
79
                SearchPattern.create("test", false, false, MatchType.LITERAL));
80
        assertEquals(MatchType.LITERAL, matchTypeCb.getSelectedItem());
81
82
        controller.setSearchPattern(
83
                SearchPattern.create("test", false, false, MatchType.REGEXP));
84
        assertEquals(MatchType.REGEXP, matchTypeCb.getSelectedItem());
85
86
        controller.setSearchPattern(
87
                SearchPattern.create("test", false, false, MatchType.BASIC));
88
        assertEquals(MatchType.BASIC, matchTypeCb.getSelectedItem());
89
90
        matchTypeCb.setSelectedItem(MatchType.LITERAL);
91
        assertEquals(MatchType.LITERAL,
92
                controller.getSearchPattern().getMatchType());
93
94
        matchTypeCb.setSelectedItem(MatchType.REGEXP);
95
        assertEquals(MatchType.REGEXP,
96
                controller.getSearchPattern().getMatchType());
97
98
        matchTypeCb.setSelectedItem(MatchType.BASIC);
99
        assertEquals(MatchType.BASIC,
100
                controller.getSearchPattern().getMatchType());
101
    }
102
}
(-)a/api.search/test/unit/src/org/netbeans/modules/search/BasicSearchCriteriaTest.java (-1 / +2 lines)
Lines 43-48 Link Here
43
43
44
import org.junit.Test;
44
import org.junit.Test;
45
import static org.junit.Assert.*;
45
import static org.junit.Assert.*;
46
import org.netbeans.api.search.SearchPattern;
46
47
47
/**
48
/**
48
 *
49
 *
Lines 56-62 Link Here
56
    @Test
57
    @Test
57
    public void testDetectInvalidReplacePattern() {
58
    public void testDetectInvalidReplacePattern() {
58
        BasicSearchCriteria bsc = new BasicSearchCriteria();
59
        BasicSearchCriteria bsc = new BasicSearchCriteria();
59
        bsc.setRegexp(true);
60
        bsc.setMatchType(SearchPattern.MatchType.REGEXP);
60
        bsc.setTextPattern("a");
61
        bsc.setTextPattern("a");
61
        bsc.setReplaceExpr("$1");
62
        bsc.setReplaceExpr("$1");
62
        assertFalse(bsc.isUsable());
63
        assertFalse(bsc.isUsable());
(-)a/api.search/test/unit/src/org/netbeans/modules/search/MatchingObjectTest.java (-1 / +1 lines)
Lines 209-215 Link Here
209
209
210
        BasicSearchCriteria bsc = new BasicSearchCriteria();
210
        BasicSearchCriteria bsc = new BasicSearchCriteria();
211
        bsc.setTextPattern(find);
211
        bsc.setTextPattern(find);
212
        bsc.setRegexp(false);
212
        bsc.setMatchType(SearchPattern.MatchType.BASIC);
213
        bsc.setReplaceExpr(replace);
213
        bsc.setReplaceExpr(replace);
214
        bsc.setPreserveCase(true);
214
        bsc.setPreserveCase(true);
215
        bsc.onOk();
215
        bsc.onOk();
(-)a/api.search/test/unit/src/org/netbeans/modules/search/RegexpMakerTest.java (-280 / +179 lines)
Lines 34-53 Link Here
34
import java.lang.reflect.Field;
34
import java.lang.reflect.Field;
35
import java.util.regex.Matcher;
35
import java.util.regex.Matcher;
36
import java.util.regex.Pattern;
36
import java.util.regex.Pattern;
37
import org.netbeans.api.search.SearchPattern;
38
import org.netbeans.api.search.SearchPattern.MatchType;
37
import org.netbeans.junit.NbTestCase;
39
import org.netbeans.junit.NbTestCase;
38
40
39
/**
41
/**
40
 *
42
 *
41
 * @author mp
43
 * @author mp
42
 */
44
 */
43
public class RegexpMakerTest extends NbTestCase {
45
public class TextRegexpUtilTest extends NbTestCase {
44
46
45
    public RegexpMakerTest() {
47
    public TextRegexpUtilTest() {
46
        super("SimpleRegexpParserTest");
48
        super("SimpleRegexpParserTest");
47
    }
49
    }
48
50
49
    private static String getClassField(String name) throws Exception {
51
    private static String getClassField(String name) throws Exception {
50
        Field field = RegexpMaker.class.getDeclaredField(name);
52
        Field field = TextRegexpUtil.class.getDeclaredField(name);
51
        field.setAccessible(true);
53
        field.setAccessible(true);
52
        return (String) field.get(null);
54
        return (String) field.get(null);
53
    }
55
    }
Lines 55-99 Link Here
55
    public void testMakeRegexp() throws Exception {
57
    public void testMakeRegexp() throws Exception {
56
58
57
        /* basics: */
59
        /* basics: */
58
        assertEquals("", RegexpMaker.makeRegexp(""));
60
        assertEquals("", makeRegexp(""));
59
        assertEquals("a", RegexpMaker.makeRegexp("a"));
61
        assertEquals("a", makeRegexp("a"));
60
        assertEquals("ab", RegexpMaker.makeRegexp("ab"));
62
        assertEquals("ab", makeRegexp("ab"));
61
        assertEquals("abc", RegexpMaker.makeRegexp("abc"));
63
        assertEquals("abc", makeRegexp("abc"));
62
64
63
        /* special chars in the middle: */
65
        /* special chars in the middle: */
64
        assertEquals("a.*?b.c", RegexpMaker.makeRegexp("a*b?c"));
66
        assertEquals("a.*?b.c", makeRegexp("a*b?c"));
65
        assertEquals("a..+?b", RegexpMaker.makeRegexp("a?*?b"));
67
        assertEquals("a..+?b", makeRegexp("a?*?b"));
66
        assertEquals("a.+?b", RegexpMaker.makeRegexp("a*?*b"));
68
        assertEquals("a.+?b", makeRegexp("a*?*b"));
67
69
68
        /* ignore stars in the begining: */
70
        /* ignore stars in the begining: */
69
        assertEquals("a", RegexpMaker.makeRegexp("*a"));
71
        assertEquals("a", makeRegexp("*a"));
70
        assertEquals(".a", RegexpMaker.makeRegexp("?a"));
72
        assertEquals(".a", makeRegexp("?a"));
71
        assertEquals("a", RegexpMaker.makeRegexp("**a"));
73
        assertEquals("a", makeRegexp("**a"));
72
        assertEquals(".a", RegexpMaker.makeRegexp("*?a"));
74
        assertEquals(".a", makeRegexp("*?a"));
73
        assertEquals(".a", RegexpMaker.makeRegexp("?*a"));
75
        assertEquals(".a", makeRegexp("?*a"));
74
        assertEquals("..a", RegexpMaker.makeRegexp("??a"));
76
        assertEquals("..a", makeRegexp("??a"));
75
77
76
        /* ignore stars at the end: */
78
        /* ignore stars at the end: */
77
        assertEquals("a", RegexpMaker.makeRegexp("a*"));
79
        assertEquals("a", makeRegexp("a*"));
78
        assertEquals("a.", RegexpMaker.makeRegexp("a?"));
80
        assertEquals("a.", makeRegexp("a?"));
79
        assertEquals("a", RegexpMaker.makeRegexp("a**"));
81
        assertEquals("a", makeRegexp("a**"));
80
        assertEquals("a.", RegexpMaker.makeRegexp("a*?"));
82
        assertEquals("a.", makeRegexp("a*?"));
81
        assertEquals("a.", RegexpMaker.makeRegexp("a?*"));
83
        assertEquals("a.", makeRegexp("a?*"));
82
        assertEquals("a..", RegexpMaker.makeRegexp("a??"));
84
        assertEquals("a..", makeRegexp("a??"));
83
85
84
        /* other usage of '*' and '?': */
86
        /* other usage of '*' and '?': */
85
        assertEquals(" .*?a", RegexpMaker.makeRegexp(" *a"));
87
        assertEquals(" .*?a", makeRegexp(" *a"));
86
        assertEquals(" .a", RegexpMaker.makeRegexp(" ?a"));
88
        assertEquals(" .a", makeRegexp(" ?a"));
87
        assertEquals(" a", RegexpMaker.makeRegexp("* a"));
89
        assertEquals(" a", makeRegexp("* a"));
88
        assertEquals(". a", RegexpMaker.makeRegexp("? a"));
90
        assertEquals(". a", makeRegexp("? a"));
89
        assertEquals("\\,a", RegexpMaker.makeRegexp("*,a"));
91
        assertEquals("\\,a", makeRegexp("*,a"));
90
        assertEquals(".\\,a", RegexpMaker.makeRegexp("?,a"));
92
        assertEquals(".\\,a", makeRegexp("?,a"));
91
        assertEquals("a.*? ", RegexpMaker.makeRegexp("a* "));
93
        assertEquals("a.*? ", makeRegexp("a* "));
92
        assertEquals("a. ", RegexpMaker.makeRegexp("a? "));
94
        assertEquals("a. ", makeRegexp("a? "));
93
        assertEquals("a ", RegexpMaker.makeRegexp("a *"));
95
        assertEquals("a ", makeRegexp("a *"));
94
        assertEquals("a .", RegexpMaker.makeRegexp("a ?"));
96
        assertEquals("a .", makeRegexp("a ?"));
95
        assertEquals("a\\,", RegexpMaker.makeRegexp("a,*"));
97
        assertEquals("a\\,", makeRegexp("a,*"));
96
        assertEquals("a\\,.", RegexpMaker.makeRegexp("a,?"));
98
        assertEquals("a\\,.", makeRegexp("a,?"));
97
99
98
        /* whole words: */
100
        /* whole words: */
99
101
Lines 101-251 Link Here
101
        final String checkNotAfterWordChar = getClassField("checkNotAfterWordChar");
103
        final String checkNotAfterWordChar = getClassField("checkNotAfterWordChar");
102
        final String checkNotBeforeWordChar = getClassField("checkNotBeforeWordChar");
104
        final String checkNotBeforeWordChar = getClassField("checkNotBeforeWordChar");
103
105
104
        assertEquals("", RegexpMaker.makeRegexp("", true));
106
        assertEquals("", makeRegexp("", true));
105
        assertEquals(checkNotAfterWordChar + "a" + checkNotBeforeWordChar,
107
        assertEquals(checkNotAfterWordChar + "a" + checkNotBeforeWordChar,
106
                     RegexpMaker.makeRegexp("a", true));
108
                     makeRegexp("a", true));
107
        assertEquals(checkNotAfterWordChar
109
        assertEquals(checkNotAfterWordChar
108
                     + "a" + wordCharsExpr + "*?b" + wordCharsExpr + "c"
110
                     + "a" + wordCharsExpr + "*?b" + wordCharsExpr + "c"
109
                     + checkNotBeforeWordChar,
111
                     + checkNotBeforeWordChar,
110
                     RegexpMaker.makeRegexp("a*b?c", true));
112
                     makeRegexp("a*b?c", true));
111
        assertEquals(checkNotAfterWordChar
113
        assertEquals(checkNotAfterWordChar
112
                     + "a" + wordCharsExpr + "{2,}?b"
114
                     + "a" + wordCharsExpr + "{2,}?b"
113
                     + checkNotBeforeWordChar,
115
                     + checkNotBeforeWordChar,
114
                     RegexpMaker.makeRegexp("a?*?b", true));
116
                     makeRegexp("a?*?b", true));
115
        assertEquals(checkNotAfterWordChar
117
        assertEquals(checkNotAfterWordChar
116
                     + "a" + wordCharsExpr + "+?b"
118
                     + "a" + wordCharsExpr + "+?b"
117
                     + checkNotBeforeWordChar,
119
                     + checkNotBeforeWordChar,
118
                     RegexpMaker.makeRegexp("a*?*b", true));
120
                     makeRegexp("a*?*b", true));
119
121
120
        assertEquals(wordCharsExpr + "*a" + checkNotBeforeWordChar,
122
        assertEquals(wordCharsExpr + "*a" + checkNotBeforeWordChar,
121
                     RegexpMaker.makeRegexp("*a", true));
123
                     makeRegexp("*a", true));
122
        assertEquals(checkNotAfterWordChar + wordCharsExpr + "a" + checkNotBeforeWordChar,
124
        assertEquals(checkNotAfterWordChar + wordCharsExpr + "a" + checkNotBeforeWordChar,
123
                     RegexpMaker.makeRegexp("?a", true));
125
                     makeRegexp("?a", true));
124
        assertEquals(wordCharsExpr + "*a" + checkNotBeforeWordChar,
126
        assertEquals(wordCharsExpr + "*a" + checkNotBeforeWordChar,
125
                     RegexpMaker.makeRegexp("**a", true));
127
                     makeRegexp("**a", true));
126
        assertEquals(wordCharsExpr + "+a" + checkNotBeforeWordChar,
128
        assertEquals(wordCharsExpr + "+a" + checkNotBeforeWordChar,
127
                     RegexpMaker.makeRegexp("*?a", true));
129
                     makeRegexp("*?a", true));
128
        assertEquals(wordCharsExpr + "+a" + checkNotBeforeWordChar,
130
        assertEquals(wordCharsExpr + "+a" + checkNotBeforeWordChar,
129
                     RegexpMaker.makeRegexp("?*a", true));
131
                     makeRegexp("?*a", true));
130
        assertEquals(checkNotAfterWordChar + wordCharsExpr + "{2}a" + checkNotBeforeWordChar,
132
        assertEquals(checkNotAfterWordChar + wordCharsExpr + "{2}a" + checkNotBeforeWordChar,
131
                     RegexpMaker.makeRegexp("??a", true));
133
                     makeRegexp("??a", true));
132
134
133
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "*",
135
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "*",
134
                     RegexpMaker.makeRegexp("a*", true));
136
                     makeRegexp("a*", true));
135
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + checkNotBeforeWordChar,
137
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + checkNotBeforeWordChar,
136
                     RegexpMaker.makeRegexp("a?", true));
138
                     makeRegexp("a?", true));
137
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "*",
139
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "*",
138
                     RegexpMaker.makeRegexp("a**", true));
140
                     makeRegexp("a**", true));
139
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "+",
141
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "+",
140
                     RegexpMaker.makeRegexp("a*?", true));
142
                     makeRegexp("a*?", true));
141
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "+",
143
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "+",
142
                     RegexpMaker.makeRegexp("a?*", true));
144
                     makeRegexp("a?*", true));
143
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "{2}" + checkNotBeforeWordChar,
145
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "{2}" + checkNotBeforeWordChar,
144
                     RegexpMaker.makeRegexp("a??", true));
146
                     makeRegexp("a??", true));
145
147
146
        assertEquals(" " + wordCharsExpr + "*?a" + checkNotBeforeWordChar,
148
        assertEquals(" " + wordCharsExpr + "*?a" + checkNotBeforeWordChar,
147
                     RegexpMaker.makeRegexp(" *a", true));
149
                     makeRegexp(" *a", true));
148
        assertEquals(" " + wordCharsExpr + "a" + checkNotBeforeWordChar,
150
        assertEquals(" " + wordCharsExpr + "a" + checkNotBeforeWordChar,
149
                     RegexpMaker.makeRegexp(" ?a", true));
151
                     makeRegexp(" ?a", true));
150
        assertEquals(wordCharsExpr + "* a" + checkNotBeforeWordChar,
152
        assertEquals(wordCharsExpr + "* a" + checkNotBeforeWordChar,
151
                     RegexpMaker.makeRegexp("* a", true));
153
                     makeRegexp("* a", true));
152
        assertEquals(checkNotAfterWordChar + wordCharsExpr + " a" + checkNotBeforeWordChar,
154
        assertEquals(checkNotAfterWordChar + wordCharsExpr + " a" + checkNotBeforeWordChar,
153
                     RegexpMaker.makeRegexp("? a", true));
155
                     makeRegexp("? a", true));
154
        assertEquals(wordCharsExpr + "*\\,a" + checkNotBeforeWordChar,
156
        assertEquals(wordCharsExpr + "*\\,a" + checkNotBeforeWordChar,
155
                     RegexpMaker.makeRegexp("*,a", true));
157
                     makeRegexp("*,a", true));
156
        assertEquals(checkNotAfterWordChar + wordCharsExpr + "\\,a" + checkNotBeforeWordChar,
158
        assertEquals(checkNotAfterWordChar + wordCharsExpr + "\\,a" + checkNotBeforeWordChar,
157
                     RegexpMaker.makeRegexp("?,a", true));
159
                     makeRegexp("?,a", true));
158
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "*? ",
160
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + "*? ",
159
                     RegexpMaker.makeRegexp("a* ", true));
161
                     makeRegexp("a* ", true));
160
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + " ",
162
        assertEquals(checkNotAfterWordChar + "a" + wordCharsExpr + " ",
161
                     RegexpMaker.makeRegexp("a? ", true));
163
                     makeRegexp("a? ", true));
162
        assertEquals(checkNotAfterWordChar + "a " + wordCharsExpr + "*",
164
        assertEquals(checkNotAfterWordChar + "a " + wordCharsExpr + "*",
163
                     RegexpMaker.makeRegexp("a *", true));
165
                     makeRegexp("a *", true));
164
        assertEquals(checkNotAfterWordChar + "a " + wordCharsExpr + checkNotBeforeWordChar,
166
        assertEquals(checkNotAfterWordChar + "a " + wordCharsExpr + checkNotBeforeWordChar,
165
                     RegexpMaker.makeRegexp("a ?", true));
167
                     makeRegexp("a ?", true));
166
        assertEquals(checkNotAfterWordChar + "a\\," + wordCharsExpr + "*",
168
        assertEquals(checkNotAfterWordChar + "a\\," + wordCharsExpr + "*",
167
                     RegexpMaker.makeRegexp("a,*", true));
169
                     makeRegexp("a,*", true));
168
        assertEquals(checkNotAfterWordChar + "a\\," + wordCharsExpr + checkNotBeforeWordChar,
170
        assertEquals(checkNotAfterWordChar + "a\\," + wordCharsExpr + checkNotBeforeWordChar,
169
                     RegexpMaker.makeRegexp("a,?", true));
171
                     makeRegexp("a,?", true));
170
172
171
        assertEquals("a b", RegexpMaker.makeRegexp("a b"));
173
        assertEquals("a b", makeRegexp("a b"));
172
        assertEquals("a\\!b", RegexpMaker.makeRegexp("a!b"));
174
        assertEquals("a\\!b", makeRegexp("a!b"));
173
        assertEquals("a\\\"b", RegexpMaker.makeRegexp("a\"b"));
175
        assertEquals("a\\\"b", makeRegexp("a\"b"));
174
        assertEquals("a\\#b", RegexpMaker.makeRegexp("a#b"));
176
        assertEquals("a\\#b", makeRegexp("a#b"));
175
        assertEquals("a\\$b", RegexpMaker.makeRegexp("a$b"));
177
        assertEquals("a\\$b", makeRegexp("a$b"));
176
        assertEquals("a\\%b", RegexpMaker.makeRegexp("a%b"));
178
        assertEquals("a\\%b", makeRegexp("a%b"));
177
        assertEquals("a\\&b", RegexpMaker.makeRegexp("a&b"));
179
        assertEquals("a\\&b", makeRegexp("a&b"));
178
        assertEquals("a\\'b", RegexpMaker.makeRegexp("a'b"));
180
        assertEquals("a\\'b", makeRegexp("a'b"));
179
        assertEquals("a\\(b", RegexpMaker.makeRegexp("a(b"));
181
        assertEquals("a\\(b", makeRegexp("a(b"));
180
        assertEquals("a\\)b", RegexpMaker.makeRegexp("a)b"));
182
        assertEquals("a\\)b", makeRegexp("a)b"));
181
        assertEquals("a\\+b", RegexpMaker.makeRegexp("a+b"));
183
        assertEquals("a\\+b", makeRegexp("a+b"));
182
        assertEquals("a\\,b", RegexpMaker.makeRegexp("a,b"));
184
        assertEquals("a\\,b", makeRegexp("a,b"));
183
        assertEquals("a\\-b", RegexpMaker.makeRegexp("a-b"));
185
        assertEquals("a\\-b", makeRegexp("a-b"));
184
        assertEquals("a\\.b", RegexpMaker.makeRegexp("a.b"));
186
        assertEquals("a\\.b", makeRegexp("a.b"));
185
        assertEquals("a\\/b", RegexpMaker.makeRegexp("a/b"));
187
        assertEquals("a\\/b", makeRegexp("a/b"));
186
        
188
        
187
        assertEquals("a0b", RegexpMaker.makeRegexp("a0b"));
189
        assertEquals("a0b", makeRegexp("a0b"));
188
        assertEquals("a1b", RegexpMaker.makeRegexp("a1b"));
190
        assertEquals("a1b", makeRegexp("a1b"));
189
        assertEquals("a2b", RegexpMaker.makeRegexp("a2b"));
191
        assertEquals("a2b", makeRegexp("a2b"));
190
        assertEquals("a3b", RegexpMaker.makeRegexp("a3b"));
192
        assertEquals("a3b", makeRegexp("a3b"));
191
        assertEquals("a4b", RegexpMaker.makeRegexp("a4b"));
193
        assertEquals("a4b", makeRegexp("a4b"));
192
        assertEquals("a5b", RegexpMaker.makeRegexp("a5b"));
194
        assertEquals("a5b", makeRegexp("a5b"));
193
        assertEquals("a6b", RegexpMaker.makeRegexp("a6b"));
195
        assertEquals("a6b", makeRegexp("a6b"));
194
        assertEquals("a7b", RegexpMaker.makeRegexp("a7b"));
196
        assertEquals("a7b", makeRegexp("a7b"));
195
        assertEquals("a8b", RegexpMaker.makeRegexp("a8b"));
197
        assertEquals("a8b", makeRegexp("a8b"));
196
        assertEquals("a9b", RegexpMaker.makeRegexp("a9b"));
198
        assertEquals("a9b", makeRegexp("a9b"));
197
        
199
        
198
        assertEquals("a\\:b", RegexpMaker.makeRegexp("a:b"));
200
        assertEquals("a\\:b", makeRegexp("a:b"));
199
        assertEquals("a\\;b", RegexpMaker.makeRegexp("a;b"));
201
        assertEquals("a\\;b", makeRegexp("a;b"));
200
        assertEquals("a\\<b", RegexpMaker.makeRegexp("a<b"));
202
        assertEquals("a\\<b", makeRegexp("a<b"));
201
        assertEquals("a\\=b", RegexpMaker.makeRegexp("a=b"));
203
        assertEquals("a\\=b", makeRegexp("a=b"));
202
        assertEquals("a\\>b", RegexpMaker.makeRegexp("a>b"));
204
        assertEquals("a\\>b", makeRegexp("a>b"));
203
        assertEquals("a\\@b", RegexpMaker.makeRegexp("a@b"));
205
        assertEquals("a\\@b", makeRegexp("a@b"));
204
        assertEquals("a\\[b", RegexpMaker.makeRegexp("a[b"));
206
        assertEquals("a\\[b", makeRegexp("a[b"));
205
        assertEquals("a\\\\a", RegexpMaker.makeRegexp("a\\a"));
207
        assertEquals("a\\\\a", makeRegexp("a\\a"));
206
        assertEquals("a\\\\b", RegexpMaker.makeRegexp("a\\b"));
208
        assertEquals("a\\\\b", makeRegexp("a\\b"));
207
        assertEquals("a\\\\c", RegexpMaker.makeRegexp("a\\c"));
209
        assertEquals("a\\\\c", makeRegexp("a\\c"));
208
        assertEquals("a\\\\d", RegexpMaker.makeRegexp("a\\d"));
210
        assertEquals("a\\\\d", makeRegexp("a\\d"));
209
        assertEquals("a\\\\e", RegexpMaker.makeRegexp("a\\e"));
211
        assertEquals("a\\\\e", makeRegexp("a\\e"));
210
        assertEquals("a\\\\f", RegexpMaker.makeRegexp("a\\f"));
212
        assertEquals("a\\\\f", makeRegexp("a\\f"));
211
        assertEquals("a\\\\g", RegexpMaker.makeRegexp("a\\g"));
213
        assertEquals("a\\\\g", makeRegexp("a\\g"));
212
        assertEquals("a\\\\h", RegexpMaker.makeRegexp("a\\h"));
214
        assertEquals("a\\\\h", makeRegexp("a\\h"));
213
        assertEquals("a\\\\i", RegexpMaker.makeRegexp("a\\i"));
215
        assertEquals("a\\\\i", makeRegexp("a\\i"));
214
        assertEquals("a\\\\j", RegexpMaker.makeRegexp("a\\j"));
216
        assertEquals("a\\\\j", makeRegexp("a\\j"));
215
        assertEquals("a\\\\k", RegexpMaker.makeRegexp("a\\k"));
217
        assertEquals("a\\\\k", makeRegexp("a\\k"));
216
        assertEquals("a\\\\l", RegexpMaker.makeRegexp("a\\l"));
218
        assertEquals("a\\\\l", makeRegexp("a\\l"));
217
        assertEquals("a\\\\m", RegexpMaker.makeRegexp("a\\m"));
219
        assertEquals("a\\\\m", makeRegexp("a\\m"));
218
        assertEquals("a\\\\n", RegexpMaker.makeRegexp("a\\n"));
220
        assertEquals("a\\\\n", makeRegexp("a\\n"));
219
        assertEquals("a\\\\o", RegexpMaker.makeRegexp("a\\o"));
221
        assertEquals("a\\\\o", makeRegexp("a\\o"));
220
        assertEquals("a\\\\p", RegexpMaker.makeRegexp("a\\p"));
222
        assertEquals("a\\\\p", makeRegexp("a\\p"));
221
        assertEquals("a\\\\q", RegexpMaker.makeRegexp("a\\q"));
223
        assertEquals("a\\\\q", makeRegexp("a\\q"));
222
        assertEquals("a\\\\r", RegexpMaker.makeRegexp("a\\r"));
224
        assertEquals("a\\\\r", makeRegexp("a\\r"));
223
        assertEquals("a\\\\s", RegexpMaker.makeRegexp("a\\s"));
225
        assertEquals("a\\\\s", makeRegexp("a\\s"));
224
        assertEquals("a\\\\t", RegexpMaker.makeRegexp("a\\t"));
226
        assertEquals("a\\\\t", makeRegexp("a\\t"));
225
        assertEquals("a\\\\u", RegexpMaker.makeRegexp("a\\u"));
227
        assertEquals("a\\\\u", makeRegexp("a\\u"));
226
        assertEquals("a\\\\v", RegexpMaker.makeRegexp("a\\v"));
228
        assertEquals("a\\\\v", makeRegexp("a\\v"));
227
        assertEquals("a\\\\w", RegexpMaker.makeRegexp("a\\w"));
229
        assertEquals("a\\\\w", makeRegexp("a\\w"));
228
        assertEquals("a\\\\x", RegexpMaker.makeRegexp("a\\x"));
230
        assertEquals("a\\\\x", makeRegexp("a\\x"));
229
        assertEquals("a\\\\y", RegexpMaker.makeRegexp("a\\y"));
231
        assertEquals("a\\\\y", makeRegexp("a\\y"));
230
        assertEquals("a\\\\z", RegexpMaker.makeRegexp("a\\z"));
232
        assertEquals("a\\\\z", makeRegexp("a\\z"));
231
        assertEquals("a\\]b", RegexpMaker.makeRegexp("a]b"));
233
        assertEquals("a\\]b", makeRegexp("a]b"));
232
        assertEquals("a\\^b", RegexpMaker.makeRegexp("a^b"));
234
        assertEquals("a\\^b", makeRegexp("a^b"));
233
        assertEquals("a\\_b", RegexpMaker.makeRegexp("a_b"));
235
        assertEquals("a\\_b", makeRegexp("a_b"));
234
        assertEquals("a\\`b", RegexpMaker.makeRegexp("a`b"));
236
        assertEquals("a\\`b", makeRegexp("a`b"));
235
        assertEquals("a\\{b", RegexpMaker.makeRegexp("a{b"));
237
        assertEquals("a\\{b", makeRegexp("a{b"));
236
        assertEquals("a\\|b", RegexpMaker.makeRegexp("a|b"));
238
        assertEquals("a\\|b", makeRegexp("a|b"));
237
        assertEquals("a\\}b", RegexpMaker.makeRegexp("a}b"));
239
        assertEquals("a\\}b", makeRegexp("a}b"));
238
        assertEquals("a\\~b", RegexpMaker.makeRegexp("a~b"));
240
        assertEquals("a\\~b", makeRegexp("a~b"));
239
        assertEquals("a\\\u007fb", RegexpMaker.makeRegexp("a\u007fb"));
241
        assertEquals("a\\\u007fb", makeRegexp("a\u007fb"));
240
        
242
        
241
        assertEquals("a\u0080b", RegexpMaker.makeRegexp("a\u0080b"));
243
        assertEquals("a\u0080b", makeRegexp("a\u0080b"));
242
        assertEquals("a\u00c1b", RegexpMaker.makeRegexp("a\u00c1b"));
244
        assertEquals("a\u00c1b", makeRegexp("a\u00c1b"));
243
        
245
        
244
        assertEquals("abc\\\\", RegexpMaker.makeRegexp("abc\\"));
246
        assertEquals("abc\\\\", makeRegexp("abc\\"));
245
        assertEquals("\\\\\\\"", RegexpMaker.makeRegexp("\\\""));
247
        assertEquals("\\\\\\\"", makeRegexp("\\\""));
246
        assertEquals("\\\\", RegexpMaker.makeRegexp("\\"));
248
        assertEquals("\\\\", makeRegexp("\\"));
247
        assertEquals("\\<h3 style\\=\\\\\\\"color\\: green\\;\\\\\\\"\\>\\<\\/h3\\>", 
249
        assertEquals("\\<h3 style\\=\\\\\\\"color\\: green\\;\\\\\\\"\\>\\<\\/h3\\>", 
248
                RegexpMaker.makeRegexp("<h3 style=\\\"color: green;\\\"></h3>"));
250
                makeRegexp("<h3 style=\\\"color: green;\\\"></h3>"));
249
        
251
        
250
    }
252
    }
251
253
Lines 300-306 Link Here
300
                            String simpleExpr,
302
                            String simpleExpr,
301
                            String expectedMatch,
303
                            String expectedMatch,
302
                            boolean wholeWords) {
304
                            boolean wholeWords) {
303
        String regexp = RegexpMaker.makeRegexp(simpleExpr, wholeWords);
305
        String regexp = makeRegexp(simpleExpr, wholeWords);
304
        Matcher matcher = Pattern.compile(regexp).matcher(testString);
306
        Matcher matcher = Pattern.compile(regexp).matcher(testString);
305
307
306
        if (expectedMatch == null) {
308
        if (expectedMatch == null) {
Lines 311-459 Link Here
311
        }
313
        }
312
    }
314
    }
313
    
315
    
314
    public void testMakeMultiRegexp() {
316
    public void testCanBeMultilinePattern() {
315
        assertEquals("", RegexpMaker.makeMultiRegexp(""));
317
        assertFalse(TextRegexpUtil.canBeMultilinePattern("a\\d\\d\\da"));
316
        assertEquals("a", RegexpMaker.makeMultiRegexp("a"));
318
        assertFalse(TextRegexpUtil.canBeMultilinePattern(".*"));
317
        assertEquals("ab", RegexpMaker.makeMultiRegexp("ab"));
319
        assertFalse(TextRegexpUtil.canBeMultilinePattern("(?m)^x.*y$"));
318
        assertEquals("abc", RegexpMaker.makeMultiRegexp("abc"));
320
        assertTrue(TextRegexpUtil.canBeMultilinePattern("(?ms-x)test.*test"));
319
        assertEquals("a.", RegexpMaker.makeMultiRegexp("a?"));
321
        assertTrue(TextRegexpUtil.canBeMultilinePattern("test\\ntest"));
320
        assertEquals("a.*", RegexpMaker.makeMultiRegexp("a*"));
322
        assertTrue(TextRegexpUtil.canBeMultilinePattern("test\\rtest"));
321
        assertEquals(".a", RegexpMaker.makeMultiRegexp("?a"));
323
        assertTrue(TextRegexpUtil.canBeMultilinePattern("test\\r\\ntest"));
322
        assertEquals(".*a", RegexpMaker.makeMultiRegexp("*a"));
324
        assertTrue(TextRegexpUtil.canBeMultilinePattern("test\\ftest"));
323
        assertEquals("a.b", RegexpMaker.makeMultiRegexp("a?b"));
325
        assertTrue(TextRegexpUtil.canBeMultilinePattern("test\\u000Btest"));
324
        assertEquals(".a.", RegexpMaker.makeMultiRegexp("?a?"));
326
        assertTrue(TextRegexpUtil.canBeMultilinePattern("test\\x85test"));
325
        assertEquals("a.*b.c", RegexpMaker.makeMultiRegexp("a*b?c"));
326
        assertEquals("a...*b", RegexpMaker.makeMultiRegexp("a?*?b"));
327
        assertEquals("a..*b", RegexpMaker.makeMultiRegexp("a*?*b"));
328
        
329
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a b"));
330
        assertEquals("a\\!b", RegexpMaker.makeMultiRegexp("a!b"));
331
        assertEquals("a\\\"b", RegexpMaker.makeMultiRegexp("a\"b"));
332
        assertEquals("a\\#b", RegexpMaker.makeMultiRegexp("a#b"));
333
        assertEquals("a\\$b", RegexpMaker.makeMultiRegexp("a$b"));
334
        assertEquals("a\\%b", RegexpMaker.makeMultiRegexp("a%b"));
335
        assertEquals("a\\&b", RegexpMaker.makeMultiRegexp("a&b"));
336
        assertEquals("a\\'b", RegexpMaker.makeMultiRegexp("a'b"));
337
        assertEquals("a\\(b", RegexpMaker.makeMultiRegexp("a(b"));
338
        assertEquals("a\\)b", RegexpMaker.makeMultiRegexp("a)b"));
339
        assertEquals("a\\+b", RegexpMaker.makeMultiRegexp("a+b"));
340
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a,b"));
341
        assertEquals("a\\-b", RegexpMaker.makeMultiRegexp("a-b"));
342
        assertEquals("a\\.b", RegexpMaker.makeMultiRegexp("a.b"));
343
        assertEquals("a\\/b", RegexpMaker.makeMultiRegexp("a/b"));
344
        
345
        assertEquals("a0b", RegexpMaker.makeMultiRegexp("a0b"));
346
        assertEquals("a1b", RegexpMaker.makeMultiRegexp("a1b"));
347
        assertEquals("a2b", RegexpMaker.makeMultiRegexp("a2b"));
348
        assertEquals("a3b", RegexpMaker.makeMultiRegexp("a3b"));
349
        assertEquals("a4b", RegexpMaker.makeMultiRegexp("a4b"));
350
        assertEquals("a5b", RegexpMaker.makeMultiRegexp("a5b"));
351
        assertEquals("a6b", RegexpMaker.makeMultiRegexp("a6b"));
352
        assertEquals("a7b", RegexpMaker.makeMultiRegexp("a7b"));
353
        assertEquals("a8b", RegexpMaker.makeMultiRegexp("a8b"));
354
        assertEquals("a9b", RegexpMaker.makeMultiRegexp("a9b"));
355
        
356
        assertEquals("a\\:b", RegexpMaker.makeMultiRegexp("a:b"));
357
        assertEquals("a\\;b", RegexpMaker.makeMultiRegexp("a;b"));
358
        assertEquals("a\\<b", RegexpMaker.makeMultiRegexp("a<b"));
359
        assertEquals("a\\=b", RegexpMaker.makeMultiRegexp("a=b"));
360
        assertEquals("a\\>b", RegexpMaker.makeMultiRegexp("a>b"));
361
        assertEquals("a\\@b", RegexpMaker.makeMultiRegexp("a@b"));
362
        assertEquals("a\\[b", RegexpMaker.makeMultiRegexp("a[b"));
363
        assertEquals("ab", RegexpMaker.makeMultiRegexp("a\\b"));
364
        assertEquals("a\\]b", RegexpMaker.makeMultiRegexp("a]b"));
365
        assertEquals("a\\^b", RegexpMaker.makeMultiRegexp("a^b"));
366
        assertEquals("a\\_b", RegexpMaker.makeMultiRegexp("a_b"));
367
        assertEquals("a\\`b", RegexpMaker.makeMultiRegexp("a`b"));
368
        assertEquals("a\\{b", RegexpMaker.makeMultiRegexp("a{b"));
369
        assertEquals("a\\|b", RegexpMaker.makeMultiRegexp("a|b"));
370
        assertEquals("a\\}b", RegexpMaker.makeMultiRegexp("a}b"));
371
        assertEquals("a\\~b", RegexpMaker.makeMultiRegexp("a~b"));
372
        assertEquals("a\\\u007fb", RegexpMaker.makeMultiRegexp("a\u007fb"));
373
        
374
        assertEquals("a\u0080b", RegexpMaker.makeMultiRegexp("a\u0080b"));
375
        assertEquals("a\u00c1b", RegexpMaker.makeMultiRegexp("a\u00c1b"));
376
        
377
        assertEquals("abc\\\\", RegexpMaker.makeRegexp("abc\\"));
378
        
379
        assertEquals("", RegexpMaker.makeMultiRegexp(""));
380
        assertEquals("", RegexpMaker.makeMultiRegexp(" "));
381
        assertEquals("", RegexpMaker.makeMultiRegexp(","));
382
        assertEquals("", RegexpMaker.makeMultiRegexp(", "));
383
        assertEquals("", RegexpMaker.makeMultiRegexp(" ,"));
384
        assertEquals("a", RegexpMaker.makeMultiRegexp("a,"));
385
        assertEquals("a", RegexpMaker.makeMultiRegexp("a "));
386
        assertEquals("a", RegexpMaker.makeMultiRegexp("a, "));
387
        assertEquals("a", RegexpMaker.makeMultiRegexp("a ,"));
388
        assertEquals("a", RegexpMaker.makeMultiRegexp(",a"));
389
        assertEquals("a", RegexpMaker.makeMultiRegexp(" a"));
390
        assertEquals("a", RegexpMaker.makeMultiRegexp(", a"));
391
        assertEquals("a", RegexpMaker.makeMultiRegexp(" ,a"));
392
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a b"));
393
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a,b"));
394
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a, b"));
395
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a ,b"));
396
        assertEquals(" ", RegexpMaker.makeMultiRegexp("\\ "));
397
        assertEquals("\\,", RegexpMaker.makeMultiRegexp("\\,"));
398
        assertEquals("\\,", RegexpMaker.makeMultiRegexp("\\, "));
399
        assertEquals(" ", RegexpMaker.makeMultiRegexp(",\\ "));
400
        assertEquals("\\, ", RegexpMaker.makeMultiRegexp("\\,\\ "));
401
        assertEquals(" ", RegexpMaker.makeMultiRegexp("\\ ,"));
402
        assertEquals("\\,", RegexpMaker.makeMultiRegexp(" \\,"));
403
        assertEquals(" \\,", RegexpMaker.makeMultiRegexp("\\ \\,"));
404
        assertEquals("a", RegexpMaker.makeMultiRegexp("\\a,"));
405
        assertEquals("a\\,", RegexpMaker.makeMultiRegexp("a\\,"));
406
        assertEquals("a\\,", RegexpMaker.makeMultiRegexp("\\a\\,"));
407
        assertEquals("a", RegexpMaker.makeMultiRegexp("\\a "));
408
        assertEquals("a ", RegexpMaker.makeMultiRegexp("a\\ "));
409
        assertEquals("a ", RegexpMaker.makeMultiRegexp("\\a\\ "));
410
        assertEquals("a|\\\\", RegexpMaker.makeMultiRegexp("a, \\"));
411
        assertEquals("a| ", RegexpMaker.makeMultiRegexp("a,\\ "));
412
        assertEquals("a| \\\\", RegexpMaker.makeMultiRegexp("a,\\ \\"));
413
        assertEquals("a\\,", RegexpMaker.makeMultiRegexp("a\\, "));
414
        assertEquals("a\\,|\\\\", RegexpMaker.makeMultiRegexp("a\\, \\"));
415
        assertEquals("a\\, ", RegexpMaker.makeMultiRegexp("a\\,\\ "));
416
        assertEquals("a\\, \\\\", RegexpMaker.makeMultiRegexp("a\\,\\ \\"));
417
        assertEquals("a", RegexpMaker.makeMultiRegexp("\\a, "));
418
        assertEquals("a|\\\\", RegexpMaker.makeMultiRegexp("\\a, \\"));
419
        assertEquals("a| ", RegexpMaker.makeMultiRegexp("\\a,\\ "));
420
        assertEquals("a| \\\\", RegexpMaker.makeMultiRegexp("\\a,\\ \\"));
421
        assertEquals("a\\,", RegexpMaker.makeMultiRegexp("\\a\\, "));
422
        assertEquals("a\\,|\\\\", RegexpMaker.makeMultiRegexp("\\a\\, \\"));
423
        assertEquals("a\\, ", RegexpMaker.makeMultiRegexp("\\a\\,\\ "));
424
        assertEquals("a\\, \\\\", RegexpMaker.makeMultiRegexp("\\a\\,\\ \\"));
425
        assertEquals("a|\\\\", RegexpMaker.makeMultiRegexp("a ,\\"));
426
        assertEquals("a|\\,", RegexpMaker.makeMultiRegexp("a \\,"));
427
        assertEquals("a|\\,\\\\", RegexpMaker.makeMultiRegexp("a \\,\\"));
428
        assertEquals("a ", RegexpMaker.makeMultiRegexp("a\\ ,"));
429
        assertEquals("a |\\\\", RegexpMaker.makeMultiRegexp("a\\ ,\\"));
430
        assertEquals("a \\,", RegexpMaker.makeMultiRegexp("a\\ \\,"));
431
        assertEquals("a \\,\\\\", RegexpMaker.makeMultiRegexp("a\\ \\,\\"));
432
        assertEquals("a", RegexpMaker.makeMultiRegexp("\\a ,"));
433
        assertEquals("a|\\\\", RegexpMaker.makeMultiRegexp("\\a ,\\"));
434
        assertEquals("a|\\,", RegexpMaker.makeMultiRegexp("\\a \\,"));
435
        assertEquals("a|\\,\\\\", RegexpMaker.makeMultiRegexp("\\a \\,\\"));
436
        assertEquals("a ", RegexpMaker.makeMultiRegexp("\\a\\ ,"));
437
        assertEquals("a |\\\\", RegexpMaker.makeMultiRegexp("\\a\\ ,\\"));
438
        assertEquals("a \\,", RegexpMaker.makeMultiRegexp("\\a\\ \\,"));
439
        assertEquals("a \\,\\\\", RegexpMaker.makeMultiRegexp("\\a\\ \\,\\"));
440
        
441
        assertEquals("a|b", RegexpMaker.makeMultiRegexp("a, b"));
442
        assertEquals("a|.*b.", RegexpMaker.makeMultiRegexp("a,*b?"));
443
        assertEquals("a|\\*b.", RegexpMaker.makeMultiRegexp("a,\\*b?"));
444
        assertEquals("a|.*b\\?", RegexpMaker.makeMultiRegexp("a,*b\\?"));
445
    }
327
    }
446
    
328
447
    public void testCanBeMultilinePattern() {
329
    public void testLiteralMatches() {
448
        assertFalse(RegexpMaker.canBeMultilinePattern("a\\d\\d\\da"));
330
        SearchPattern sp = SearchPattern.create("a*b", false, false,
449
        assertFalse(RegexpMaker.canBeMultilinePattern(".*"));
331
                MatchType.LITERAL);
450
        assertFalse(RegexpMaker.canBeMultilinePattern("(?m)^x.*y$"));
332
        Pattern p = TextRegexpUtil.makeTextPattern(sp);
451
        assertTrue(RegexpMaker.canBeMultilinePattern("(?ms-x)test.*test"));
333
        assertTrue(p.matcher("xxxa*byyy").find());
452
        assertTrue(RegexpMaker.canBeMultilinePattern("test\\ntest"));
334
        assertFalse(p.matcher("xxxaSSbyyy").find());
453
        assertTrue(RegexpMaker.canBeMultilinePattern("test\\rtest"));
335
454
        assertTrue(RegexpMaker.canBeMultilinePattern("test\\r\\ntest"));
336
        sp = sp.changeSearchExpression("a?b");
455
        assertTrue(RegexpMaker.canBeMultilinePattern("test\\ftest"));
337
        p = TextRegexpUtil.makeTextPattern(sp);
456
        assertTrue(RegexpMaker.canBeMultilinePattern("test\\u000Btest"));
338
        assertTrue(p.matcher("xxxa?byyy").find());
457
        assertTrue(RegexpMaker.canBeMultilinePattern("test\\x85test"));
339
        assertFalse(p.matcher("xxxaSbyyy").find());
340
341
        sp = sp.changeSearchExpression("a?b*c*d?e");
342
        p = TextRegexpUtil.makeTextPattern(sp);
343
        assertTrue(p.matcher("xxxa?b*c*d?eyyy").find());
344
        assertFalse(p.matcher("xxxa?b*cudweyyy").find());
345
    }
346
347
    private String makeRegexp(String string) {
348
        return TextRegexpUtil.makeTextPattern(
349
                SearchPattern.create(string, false, false, MatchType.BASIC))
350
                .pattern();
351
    }
352
353
    private String makeRegexp(String string, boolean wholeWords) {
354
        return TextRegexpUtil.makeTextPattern(
355
                SearchPattern.create(
356
                string, wholeWords, false, MatchType.BASIC)).pattern();
458
    }
357
    }
459
}
358
}

Return to bug 224328