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 (+72 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, true);
84
		rule.addWord(testTokenStringNormal, normalToken);
85
		
86
		// scenario 1
87
		// pre: pass in a normal string ("TestTokenString")
88
		// post: expect the normal token to be returned
89
		RuleBasedScanner scanner= new RuleBasedScanner();
90
		scanner.setRules(new IRule[] {rule});
91
		scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
92
		assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
93
		
94
		// scenario 2
95
		// pre: pass in a normal string but different capitalization ("TestTOKENString")
96
		// post: expect the normal token to be returned
97
		scanner= new RuleBasedScanner();
98
		scanner.setRules(new IRule[] {rule});
99
		scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
100
		assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
101
		
102
		// scenario 3
103
		// pre: pass in a completely different string ("XXX")
104
		// post: expect the default token to be returned because the string can't be matched
105
		scanner= new RuleBasedScanner();
106
		scanner.setRules(new IRule[] {rule});
107
		scanner.setRange(new Document(testTokenStringCompletelyDifferent), 0, testTokenStringCompletelyDifferent.length());
108
		assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
109
		
110
		WordRule ruleWithoutIgnoreCase= new WordRule(detector, defaultToken);
111
		ruleWithoutIgnoreCase.addWord(testTokenStringNormal, normalToken);
112
		
113
		// scenario 4
114
		// pre: pass in a normal string ("TestTokenString")
115
		// post: expect the normal token to be returned
116
		scanner= new RuleBasedScanner();
117
		scanner.setRules(new IRule[] {ruleWithoutIgnoreCase});
118
		scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
119
		assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
120
		
121
		// scenario 5
122
		// pre: pass in a normal string but different capitalization ("TestTOKENString")
123
		// post: expect the default token to be returned
124
		scanner= new RuleBasedScanner();
125
		scanner.setRules(new IRule[] {ruleWithoutIgnoreCase});
126
		scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
127
		assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
128
	}
129
	
58
}
130
}
(-)src/org/eclipse/jface/text/rules/WordRule.java (-2 / +44 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 12-18 Link Here
12
12
13
13
14
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.Iterator;
15
import java.util.Map;
16
import java.util.Map;
17
import java.util.Set;
16
18
17
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Assert;
18
20
Lines 42-47 Link Here
42
	protected Map fWords= new HashMap();
44
	protected Map fWords= new HashMap();
43
	/** Buffer used for pattern detection */
45
	/** Buffer used for pattern detection */
44
	private StringBuffer fBuffer= new StringBuffer();
46
	private StringBuffer fBuffer= new StringBuffer();
47
	/** The boolean repsenting whether we should be case sensitive */
48
	private boolean fIgnoreCase= false;
45
49
46
	/**
50
	/**
47
	 * Creates a rule which, with the help of an word detector, will return the token
51
	 * Creates a rule which, with the help of an word detector, will return the token
Lines 78-83 Link Here
78
	}
82
	}
79
83
80
	/**
84
	/**
85
	 * Creates a rule which, with the help of a word detector, will return the token
86
	 * associated with the detected word. If no token has been associated, the
87
	 * specified default token will be returned.
88
	 *
89
	 * @param detector the word detector to be used by this rule, may not be <code>null</code>
90
	 * @param defaultToken the default token to be returned on success
91
	 *		if nothing else is specified, may not be <code>null</code>
92
	 * @param ignoreCase the case sensitivity associated with the rule
93
	 *
94
	 * @since 3.3
95
	 * @see #addWord(String, IToken)
96
	 */
97
	public WordRule(IWordDetector detector, IToken defaultToken, boolean ignoreCase) {
98
99
		Assert.isNotNull(detector);
100
		Assert.isNotNull(defaultToken);
101
102
		fDetector= detector;
103
		fDefaultToken= defaultToken;
104
		fIgnoreCase= ignoreCase;
105
	}
106
107
	/**
81
	 * Adds a word and the token to be returned if it is detected.
108
	 * Adds a word and the token to be returned if it is detected.
82
	 *
109
	 *
83
	 * @param word the word this rule will search for, may not be <code>null</code>
110
	 * @param word the word this rule will search for, may not be <code>null</code>
Lines 119-125 Link Here
119
				} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
146
				} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
120
				scanner.unread();
147
				scanner.unread();
121
148
122
				IToken token= (IToken) fWords.get(fBuffer.toString());
149
				String buffer = null;
150
151
				if(fIgnoreCase) {
152
					Set entries= fWords.keySet();
153
					for (Iterator i = entries.iterator(); i.hasNext(); ) {
154
						String s= (String) i.next();
155
						if(s.equalsIgnoreCase(fBuffer.toString())) {
156
							buffer= s;
157
						}
158
					}
159
				} else {
160
					buffer= fBuffer.toString();
161
				}
162
163
				IToken token= (IToken) fWords.get(buffer);
123
				if (token != null)
164
				if (token != null)
124
					return token;
165
					return token;
125
166
Lines 143-146 Link Here
143
		for (int i= fBuffer.length() - 1; i >= 0; i--)
184
		for (int i= fBuffer.length() - 1; i >= 0; i--)
144
			scanner.unread();
185
			scanner.unread();
145
	}
186
	}
187
146
}
188
}

Return to bug 144355