Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 144355 | Differences between
and this patch

Collapse All | Expand All

(-)JFaceTextTestSuite.launch (+7 lines)
Lines 4-9 Link Here
4
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
4
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
5
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.jface.text.tests.JFaceTextTestSuite"/>
5
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.jface.text.tests.JFaceTextTestSuite"/>
6
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
6
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
7
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
8
<listEntry value="4"/>
9
</listAttribute>
7
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
10
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
8
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;org.eclipse.jface.text.tests&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
11
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;org.eclipse.jface.text.tests&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
9
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento project=&quot;org.eclipse.jface.text.tests&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
12
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento project=&quot;org.eclipse.jface.text.tests&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
Lines 12-17 Link Here
12
</listAttribute>
15
</listAttribute>
13
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jface.text.tests"/>
16
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jface.text.tests"/>
14
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.library.path=${workspace_loc}/org.eclipse.swt.${system:OS}.${system:WS}.${system:ARCH}/"/>
17
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.library.path=${workspace_loc}/org.eclipse.swt.${system:OS}.${system:WS}.${system:ARCH}/"/>
18
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
19
<listEntry value="/org.eclipse.jface.text.tests"/>
20
</listAttribute>
15
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
21
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
16
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
22
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
23
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
17
</launchConfiguration>
24
</launchConfiguration>
(-)src/org/eclipse/jface/text/tests/rules/WordRuleTest.java (+53 lines)
Lines 55-58 Link Here
55
		assertTrue(i < 1000);
55
		assertTrue(i < 1000);
56
56
57
	}
57
	}
58
	
59
	/*
60
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=144355
61
	 */
62
	public void testBug144355() throws Exception {
63
		IWordDetector detector= new IWordDetector() {
64
65
			public boolean isWordPart(char c) {
66
				return true;
67
			}
68
69
			public boolean isWordStart(char c) {
70
				return true;
71
			}
72
73
		};
74
		
75
		String defaultTokenString = "defaultToken";
76
		Token defaultToken = new Token(defaultTokenString);
77
		
78
		String testTokenStringNormal = "TestTokenString";
79
		String testTokenStringDifferentCapitalization = "TestTOKENString";
80
		String testTokenStringCompletelyDifferent = "XXX";
81
		Token normalToken = new Token(testTokenStringNormal);
82
		
83
		WordRule rule= new WordRule(detector, defaultToken);
84
		rule.setIgnoreCase(true);
85
		rule.addWord(testTokenStringNormal, normalToken);
86
		
87
		// scenario 1
88
		// pre: pass in a normal string ("TestTokenString")
89
		// post: expect the normal token to be returned
90
		RuleBasedScanner scanner= new RuleBasedScanner();
91
		scanner.setRules(new IRule[] {rule});
92
		scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
93
		assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
94
		
95
		// scenario 2
96
		// pre: pass in a normal string but different capitalization ("TestTOKENString")
97
		// post: expect the normal token to be returned
98
		scanner= new RuleBasedScanner();
99
		scanner.setRules(new IRule[] {rule});
100
		scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
101
		assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
102
		
103
		// scenario 3
104
		// pre: pass in a completely different string ("XXX")
105
		// post: expect the default token to be returned because the string can't be matched
106
		scanner= new RuleBasedScanner();
107
		scanner.setRules(new IRule[] {rule});
108
		scanner.setRange(new Document(testTokenStringCompletelyDifferent), 0, testTokenStringCompletelyDifferent.length());
109
		assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
110
	}
58
}
111
}
(-)src/org/eclipse/jface/text/rules/WordRule.java (-3 / +43 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 42-47 Link Here
42
	protected Map fWords= new HashMap();
42
	protected Map fWords= new HashMap();
43
	/** Buffer used for pattern detection */
43
	/** Buffer used for pattern detection */
44
	private StringBuffer fBuffer= new StringBuffer();
44
	private StringBuffer fBuffer= new StringBuffer();
45
	/** The boolean repsenting whether we should be case sensitive */
46
	private boolean fIgnoreCase = false;
45
47
46
	/**
48
	/**
47
	 * Creates a rule which, with the help of an word detector, will return the token
49
	 * Creates a rule which, with the help of an word detector, will return the token
Lines 76-81 Link Here
76
		fDetector= detector;
78
		fDetector= detector;
77
		fDefaultToken= defaultToken;
79
		fDefaultToken= defaultToken;
78
	}
80
	}
81
	
82
	/**
83
	 * Creates a rule which, with the help of a word detector, will return the token
84
	 * associated with the detected word. If no token has been associated, the
85
	 * specified default token will be returned.
86
	 *
87
	 * @param detector the word detector to be used by this rule, may not be <code>null</code>
88
	 * @param defaultToken the default token to be returned on success
89
	 *		if nothing else is specified, may not be <code>null</code>
90
	 * @param ignoreCase the case sensitivity associated with the rule
91
	 *
92
	 * @see #addWord(String, IToken)
93
	 */
94
	public WordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase) {
95
96
		Assert.isNotNull(detector);
97
		Assert.isNotNull(defaultToken);
98
99
		fDetector= detector;
100
		fDefaultToken= defaultToken;
101
		setIgnoreCase(ignoreCase);
102
	}
79
103
80
	/**
104
	/**
81
	 * Adds a word and the token to be returned if it is detected.
105
	 * Adds a word and the token to be returned if it is detected.
Lines 87-93 Link Here
87
		Assert.isNotNull(word);
111
		Assert.isNotNull(word);
88
		Assert.isNotNull(token);
112
		Assert.isNotNull(token);
89
113
90
		fWords.put(word, token);
114
		if(!fIgnoreCase)
115
			fWords.put(word, token);
116
		else
117
			fWords.put(word.toUpperCase(), token);
91
	}
118
	}
92
119
93
	/**
120
	/**
Lines 118-125 Link Here
118
					c= scanner.read();
145
					c= scanner.read();
119
				} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
146
				} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
120
				scanner.unread();
147
				scanner.unread();
148
				
149
				String buffer= fIgnoreCase ? fBuffer.toString().toUpperCase() : fBuffer.toString();
121
150
122
				IToken token= (IToken) fWords.get(fBuffer.toString());
151
				IToken token= (IToken) fWords.get(buffer);
123
				if (token != null)
152
				if (token != null)
124
					return token;
153
					return token;
125
154
Lines 143-146 Link Here
143
		for (int i= fBuffer.length() - 1; i >= 0; i--)
172
		for (int i= fBuffer.length() - 1; i >= 0; i--)
144
			scanner.unread();
173
			scanner.unread();
145
	}
174
	}
175
176
	/**
177
	 * Sets the case sensitivity for this rule 
178
	 * 
179
	 * @param value the case sensitivity value
180
	 * @since 3.3
181
	 */
182
	public void setIgnoreCase(boolean value) {
183
		this.fIgnoreCase = value;
184
	}
185
	
146
}
186
}

Return to bug 144355