|
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 |
} |