View | Details | Raw Unified | Return to bug 174349 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/dialogs/SearchPattern.java (-10 / +27 lines)
Lines 17-23 Link Here
17
 * 
17
 * 
18
 * <p>
18
 * <p>
19
 * This class is intended to be subclassed by clients. A default behavior is
19
 * This class is intended to be subclassed by clients. A default behavior is
20
 * provided for each of the methods above, that clients can override if they
20
 * provided for each of the methods above, that clients can ovveride if they
21
 * wish.
21
 * wish.
22
 * </p>
22
 * </p>
23
 * 
23
 * 
Lines 207-223 Link Here
207
			return;
207
			return;
208
		}
208
		}
209
209
210
		if (last == END_SYMBOL || last == BLANK) {
211
			matchRule = RULE_EXACT_MATCH;
212
			stringPattern = pattern.substring(0, length - 1);
213
			return;
214
		}
215
216
		if (validateMatchRule(pattern, RULE_CAMELCASE_MATCH) == RULE_CAMELCASE_MATCH) {
210
		if (validateMatchRule(pattern, RULE_CAMELCASE_MATCH) == RULE_CAMELCASE_MATCH) {
217
			matchRule = RULE_CAMELCASE_MATCH;
211
			matchRule = RULE_CAMELCASE_MATCH;
218
			stringPattern = pattern;
212
			stringPattern = pattern;
219
			return;
213
			return;
220
		}
214
		}
215
		
216
		if (last == END_SYMBOL || last == BLANK) {
217
			matchRule = RULE_EXACT_MATCH;
218
			stringPattern = pattern.substring(0, length - 1);
219
			return;
220
		}
221
221
222
		matchRule = RULE_PREFIX_MATCH;
222
		matchRule = RULE_PREFIX_MATCH;
223
		stringPattern = pattern;
223
		stringPattern = pattern;
Lines 437-442 Link Here
437
			return false;
437
			return false;
438
		}
438
		}
439
439
440
		int patternLength = patternEnd;
441
		
442
		if (pattern.charAt(patternEnd - 1) == END_SYMBOL || pattern.charAt(patternEnd - 1) == BLANK )
443
			patternLength = patternEnd - 1;
444
445
440
		char patternChar, nameChar;
446
		char patternChar, nameChar;
441
		int iPattern = patternStart;
447
		int iPattern = patternStart;
442
		int iName = nameStart;
448
		int iName = nameStart;
Lines 453-458 Link Here
453
			}
459
			}
454
460
455
			if (iName == nameEnd) {
461
			if (iName == nameEnd) {
462
				if (iPattern == patternLength) 
463
					return true;
456
				// We have exhausted name (and not pattern), so it's not a match
464
				// We have exhausted name (and not pattern), so it's not a match
457
				return false;
465
				return false;
458
			}
466
			}
Lines 472-484 Link Here
472
			// name
480
			// name
