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/src/org/netbeans/api/search/SearchPattern.java (-8 / +18 lines)
Lines 69-81 Link Here
69
        /**
69
        /**
70
         * Match the pattern literally.
70
         * Match the pattern literally.
71
         */
71
         */
72
        LITERAL(Bundle.LBL_MatchType_Literal(), 'r'),
72
        LITERAL(Bundle.LBL_MatchType_Literal(), 'L'),
73
        /**
73
        /**
74
         * The pattern can contain basic wildcards, star (*) for any string and
74
         * The pattern can contain basic wildcards, star (*) for any string and
75
         * questionaire (?) for any character. The escape character for these
75
         * questionaire (?) for any character. The escape character for these
76
         * wildcards is backslash (\).
76
         * wildcards is backslash (\).
77
         */
77
         */
78
        BASIC(Bundle.LBL_MatchType_Basic_Wildcards(), 'B'),
78
        BASIC(Bundle.LBL_MatchType_Basic_Wildcards(), 'r'),
79
        /**
79
        /**
80
         * The pattern follows java.util.regex.Pattern syntax.
80
         * The pattern follows java.util.regex.Pattern syntax.
81
         */
81
         */
Lines 102-114 Link Here
102
                case 'R':
102
                case 'R':
103
                    return REGEXP;
103
                    return REGEXP;
104
                case 'r':
104
                case 'r':
105
                    return BASIC;
106
                case 'L':
105
                    return LITERAL;
107
                    return LITERAL;
106
                case 'B':
108
                default:
107
                    return BASIC;
109
                    return BASIC;
108
                default:
109
                    return LITERAL;
110
            }
110
            }
111
        }
111
        }
112
113
        private static boolean isCanonicalPatternFlag(char ch) {
114
            for (MatchType mt : MatchType.values()) {
115
                if (mt.getCanonicalPatternFlag() == ch) {
116
                    return true;
117
                }
118
            }
119
            return false;
120
        }
112
    }
121
    }
113
122
114
    /**
123
    /**
Lines 150-162 Link Here
150
     * @param searchExpression non-null String of a searched text
159
     * @param searchExpression non-null String of a searched text
151
     * @param wholeWords if true, only whole words were searched
160
     * @param wholeWords if true, only whole words were searched
152
     * @param matchCase if true, case sensitive search was preformed
161
     * @param matchCase if true, case sensitive search was preformed
153
     * @param regExp if true, regular expression search was performed
162
     * @param regExp if true, regular expression search was performed; if false,
163
     * search with basic wildcards was performed
154
     * @return a new SearchPattern in accordance with given parameters
164
     * @return a new SearchPattern in accordance with given parameters
155
     */
165
     */
156
    public static SearchPattern create(String searchExpression, boolean wholeWords,
166
    public static SearchPattern create(String searchExpression, boolean wholeWords,
157
            boolean matchCase, boolean regExp) {
167
            boolean matchCase, boolean regExp) {
158
        return new SearchPattern(searchExpression, wholeWords, matchCase,
168
        return new SearchPattern(searchExpression, wholeWords, matchCase,
159
                regExp ? MatchType.REGEXP : MatchType.LITERAL);
169
                regExp ? MatchType.REGEXP : MatchType.BASIC);
160
    }
170
    }
161
171
162
    /**
172
    /**
Lines 320-326 Link Here
320
        //format mrw-findwhat
330
        //format mrw-findwhat
321
        if (canonicalString == null
331
        if (canonicalString == null
322
                || Character.toUpperCase(canonicalString.charAt(0)) != 'M'
332
                || Character.toUpperCase(canonicalString.charAt(0)) != 'M'
323
                || Character.toUpperCase(canonicalString.charAt(1)) != 'R'
333
                || !MatchType.isCanonicalPatternFlag(canonicalString.charAt(1))
324
                || Character.toUpperCase(canonicalString.charAt(2)) != 'W'
334
                || Character.toUpperCase(canonicalString.charAt(2)) != 'W'
325
                || canonicalString.charAt(3) != '-') {
335
                || canonicalString.charAt(3) != '-') {
326
            return null;
336
            return null;
(-)a/api.search/test/unit/src/org/netbeans/api/search/SearchPatternTest.java (-2 / +23 lines)
Lines 55-60 Link Here
55
        assertFalse(sp.isRegExp());
55
        assertFalse(sp.isRegExp());
56
        assertTrue(sp.isWholeWords());
56
        assertTrue(sp.isWholeWords());
57
        assertEquals("Test", sp.getSearchExpression());
57
        assertEquals("Test", sp.getSearchExpression());
58
        assertEquals(MatchType.BASIC, sp.getMatchType());
59
    }
60
61
    @Test
62
    public void testManuallyParseRegexp() throws Exception {
63
        String canString = "MRW-Test";
64
        SearchPattern sp = SearchPattern.parsePattern(canString);
65
        assertEquals(MatchType.REGEXP, sp.getMatchType());
66
    }
67
68
    @Test
69
    public void testManuallyParseLiteral() throws Exception {
70
        String canString = "MLW-Test";
71
        SearchPattern sp = SearchPattern.parsePattern(canString);
72
        assertEquals(MatchType.LITERAL, sp.getMatchType());
58
    }
73
    }
59
74
60
    @Test
75
    @Test
Lines 63-68 Link Here
63
        String canString = sp.toCanonicalString();
78
        String canString = sp.toCanonicalString();
64
        
79
        
65
        assertEquals("mRW-ta", canString);
80
        assertEquals("mRW-ta", canString);
81
82
        sp = sp.changeMatchType(MatchType.BASIC);
83
        assertEquals("mrW-ta", sp.toCanonicalString());
84
85
        sp = sp.changeMatchType(MatchType.LITERAL);
86
        assertEquals("mLW-ta", sp.toCanonicalString());
66
    }
87
    }
67
88
68
    @Test
89
    @Test
Lines 95-102 Link Here
95
                false, false, true).changeMatchType(MatchType.BASIC)
116
                false, false, true).changeMatchType(MatchType.BASIC)
96
                .getMatchType());
117
                .getMatchType());
97
118
98
        assertEquals("If not specified exactly, match type should be LITERAL",
119
        assertEquals("If not specified exactly, match type should be BASIC",
99
                MatchType.LITERAL, SearchPattern.create("test",
120
                MatchType.BASIC, SearchPattern.create("test",
100
                false, false, false).getMatchType());
121
                false, false, false).getMatchType());
101
    }
122
    }
102
}
123
}

Return to bug 224328