Lines 20-25
Link Here
|
20 |
package org.netbeans.spi.lexer; |
20 |
package org.netbeans.spi.lexer; |
21 |
|
21 |
|
22 |
import java.util.Set; |
22 |
import java.util.Set; |
|
|
23 |
import org.netbeans.api.lexer.PartType; |
23 |
import org.netbeans.api.lexer.Token; |
24 |
import org.netbeans.api.lexer.Token; |
24 |
import org.netbeans.api.lexer.TokenId; |
25 |
import org.netbeans.api.lexer.TokenId; |
25 |
import org.netbeans.lib.editor.util.CharSequenceUtilities; |
26 |
import org.netbeans.lib.editor.util.CharSequenceUtilities; |
Lines 28-36
Link Here
|
28 |
import org.netbeans.lib.lexer.TokenIdImpl; |
29 |
import org.netbeans.lib.lexer.TokenIdImpl; |
29 |
import org.netbeans.lib.lexer.token.CustomTextToken; |
30 |
import org.netbeans.lib.lexer.token.CustomTextToken; |
30 |
import org.netbeans.lib.lexer.token.DefaultToken; |
31 |
import org.netbeans.lib.lexer.token.DefaultToken; |
|
|
32 |
import org.netbeans.lib.lexer.token.ComplexToken; |
31 |
import org.netbeans.lib.lexer.token.PreprocessedTextToken; |
33 |
import org.netbeans.lib.lexer.token.PreprocessedTextToken; |
32 |
import org.netbeans.lib.lexer.token.PropertyCustomTextToken; |
34 |
import org.netbeans.lib.lexer.token.ComplexToken; |
33 |
import org.netbeans.lib.lexer.token.PropertyPreprocessedTextToken; |
|
|
34 |
import org.netbeans.lib.lexer.token.PropertyToken; |
35 |
import org.netbeans.lib.lexer.token.PropertyToken; |
35 |
import org.netbeans.lib.lexer.token.TextToken; |
36 |
import org.netbeans.lib.lexer.token.TextToken; |
36 |
|
37 |
|
Lines 104-109
Link Here
|
104 |
} |
105 |
} |
105 |
|
106 |
|
106 |
/** |
107 |
/** |
|
|
108 |
* Create regular token instance with an explicit length and part type. |
109 |
* |
110 |
* @param id non-null token id recognized by the lexer. |
111 |
* @param length >=0 length of the token to be created. The length must not |
112 |
* exceed the number of characters read from the lexer input. |
113 |
* @param partType whether this token is complete token or a part of a complete token. |
114 |
* @return non-null regular token instance. |
115 |
* <br/> |
116 |
* If there were any characters preprocessed by {@link CharPreprocessor} |
117 |
* then a special token instance will be created for it. |
118 |
* <br/> |
119 |
* {@link #SKIP_TOKEN} will be returned |
120 |
* if tokens for the given token id should be skipped |
121 |
* because of token id filter. |
122 |
*/ |
123 |
public Token<T> createToken(T id, int length, PartType partType) { |
124 |
checkPartTypeNonNull(partType); |
125 |
if (partType == PartType.COMPLETE) |
126 |
return createToken(id, length); |
127 |
|
128 |
if (isSkipToken(id)) { |
129 |
operation.tokenRecognized(length, true); |
130 |
return skipToken(); |
131 |
} else { // Do not skip the token |
132 |
if (operation.tokenRecognized(length, false)) { // Create preprocessed token |
133 |
return new ComplexToken<T>(id, operation.tokenLength(), null, null, partType); |
134 |
} else { |
135 |
return new PropertyToken<T>(id, operation.tokenLength(), null, partType); |
136 |
} |
137 |
} |
138 |
} |
139 |
|
140 |
/** |
107 |
* Get flyweight token for the given arguments. |
141 |
* Get flyweight token for the given arguments. |
108 |
* <br/> |
142 |
* <br/> |
109 |
* <b>Note:</b> The returned token will not be flyweight under certain |
143 |
* <b>Note:</b> The returned token will not be flyweight under certain |
Lines 165-173
Link Here
|
165 |
* @param length >=0 length of the token to be created. The length must not |
199 |
* @param length >=0 length of the token to be created. The length must not |
166 |
* exceed the number of characters read from the lexer input. |
200 |
* exceed the number of characters read from the lexer input. |
167 |
* @param propertyProvider non-null token property provider. |
201 |
* @param propertyProvider non-null token property provider. |
168 |
* @param tokenStoreValue explicit value for property stored in the token itself |
202 |
* @param partType whether this token is complete or just a part of complete token. |
169 |
* or null if there is no explicit value (value will be computed lazily when asked). |
|
|
170 |
* <br/> |
171 |
* See {@link TokenPropertyProvider} for examples how this parameter may be used. |
203 |
* See {@link TokenPropertyProvider} for examples how this parameter may be used. |
172 |
* @return non-null property token instance. |
204 |
* @return non-null property token instance. |
173 |
* <br/> |
205 |
* <br/> |
Lines 179-195
Link Here
|
179 |
* because of token id filter. |
211 |
* because of token id filter. |
180 |
*/ |
212 |
*/ |
181 |
public Token<T> createPropertyToken(T id, int length, |
213 |
public Token<T> createPropertyToken(T id, int length, |
182 |
TokenPropertyProvider propertyProvider, Object tokenStoreValue) { |
214 |
TokenPropertyProvider propertyProvider, PartType partType) { |
|
|
215 |
checkPartTypeNonNull(partType); |
183 |
if (isSkipToken(id)) { |
216 |
if (isSkipToken(id)) { |
184 |
operation.tokenRecognized(length, true); |
217 |
operation.tokenRecognized(length, true); |
185 |
return skipToken(); |
218 |
return skipToken(); |
186 |
} else { // Do not skip the token |
219 |
} else { // Do not skip the token |
187 |
if (operation.tokenRecognized(length, false)) { // Create preprocessed token |
220 |
if (operation.tokenRecognized(length, false)) { // Create preprocessed token |
188 |
return new PropertyPreprocessedTextToken<T>(id, operation.tokenLength(), |
221 |
return new ComplexToken<T>(id, operation.tokenLength(), |
189 |
propertyProvider, tokenStoreValue); |
222 |
propertyProvider, null, partType); |
190 |
} else { |
223 |
} else { |
191 |
return new PropertyToken<T>(id, operation.tokenLength(), |
224 |
return new PropertyToken<T>(id, operation.tokenLength(), |
192 |
propertyProvider, tokenStoreValue); |
225 |
propertyProvider, partType); |
193 |
} |
226 |
} |
194 |
} |
227 |
} |
195 |
} |
228 |
} |
Lines 198-213
Link Here
|
198 |
* Create token with a custom text that possibly differs from the text |
231 |
* Create token with a custom text that possibly differs from the text |
199 |
* represented by the token in the input text. |
232 |
* represented by the token in the input text. |
200 |
*/ |
233 |
*/ |
201 |
public Token<T> createCustomTextToken(T id, CharSequence text, int length) { |
234 |
public Token<T> createCustomTextToken(T id, CharSequence text, int length, PartType partType) { |
|
|
235 |
checkPartTypeNonNull(partType); |
202 |
if (isSkipToken(id)) { |
236 |
if (isSkipToken(id)) { |
203 |
operation.tokenRecognized(length, true); |
237 |
operation.tokenRecognized(length, true); |
204 |
return skipToken(); |
238 |
return skipToken(); |
205 |
} else { // Do not skip the token |
239 |
} else { // Do not skip the token |
206 |
if (operation.tokenRecognized(length, false)) { // Create preprocessed token |
240 |
if (operation.tokenRecognized(length, false)) { // Create preprocessed token |
207 |
return new PropertyCustomTextToken<T>(id, |
241 |
return new ComplexToken<T>(id, operation.tokenLength(), null, text, partType); |
208 |
operation.tokenLength(), text, null, null); |
|
|
209 |
} else { |
242 |
} else { |
210 |
return new CustomTextToken<T>(id, operation.tokenLength(), text); |
243 |
return new CustomTextToken<T>(id, operation.tokenLength(), text, partType); |
211 |
} |
244 |
} |
212 |
} |
245 |
} |
213 |
} |
246 |
} |
Lines 220-225
Link Here
|
220 |
@SuppressWarnings("unchecked") // NOI18N |
253 |
@SuppressWarnings("unchecked") // NOI18N |
221 |
private Token<T> skipToken() { |
254 |
private Token<T> skipToken() { |
222 |
return SKIP_TOKEN; |
255 |
return SKIP_TOKEN; |
|
|
256 |
} |
257 |
|
258 |
private void checkPartTypeNonNull(PartType partType) { |
259 |
if (partType == null) |
260 |
throw new IllegalArgumentException("partType must be non-null"); |
223 |
} |
261 |
} |
224 |
|
262 |
|
225 |
} |
263 |
} |