473
			while (true) {
481
			while (true) {
474
				if (iName == nameEnd) {
482
				if (iName == nameEnd) {
475
					// We have exhausted name (and not pattern), so it's not a
483
					if ((iPattern == patternLength) && (patternChar == END_SYMBOL || patternChar == BLANK))
476
					// match
484
						return true;
477
					return false;
485
					return false;
478
				}
486
				}
479
487
480
				nameChar = name.charAt(iName);
488
				nameChar = name.charAt(iName);
481
489
490
				if ((iPattern == patternLength) && (patternChar == END_SYMBOL || patternChar == BLANK)) {
491
					if (isNameCharAllowed(nameChar)) {
492
						return false;
493
					}
494
					iName++;
495
					continue;
496
				}
497
482
				if (!isNameCharAllowed(nameChar)) {
498
				if (!isNameCharAllowed(nameChar)) {
483
					// nameChar is lowercase
499
					// nameChar is lowercase
484
					iName++;
500
					iName++;
Lines 505-511 Link Here
505
	 * @return true if patternChar is in set of allowed characters for pattern
521
	 * @return true if patternChar is in set of allowed characters for pattern
506
	 */
522
	 */
507
	protected boolean isPatternCharAllowed(char patternChar) {
523
	protected boolean isPatternCharAllowed(char patternChar) {
508
		return Character.isUpperCase(patternChar);
524
		return Character.isUpperCase(patternChar) || patternChar == END_SYMBOL
525
				|| patternChar == BLANK;
509
	}
526
	}
510
527
511
	/**
528
	/**
(-)Eclipse UI Tests/org/eclipse/ui/tests/dialogs/SearchPatternAuto.java (-7 / +41 lines)
Lines 80-90 Link Here
80
	
80
	
81
	/**
81
	/**
82
	 * Tests exact match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
82
	 * Tests exact match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
83
	 * Result for "aBcD " pattern should be similar to regexp pattern "abcd" with case insensitive.
83
	 * Result for "abcd " pattern should be similar to regexp pattern "abcd" with case insensitive.
84
	 */
84
	 */
85
	public void testExactMatch1() {
85
	public void testExactMatch1() {
86
		String patternText = "aBcD ";
86
		String patternText = "abcd ";
87
		Pattern pattern = Pattern.compile("aBcD", Pattern.CASE_INSENSITIVE);
87
		Pattern pattern = Pattern.compile("abcd", Pattern.CASE_INSENSITIVE);
88
		SearchPattern patternMatcher = new SearchPattern();
88
		SearchPattern patternMatcher = new SearchPattern();
89
		patternMatcher.setPattern(patternText);
89
		patternMatcher.setPattern(patternText);
90
		assertEquals(patternMatcher.getMatchRule(), SearchPattern.RULE_EXACT_MATCH);
90
		assertEquals(patternMatcher.getMatchRule(), SearchPattern.RULE_EXACT_MATCH);
Lines 96-106 Link Here
96
	
96
	
97
	/**
97
	/**
98
	 * Tests exact match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
98
	 * Tests exact match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
99
	 * Result for "AbCdEfGh<" pattern should be similar to regexp pattern "AbCdEfGh" with case insensitive.
99
	 * Result for "abcdefgh " pattern should be similar to regexp pattern "abcdefgh" with case insensitive.
100
	 */
100
	 */
101
	public void testExactMatch2() {
101
	public void testExactMatch2() {
102
		String patternText = "AbCdEfGh<";
102
		String patternText = "abcdefgh<";
103
		Pattern pattern = Pattern.compile("AbCdEfGh", Pattern.CASE_INSENSITIVE);
103
		Pattern pattern = Pattern.compile("abcdefgh", Pattern.CASE_INSENSITIVE);
104
		SearchPattern patternMatcher = new SearchPattern();
104
		SearchPattern patternMatcher = new SearchPattern();
105
		patternMatcher.setPattern(patternText);
105
		patternMatcher.setPattern(patternText);
106
		assertEquals(patternMatcher.getMatchRule(), SearchPattern.RULE_EXACT_MATCH);
106
		assertEquals(patternMatcher.getMatchRule(), SearchPattern.RULE_EXACT_MATCH);
Lines 164-170 Link Here
164
	 * Result for "CD" SearchPattern should be similar to regexp pattern "C[^A-Z]*D.*" or "CD.*"
164
	 * Result for "CD" SearchPattern should be similar to regexp pattern "C[^A-Z]*D.*" or "CD.*"
165
	 * If pattern contains only upperCase characters result contains all prefix match elements.
165
	 * If pattern contains only upperCase characters result contains all prefix match elements.
166
	 */
166
	 */
167
	public void testCamelCaseMatch() {
167
	public void testCamelCaseMatch1() {
168
		String patternText = "CD";
168
		String patternText = "CD";
169
		Pattern pattern = Pattern.compile("C[^A-Z]*D.*");
169
		Pattern pattern = Pattern.compile("C[^A-Z]*D.*");
170
		Pattern pattern2 = Pattern.compile("CD.*", Pattern.CASE_INSENSITIVE);
170
		Pattern pattern2 = Pattern.compile("CD.*", Pattern.CASE_INSENSITIVE);
Lines 180-185 Link Here
180
	}
180
	}
181
	
181
	
182
	/**
182
	/**
183
	 * Tests camelCase match functionality.
184
	 * Every string starts with upperCase characters should be recognize as camelCase pattern match rule.
185
	 * Result for "AbCd " SearchPattern should be similar to regexp pattern "C[^A-Z]*D.*" or "CD.*"
186
	 */
187
	public void testCamelCaseMatch2() {
188
		String patternText = "AbCd ";
189
		Pattern pattern = Pattern.compile("Ab[^A-Z]*Cd[^A-Z]*");
190
		SearchPattern patternMatcher = new SearchPattern();
191
		patternMatcher.setPattern(patternText);
192
		assertEquals(patternMatcher.getMatchRule(), SearchPattern.RULE_CAMELCASE_MATCH);
193
		for (Iterator iter = resources.iterator(); iter.hasNext();) {
194
			String res = (String) iter.next();
195
			assertEquals(patternMatcher.matches(res), pattern.matcher(res).matches());
196
		}
197
	}
198
	
199
	/**
200
	 * Tests camelCase match functionality.
201
	 * Every string starts with upperCase characters should be recognize as camelCase pattern match rule.
202
	 * Result for "AbCdE<" SearchPattern should be similar to regexp pattern "Ab[^A-Z]*Cd[^A-Z]*E[^A-Z]*"
203
	 */
204
	public void testCamelCaseMatch3() {
205
		String patternText = "AbCdE<";
206
		Pattern pattern = Pattern.compile("Ab[^A-Z]*Cd[^A-Z]*E[^A-Z]*");
207
		SearchPattern patternMatcher = new SearchPattern();
208
		patternMatcher.setPattern(patternText);
209
		assertEquals(patternMatcher.getMatchRule(), SearchPattern.RULE_CAMELCASE_MATCH);
210
		for (Iterator iter = resources.iterator(); iter.hasNext();) {
211
			String res = (String) iter.next();
212
			assertEquals(patternMatcher.matches(res), pattern.matcher(res).matches());
213
		}
214
	}
215
	
216
	/**
183
	 * Tests blank match functionality. 
217
	 * Tests blank match functionality. 
184
	 * Blank string should be recognize as blank pattern match rule.
218
	 * Blank string should be recognize as blank pattern match rule.
185
	 * It should match with all resources.
219
	 * It should match with all resources.

Return to bug 174349