KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > java > JavaTokenContext


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.editor.ext.java;
21
22 import java.util.HashMap JavaDoc;
23 import org.netbeans.editor.BaseTokenCategory;
24 import org.netbeans.editor.BaseTokenID;
25 import org.netbeans.editor.TokenID;
26 import org.netbeans.editor.BaseImageTokenID;
27 import org.netbeans.editor.TokenContext;
28 import org.netbeans.editor.TokenContextPath;
29 import org.netbeans.editor.Utilities;
30
31 /**
32 * Java token-context defines token-ids and token-categories
33 * used in Java language.
34 *
35 * @author Miloslav Metelka
36 * @version 1.00
37 */

38
39 public class JavaTokenContext extends TokenContext {
40
41     // Token category-ids
42
public static final int KEYWORDS_ID = 1;
43     public static final int OPERATORS_ID = KEYWORDS_ID + 1;
44     public static final int NUMERIC_LITERALS_ID = OPERATORS_ID + 1;
45     public static final int ERRORS_ID = NUMERIC_LITERALS_ID + 1;
46
47     // Numeric-ids for token-ids
48
public static final int WHITESPACE_ID = ERRORS_ID + 1;
49     public static final int IDENTIFIER_ID = WHITESPACE_ID + 1;
50     public static final int LINE_COMMENT_ID = IDENTIFIER_ID + 1;
51     public static final int BLOCK_COMMENT_ID = LINE_COMMENT_ID + 1;
52     public static final int CHAR_LITERAL_ID = BLOCK_COMMENT_ID + 1;
53     public static final int STRING_LITERAL_ID = CHAR_LITERAL_ID + 1;
54     public static final int INT_LITERAL_ID = STRING_LITERAL_ID + 1;
55     public static final int LONG_LITERAL_ID = INT_LITERAL_ID + 1;
56     public static final int HEX_LITERAL_ID = LONG_LITERAL_ID + 1;
57     public static final int OCTAL_LITERAL_ID = HEX_LITERAL_ID + 1;
58     public static final int FLOAT_LITERAL_ID = OCTAL_LITERAL_ID + 1;
59     public static final int DOUBLE_LITERAL_ID = FLOAT_LITERAL_ID + 1;
60
61     // Operator numeric-ids
62
public static final int EQ_ID = DOUBLE_LITERAL_ID + 1; // =
63
public static final int LT_ID = EQ_ID + 1; // <
64
public static final int GT_ID = LT_ID + 1; // >
65
public static final int LSHIFT_ID = GT_ID + 1; // <<
66
public static final int RSSHIFT_ID = LSHIFT_ID + 1; // >>
67
public static final int RUSHIFT_ID = RSSHIFT_ID + 1; // >>>
68
public static final int PLUS_ID = RUSHIFT_ID + 1; // +
69
public static final int MINUS_ID = PLUS_ID + 1; // -
70
public static final int MUL_ID = MINUS_ID + 1; // *
71
public static final int DIV_ID = MUL_ID + 1; // /
72
public static final int AND_ID = DIV_ID + 1; // &
73
public static final int OR_ID = AND_ID + 1; // |
74
public static final int XOR_ID = OR_ID + 1; // ^
75
public static final int MOD_ID = XOR_ID + 1; // %
76
public static final int NOT_ID = MOD_ID + 1; // !
77
public static final int NEG_ID = NOT_ID + 1; // ~
78
public static final int EQ_EQ_ID = NEG_ID + 1; // ==
79
public static final int LT_EQ_ID = EQ_EQ_ID + 1; // <=
80
public static final int GT_EQ_ID = LT_EQ_ID + 1; // >=
81
public static final int LSHIFT_EQ_ID = GT_EQ_ID + 1; // <<=
82
public static final int RSSHIFT_EQ_ID = LSHIFT_EQ_ID + 1; // >>=
83
public static final int RUSHIFT_EQ_ID = RSSHIFT_EQ_ID + 1; // >>>=
84
public static final int PLUS_EQ_ID = RUSHIFT_EQ_ID + 1; // +=
85
public static final int MINUS_EQ_ID = PLUS_EQ_ID + 1; // -=
86
public static final int MUL_EQ_ID = MINUS_EQ_ID + 1; // *=
87
public static final int DIV_EQ_ID = MUL_EQ_ID + 1; // /=
88
public static final int AND_EQ_ID = DIV_EQ_ID + 1; // &=
89
public static final int OR_EQ_ID = AND_EQ_ID + 1; // |=
90
public static final int XOR_EQ_ID = OR_EQ_ID + 1; // ^=
91
public static final int MOD_EQ_ID = XOR_EQ_ID + 1; // %=
92
public static final int NOT_EQ_ID = MOD_EQ_ID + 1; // !=
93
public static final int DOT_ID = NOT_EQ_ID + 1; // .
94
public static final int COMMA_ID = DOT_ID + 1; // ,
95
public static final int COLON_ID = COMMA_ID + 1; // :
96
public static final int SEMICOLON_ID = COLON_ID + 1; // ;
97
public static final int QUESTION_ID = SEMICOLON_ID + 1; // ?
98
public static final int LPAREN_ID = QUESTION_ID + 1; // (
99
public static final int RPAREN_ID = LPAREN_ID + 1; // )
100
public static final int LBRACKET_ID = RPAREN_ID + 1; // [
101
public static final int RBRACKET_ID = LBRACKET_ID + 1; // ]
102
public static final int LBRACE_ID = RBRACKET_ID + 1; // {
103
public static final int RBRACE_ID = LBRACE_ID + 1; // }
104
public static final int PLUS_PLUS_ID = RBRACE_ID + 1; // ++
105
public static final int MINUS_MINUS_ID = PLUS_PLUS_ID + 1; // --
106
public static final int AND_AND_ID = MINUS_MINUS_ID + 1; // &&
107
public static final int OR_OR_ID = AND_AND_ID + 1; // ||
108

109     // Data type keyword numeric-ids
110
public static final int BOOLEAN_ID = OR_OR_ID + 1;
111     public static final int BYTE_ID = BOOLEAN_ID + 1;
112     public static final int CHAR_ID = BYTE_ID + 1;
113     public static final int DOUBLE_ID = CHAR_ID + 1;
114     public static final int FLOAT_ID = DOUBLE_ID + 1;
115     public static final int INT_ID = FLOAT_ID + 1;
116     public static final int LONG_ID = INT_ID + 1;
117     public static final int SHORT_ID = LONG_ID + 1;
118
119     // Void type keyword numeric-id
120
public static final int VOID_ID = SHORT_ID + 1;
121
122     // Other keywords numeric-ids
123
public static final int ABSTRACT_ID = VOID_ID + 1;
124     public static final int ASSERT_ID = ABSTRACT_ID + 1;
125     public static final int BREAK_ID = ASSERT_ID + 1;
126     public static final int CASE_ID = BREAK_ID + 1;
127     public static final int CATCH_ID = CASE_ID + 1;
128     public static final int CLASS_ID = CATCH_ID + 1;
129     public static final int CONST_ID = CLASS_ID + 1;
130     public static final int CONTINUE_ID = CONST_ID + 1;
131     public static final int DEFAULT_ID = CONTINUE_ID + 1;
132     public static final int DO_ID = DEFAULT_ID + 1;
133     public static final int ELSE_ID = DO_ID + 1;
134     public static final int ENUM_ID = ELSE_ID + 1;
135     public static final int EXTENDS_ID = ENUM_ID+ 1;
136     public static final int FALSE_ID = EXTENDS_ID + 1;
137     public static final int FINAL_ID = FALSE_ID + 1;
138     public static final int FINALLY_ID = FINAL_ID + 1;
139     public static final int FOR_ID = FINALLY_ID + 1;
140     public static final int GOTO_ID = FOR_ID + 1;
141     public static final int IF_ID = GOTO_ID + 1;
142     public static final int IMPLEMENTS_ID = IF_ID + 1;
143     public static final int IMPORT_ID = IMPLEMENTS_ID + 1;
144     public static final int INSTANCEOF_ID = IMPORT_ID + 1;
145     public static final int INTERFACE_ID = INSTANCEOF_ID + 1;
146     public static final int NATIVE_ID = INTERFACE_ID + 1;
147     public static final int NEW_ID = NATIVE_ID + 1;
148     public static final int NULL_ID = NEW_ID + 1;
149     public static final int PACKAGE_ID = NULL_ID + 1;
150     public static final int PRIVATE_ID = PACKAGE_ID + 1;
151     public static final int PROTECTED_ID = PRIVATE_ID + 1;
152     public static final int PUBLIC_ID = PROTECTED_ID + 1;
153     public static final int RETURN_ID = PUBLIC_ID + 1;
154     public static final int STATIC_ID = RETURN_ID + 1;
155     public static final int STRICTFP_ID = STATIC_ID + 1;
156     public static final int SUPER_ID = STRICTFP_ID + 1;
157     public static final int SWITCH_ID = SUPER_ID + 1;
158     public static final int SYNCHRONIZED_ID = SWITCH_ID + 1;
159     public static final int THIS_ID = SYNCHRONIZED_ID + 1;
160     public static final int THROW_ID = THIS_ID + 1;
161     public static final int THROWS_ID = THROW_ID + 1;
162     public static final int TRANSIENT_ID = THROWS_ID + 1;
163     public static final int TRUE_ID = TRANSIENT_ID + 1;
164     public static final int TRY_ID = TRUE_ID + 1;
165     public static final int VOLATILE_ID = TRY_ID + 1;
166     public static final int WHILE_ID = VOLATILE_ID + 1;
167
168     // Incomplete tokens
169
public static final int INCOMPLETE_STRING_LITERAL_ID = WHILE_ID + 1;
170     public static final int INCOMPLETE_CHAR_LITERAL_ID = INCOMPLETE_STRING_LITERAL_ID + 1;
171     public static final int INCOMPLETE_HEX_LITERAL_ID = INCOMPLETE_CHAR_LITERAL_ID + 1;
172     public static final int INVALID_CHAR_ID = INCOMPLETE_HEX_LITERAL_ID + 1;
173     public static final int INVALID_OPERATOR_ID = INVALID_CHAR_ID + 1;
174     public static final int INVALID_OCTAL_LITERAL_ID = INVALID_OPERATOR_ID + 1;
175     public static final int INVALID_COMMENT_END_ID = INVALID_OCTAL_LITERAL_ID + 1;
176     
177     // JDK1.5 "@ident" annotation
178
// "@keyword" gets returned as two tokens "@" and "keyword"
179
public static final int ANNOTATION_ID = INVALID_COMMENT_END_ID + 1;
180
181     // JDK1.5 vararg's "..."
182
public static final int ELLIPSIS_ID = ANNOTATION_ID + 1;
183
184
185     // Token-categories
186
/** All the keywords belong to this category. */
187     public static final BaseTokenCategory KEYWORDS
188     = new BaseTokenCategory("keywords", KEYWORDS_ID); // NOI18N
189

190     /** All the operators belong to this category. */
191     public static final BaseTokenCategory OPERATORS
192     = new BaseTokenCategory("operators", OPERATORS_ID); // NOI18N
193

194     /** All the numeric literals belong to this category. */
195     public static final BaseTokenCategory NUMERIC_LITERALS
196     = new BaseTokenCategory("numeric-literals", NUMERIC_LITERALS_ID); // NOI18N
197

198     /** All the errorneous constructions and incomplete tokens
199      * belong to this category.
200      */

201     public static final BaseTokenCategory ERRORS
202     = new BaseTokenCategory("errors", ERRORS_ID); // NOI18N
203

204
205     // Token-ids
206
public static final BaseTokenID WHITESPACE
207     = new BaseTokenID("whitespace", WHITESPACE_ID); // NOI18N
208

209     public static final BaseTokenID IDENTIFIER
210     = new BaseTokenID("identifier", IDENTIFIER_ID); // NOI18N
211

212     /** Comment with the '//' prefix */
213     public static final BaseTokenID LINE_COMMENT
214     = new BaseTokenID("line-comment", LINE_COMMENT_ID); // NOI18N
215

216     /** Block comment */
217     public static final BaseTokenID BLOCK_COMMENT
218     = new BaseTokenID("block-comment", BLOCK_COMMENT_ID); // NOI18N
219

220     /** Character literal e.g. 'c' */
221     public static final BaseTokenID CHAR_LITERAL
222     = new BaseTokenID("char-literal", CHAR_LITERAL_ID); // NOI18N
223

224     /** Java string literal e.g. "hello" */
225     public static final BaseTokenID STRING_LITERAL
226     = new BaseTokenID("string-literal", STRING_LITERAL_ID); // NOI18N
227

228     /** Java integer literal e.g. 1234 */
229     public static final BaseTokenID INT_LITERAL
230     = new BaseTokenID("int-literal", INT_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
231

232     /** Java long literal e.g. 12L */
233     public static final BaseTokenID LONG_LITERAL
234     = new BaseTokenID("long-literal", LONG_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
235

236     /** Java hexadecimal literal e.g. 0x5a */
237     public static final BaseTokenID HEX_LITERAL
238     = new BaseTokenID("hex-literal", HEX_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
239

240     /** Java octal literal e.g. 0123 */
241     public static final BaseTokenID OCTAL_LITERAL
242     = new BaseTokenID("octal-literal", OCTAL_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
243

244     /** Java float literal e.g. 1.5e+20f */
245     public static final BaseTokenID FLOAT_LITERAL
246     = new BaseTokenID("float-literal", FLOAT_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
247

248     /** Java double literal e.g. 1.5e+20 */
249     public static final BaseTokenID DOUBLE_LITERAL
250     = new BaseTokenID("double-literal", DOUBLE_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
251

252     // Operators
253
public static final BaseImageTokenID EQ
254     = new BaseImageTokenID("eq", EQ_ID, OPERATORS, "="); // NOI18N
255

256     public static final BaseImageTokenID LT
257     = new BaseImageTokenID("lt", LT_ID, OPERATORS, "<"); // NOI18N
258

259     public static final BaseImageTokenID GT
260     = new BaseImageTokenID("gt", GT_ID, OPERATORS, ">"); // NOI18N
261

262     public static final BaseImageTokenID LSHIFT
263     = new BaseImageTokenID("lshift", LSHIFT_ID, OPERATORS, "<<"); // NOI18N
264

265     public static final BaseImageTokenID RSSHIFT
266     = new BaseImageTokenID("rsshift", RSSHIFT_ID, OPERATORS, ">>"); // NOI18N
267

268     public static final BaseImageTokenID RUSHIFT
269     = new BaseImageTokenID("rushift", RUSHIFT_ID, OPERATORS, ">>>"); // NOI18N
270

271     public static final BaseImageTokenID PLUS
272     = new BaseImageTokenID("plus", PLUS_ID, OPERATORS, "+"); // NOI18N
273

274     public static final BaseImageTokenID MINUS
275     = new BaseImageTokenID("minus", MINUS_ID, OPERATORS, "-"); // NOI18N
276

277     public static final BaseImageTokenID MUL
278     = new BaseImageTokenID("mul", MUL_ID, OPERATORS, "*"); // NOI18N
279

280     public static final BaseImageTokenID DIV
281     = new BaseImageTokenID("div", DIV_ID, OPERATORS, "/"); // NOI18N
282

283     public static final BaseImageTokenID AND
284     = new BaseImageTokenID("and", AND_ID, OPERATORS, "&"); // NOI18N
285

286     public static final BaseImageTokenID OR
287     = new BaseImageTokenID("or", OR_ID, OPERATORS, "|"); // NOI18N
288

289     public static final BaseImageTokenID XOR
290     = new BaseImageTokenID("xor", XOR_ID, OPERATORS, "^"); // NOI18N
291

292     public static final BaseImageTokenID MOD
293     = new BaseImageTokenID("mod", MOD_ID, OPERATORS, "%"); // NOI18N
294

295     public static final BaseImageTokenID NOT
296     = new BaseImageTokenID("not", NOT_ID, OPERATORS, "!"); // NOI18N
297

298     public static final BaseImageTokenID NEG
299     = new BaseImageTokenID("neg", NEG_ID, OPERATORS, "~"); // NOI18N
300

301
302     public static final BaseImageTokenID EQ_EQ
303     = new BaseImageTokenID("eq-eq", EQ_EQ_ID, OPERATORS, "=="); // NOI18N
304

305     public static final BaseImageTokenID LT_EQ
306     = new BaseImageTokenID("le", LT_EQ_ID, OPERATORS, "<="); // NOI18N
307

308     public static final BaseImageTokenID GT_EQ
309     = new BaseImageTokenID("ge", GT_EQ_ID, OPERATORS, ">="); // NOI18N
310

311     public static final BaseImageTokenID LSHIFT_EQ
312     = new BaseImageTokenID("lshift-eq", LSHIFT_EQ_ID, OPERATORS, "<<="); // NOI18N
313

314     public static final BaseImageTokenID RSSHIFT_EQ
315     = new BaseImageTokenID("rsshift-eq", RSSHIFT_EQ_ID, OPERATORS, ">>="); // NOI18N
316

317     public static final BaseImageTokenID RUSHIFT_EQ
318     = new BaseImageTokenID("rushift-eq", RUSHIFT_EQ_ID, OPERATORS, ">>>="); // NOI18N
319

320     public static final BaseImageTokenID PLUS_EQ
321     = new BaseImageTokenID("plus-eq", PLUS_EQ_ID, OPERATORS, "+="); // NOI18N
322

323     public static final BaseImageTokenID MINUS_EQ
324     = new BaseImageTokenID("minus-eq", MINUS_EQ_ID, OPERATORS, "-="); // NOI18N
325

326     public static final BaseImageTokenID MUL_EQ
327     = new BaseImageTokenID("mul-eq", MUL_EQ_ID, OPERATORS, "*="); // NOI18N
328

329     public static final BaseImageTokenID DIV_EQ
330     = new BaseImageTokenID("div-eq", DIV_EQ_ID, OPERATORS, "/="); // NOI18N
331

332     public static final BaseImageTokenID AND_EQ
333     = new BaseImageTokenID("and-eq", AND_EQ_ID, OPERATORS, "&="); // NOI18N
334

335     public static final BaseImageTokenID OR_EQ
336     = new BaseImageTokenID("or-eq", OR_EQ_ID, OPERATORS, "|="); // NOI18N
337

338     public static final BaseImageTokenID XOR_EQ
339     = new BaseImageTokenID("xor-eq", XOR_EQ_ID, OPERATORS, "^="); // NOI18N
340

341     public static final BaseImageTokenID MOD_EQ
342     = new BaseImageTokenID("mod-eq", MOD_EQ_ID, OPERATORS, "%="); // NOI18N
343

344     public static final BaseImageTokenID NOT_EQ
345     = new BaseImageTokenID("not-eq", NOT_EQ_ID, OPERATORS, "!="); // NOI18N
346

347
348     public static final BaseImageTokenID DOT
349     = new BaseImageTokenID("dot", DOT_ID, OPERATORS, "."); // NOI18N
350

351     public static final BaseImageTokenID COMMA
352     = new BaseImageTokenID("comma", COMMA_ID, OPERATORS, ","); // NOI18N
353

354     public static final BaseImageTokenID COLON
355     = new BaseImageTokenID("colon", COLON_ID, OPERATORS, ":"); // NOI18N
356

357     public static final BaseImageTokenID SEMICOLON
358     = new BaseImageTokenID("semicolon", SEMICOLON_ID, OPERATORS, ";"); // NOI18N
359

360     public static final BaseImageTokenID QUESTION
361     = new BaseImageTokenID("question", QUESTION_ID, OPERATORS, "?"); // NOI18N
362

363     public static final BaseImageTokenID LPAREN
364     = new BaseImageTokenID("lparen", LPAREN_ID, OPERATORS, "("); // NOI18N
365

366     public static final BaseImageTokenID RPAREN
367     = new BaseImageTokenID("rparen", RPAREN_ID, OPERATORS, ")"); // NOI18N
368

369     public static final BaseImageTokenID LBRACKET
370     = new BaseImageTokenID("lbracket", LBRACKET_ID, OPERATORS, "["); // NOI18N
371

372     public static final BaseImageTokenID RBRACKET
373     = new BaseImageTokenID("rbracket", RBRACKET_ID, OPERATORS, "]"); // NOI18N
374

375     public static final BaseImageTokenID LBRACE
376     = new BaseImageTokenID("lbrace", LBRACE_ID, OPERATORS, "{"); // NOI18N
377

378     public static final BaseImageTokenID RBRACE
379     = new BaseImageTokenID("rbrace", RBRACE_ID, OPERATORS, "}"); // NOI18N
380

381     public static final BaseImageTokenID PLUS_PLUS
382     = new BaseImageTokenID("plus-plus", PLUS_PLUS_ID, OPERATORS, "++"); // NOI18N
383

384     public static final BaseImageTokenID MINUS_MINUS
385     = new BaseImageTokenID("minus-minus", MINUS_MINUS_ID, OPERATORS, "--"); // NOI18N
386

387     public static final BaseImageTokenID AND_AND
388     = new BaseImageTokenID("and-and", AND_AND_ID, OPERATORS, "&&"); // NOI18N
389

390     public static final BaseImageTokenID OR_OR
391     = new BaseImageTokenID("or-or", OR_OR_ID, OPERATORS, "||"); // NOI18N
392

393
394     // Data types
395
public static final BaseImageTokenID BOOLEAN
396     = new BaseImageTokenID("boolean", BOOLEAN_ID, KEYWORDS); // NOI18N
397

398     public static final BaseImageTokenID BYTE
399     = new BaseImageTokenID("byte", BYTE_ID, KEYWORDS); // NOI18N
400

401     public static final BaseImageTokenID CHAR
402     = new BaseImageTokenID("char", CHAR_ID, KEYWORDS); // NOI18N
403

404     public static final BaseImageTokenID DOUBLE
405     = new BaseImageTokenID("double", DOUBLE_ID, KEYWORDS); // NOI18N
406

407     public static final BaseImageTokenID FLOAT
408     = new BaseImageTokenID("float", FLOAT_ID, KEYWORDS); // NOI18N
409

410     public static final BaseImageTokenID INT
411     = new BaseImageTokenID("int", INT_ID, KEYWORDS); // NOI18N
412

413     public static final BaseImageTokenID LONG
414     = new BaseImageTokenID("long", LONG_ID, KEYWORDS); // NOI18N
415

416     public static final BaseImageTokenID SHORT
417     = new BaseImageTokenID("short", SHORT_ID, KEYWORDS); // NOI18N
418

419     // Void type
420
public static final BaseImageTokenID VOID
421     = new BaseImageTokenID("void", VOID_ID, KEYWORDS); // NOI18N
422

423     // Rest of the keywords
424
public static final BaseImageTokenID ABSTRACT
425     = new BaseImageTokenID("abstract", ABSTRACT_ID, KEYWORDS); // NOI18N
426

427     public static final BaseImageTokenID ASSERT
428     = new BaseImageTokenID("assert", ASSERT_ID, KEYWORDS); // NOI18N
429

430     public static final BaseImageTokenID BREAK
431     = new BaseImageTokenID("break", BREAK_ID, KEYWORDS); // NOI18N
432

433     public static final BaseImageTokenID CASE
434     = new BaseImageTokenID("case", CASE_ID, KEYWORDS); // NOI18N
435

436     public static final BaseImageTokenID CATCH
437     = new BaseImageTokenID("catch", CATCH_ID, KEYWORDS); // NOI18N
438

439     public static final BaseImageTokenID CLASS
440     = new BaseImageTokenID("class", CLASS_ID, KEYWORDS); // NOI18N
441

442     public static final BaseImageTokenID CONST
443     = new BaseImageTokenID("const", CONST_ID, KEYWORDS); // NOI18N
444

445     public static final BaseImageTokenID CONTINUE
446     = new BaseImageTokenID("continue", CONTINUE_ID, KEYWORDS); // NOI18N
447

448     public static final BaseImageTokenID DEFAULT
449     = new BaseImageTokenID("default", DEFAULT_ID, KEYWORDS); // NOI18N
450

451     public static final BaseImageTokenID DO
452     = new BaseImageTokenID("do", DO_ID, KEYWORDS); // NOI18N
453

454     public static final BaseImageTokenID ELSE
455     = new BaseImageTokenID("else", ELSE_ID, KEYWORDS); // NOI18N
456

457     public static final BaseImageTokenID ENUM
458     = new BaseImageTokenID("enum", ENUM_ID, KEYWORDS); // NOI18N
459

460     public static final BaseImageTokenID EXTENDS
461     = new BaseImageTokenID("extends", EXTENDS_ID, KEYWORDS); // NOI18N
462

463     public static final BaseImageTokenID FALSE
464     = new BaseImageTokenID("false", FALSE_ID, KEYWORDS); // NOI18N
465

466     public static final BaseImageTokenID FINAL
467     = new BaseImageTokenID("final", FINAL_ID, KEYWORDS); // NOI18N
468

469     public static final BaseImageTokenID FINALLY
470     = new BaseImageTokenID("finally", FINALLY_ID, KEYWORDS); // NOI18N
471

472     public static final BaseImageTokenID FOR
473     = new BaseImageTokenID("for", FOR_ID, KEYWORDS); // NOI18N
474

475     public static final BaseImageTokenID GOTO
476     = new BaseImageTokenID("goto", GOTO_ID, KEYWORDS); // NOI18N
477

478     public static final BaseImageTokenID IF
479     = new BaseImageTokenID("if", IF_ID, KEYWORDS); // NOI18N
480

481     public static final BaseImageTokenID IMPLEMENTS
482     = new BaseImageTokenID("implements", IMPLEMENTS_ID, KEYWORDS); // NOI18N
483

484     public static final BaseImageTokenID IMPORT
485     = new BaseImageTokenID("import", IMPORT_ID, KEYWORDS); // NOI18N
486

487     public static final BaseImageTokenID INSTANCEOF
488     = new BaseImageTokenID("instanceof", INSTANCEOF_ID, KEYWORDS); // NOI18N
489

490     public static final BaseImageTokenID INTERFACE
491     = new BaseImageTokenID("interface", INTERFACE_ID, KEYWORDS); // NOI18N
492

493     public static final BaseImageTokenID NATIVE
494     = new BaseImageTokenID("native", NATIVE_ID, KEYWORDS); // NOI18N
495

496     public static final BaseImageTokenID NEW
497     = new BaseImageTokenID("new", NEW_ID, KEYWORDS); // NOI18N
498

499     public static final BaseImageTokenID NULL
500     = new BaseImageTokenID("null", NULL_ID, KEYWORDS); // NOI18N
501

502     public static final BaseImageTokenID PACKAGE
503     = new BaseImageTokenID("package", PACKAGE_ID, KEYWORDS); // NOI18N
504

505     public static final BaseImageTokenID PRIVATE
506     = new BaseImageTokenID("private", PRIVATE_ID, KEYWORDS); // NOI18N
507

508     public static final BaseImageTokenID PROTECTED
509     = new BaseImageTokenID("protected", PROTECTED_ID, KEYWORDS); // NOI18N
510

511     public static final BaseImageTokenID PUBLIC
512     = new BaseImageTokenID("public", PUBLIC_ID, KEYWORDS); // NOI18N
513

514     public static final BaseImageTokenID RETURN
515     = new BaseImageTokenID("return", RETURN_ID, KEYWORDS); // NOI18N
516

517     public static final BaseImageTokenID STATIC
518     = new BaseImageTokenID("static", STATIC_ID, KEYWORDS); // NOI18N
519

520     public static final BaseImageTokenID STRICTFP
521     = new BaseImageTokenID("strictfp", STRICTFP_ID, KEYWORDS); // NOI18N
522

523     public static final BaseImageTokenID SUPER
524     = new BaseImageTokenID("super", SUPER_ID, KEYWORDS); // NOI18N
525

526     public static final BaseImageTokenID SWITCH
527     = new BaseImageTokenID("switch", SWITCH_ID, KEYWORDS); // NOI18N
528

529     public static final BaseImageTokenID SYNCHRONIZED
530     = new BaseImageTokenID("synchronized", SYNCHRONIZED_ID, KEYWORDS); // NOI18N
531

532     public static final BaseImageTokenID THIS
533     = new BaseImageTokenID("this", THIS_ID, KEYWORDS); // NOI18N
534

535     public static final BaseImageTokenID THROW
536     = new BaseImageTokenID("throw", THROW_ID, KEYWORDS); // NOI18N
537

538     public static final BaseImageTokenID THROWS
539     = new BaseImageTokenID("throws", THROWS_ID, KEYWORDS); // NOI18N
540

541     public static final BaseImageTokenID TRANSIENT
542     = new BaseImageTokenID("transient", TRANSIENT_ID, KEYWORDS); // NOI18N
543

544     public static final BaseImageTokenID TRUE
545     = new BaseImageTokenID("true", TRUE_ID, KEYWORDS); // NOI18N
546

547     public static final BaseImageTokenID TRY
548     = new BaseImageTokenID("try", TRY_ID, KEYWORDS); // NOI18N
549

550     public static final BaseImageTokenID VOLATILE
551     = new BaseImageTokenID("volatile", VOLATILE_ID, KEYWORDS); // NOI18N
552

553     public static final BaseImageTokenID WHILE
554     = new BaseImageTokenID("while", WHILE_ID, KEYWORDS); // NOI18N
555

556     // Incomplete and error token-ids
557
public static final BaseTokenID INCOMPLETE_STRING_LITERAL
558     = new BaseTokenID("incomplete-string-literal", INCOMPLETE_STRING_LITERAL_ID, ERRORS); // NOI18N
559

560     public static final BaseTokenID INCOMPLETE_CHAR_LITERAL
561     = new BaseTokenID("incomplete-char-literal", INCOMPLETE_CHAR_LITERAL_ID, ERRORS); // NOI18N
562

563     public static final BaseTokenID INCOMPLETE_HEX_LITERAL
564     = new BaseTokenID("incomplete-hex-literal", INCOMPLETE_HEX_LITERAL_ID, ERRORS); // NOI18N
565

566     public static final BaseTokenID INVALID_CHAR
567     = new BaseTokenID("invalid-char", INVALID_CHAR_ID, ERRORS); // NOI18N
568

569     public static final BaseTokenID INVALID_OPERATOR
570     = new BaseTokenID("invalid-operator", INVALID_OPERATOR_ID, ERRORS); // NOI18N
571

572     public static final BaseTokenID INVALID_OCTAL_LITERAL
573     = new BaseTokenID("invalid-octal-literal", INVALID_OCTAL_LITERAL_ID, ERRORS); // NOI18N
574

575     public static final BaseTokenID INVALID_COMMENT_END
576     = new BaseTokenID("invalid-comment-end", INVALID_COMMENT_END_ID, ERRORS); // NOI18N
577

578     
579     // JDK1.5 "@ident" annotation
580
// "@keyword" gets returned as two tokens "@" and "keyword"
581
public static final BaseTokenID ANNOTATION
582     = new BaseTokenID("annotation", ANNOTATION_ID); // NOI18N
583

584     // JDK1.5 vararg's "..."
585
public static final BaseImageTokenID ELLIPSIS
586     = new BaseImageTokenID("ellipsis", ELLIPSIS_ID, OPERATORS, "..."); // NOI18N
587

588     // Context instance declaration
589
public static final JavaTokenContext context = new JavaTokenContext();
590
591     public static final TokenContextPath contextPath = context.getContextPath();
592
593     private static final HashMap JavaDoc str2kwd = new HashMap JavaDoc();
594
595     static {
596         BaseImageTokenID[] kwds = new BaseImageTokenID[] {
597             ABSTRACT, ASSERT, BREAK, CASE, CATCH, CLASS, CONST, CONTINUE, DEFAULT, DO,
598             ELSE, ENUM, EXTENDS, FALSE, FINAL, FINALLY, FOR, GOTO, IF, IMPLEMENTS,
599             IMPORT, INSTANCEOF, INTERFACE, NATIVE, NEW, NULL, PACKAGE, PRIVATE,
600             PROTECTED, PUBLIC, RETURN, STATIC, STRICTFP, SUPER, SWITCH, SYNCHRONIZED, THIS,
601             THROW, THROWS, TRANSIENT, TRUE, TRY, VOLATILE, WHILE,
602             BOOLEAN, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORT, VOID
603         };
604
605         for (int i = kwds.length - 1; i >= 0; i--) {
606             str2kwd.put(kwds[i].getImage(), kwds[i]);
607         }
608     }
609
610     /** Checks whether the given token-id is a type-keyword.
611     * @return true when the keyword is a data type.
612     */

613     public static boolean isType(TokenID keywordTokenID) {
614         int numID = (keywordTokenID != null) ? keywordTokenID.getNumericID() : -1;
615         return (numID >= BOOLEAN_ID && numID < VOID_ID);
616     }
617
618     /** Checks whether the given string is a type-keyword. */
619     public static boolean isType(String JavaDoc s) {
620         return isType((TokenID)str2kwd.get(s));
621     }
622
623     /** Checks whether the given token-id is a data-type-keyword or void-keyword.
624     * @return true when the keyword is a data-type-keyword or void-keyword.
625     */

626     public static boolean isTypeOrVoid(TokenID keywordTokenID) {
627         int numID = (keywordTokenID != null) ? keywordTokenID.getNumericID() : -1;
628         return (numID >= BOOLEAN_ID && numID <= VOID_ID);
629     }
630
631     /** Checks whether the given string is a data-type-keyword or void-keyword. */
632     public static boolean isTypeOrVoid(String JavaDoc s) {
633         return isTypeOrVoid((TokenID)str2kwd.get(s));
634     }
635
636     /** Get the keyword token-id from string */
637     public static TokenID getKeyword(String JavaDoc s) {
638         return (TokenID)str2kwd.get(s);
639     }
640
641     private JavaTokenContext() {
642         super("java-"); // NOI18N
643

644         try {
645             addDeclaredTokenIDs();
646         } catch (Exception JavaDoc e) {
647             Utilities.annotateLoggable(e);
648         }
649
650     }
651
652 }
653
Popular Tags