src/share/classes/com/sun/tools/javac/parser/Tokens.java

changeset 1503
2d2b2be57c78
parent 1352
d4b3cb1ece84
child 2047
5f915a0c9615
equal deleted inserted replaced
1502:916143318f10 1503:2d2b2be57c78
31 import com.sun.tools.javac.api.Messages; 31 import com.sun.tools.javac.api.Messages;
32 import com.sun.tools.javac.parser.Tokens.Token.Tag; 32 import com.sun.tools.javac.parser.Tokens.Token.Tag;
33 import com.sun.tools.javac.util.List; 33 import com.sun.tools.javac.util.List;
34 import com.sun.tools.javac.util.Name; 34 import com.sun.tools.javac.util.Name;
35 import com.sun.tools.javac.util.Context; 35 import com.sun.tools.javac.util.Context;
36 import com.sun.tools.javac.util.Filter;
36 import com.sun.tools.javac.util.ListBuffer; 37 import com.sun.tools.javac.util.ListBuffer;
37 import com.sun.tools.javac.util.Names; 38 import com.sun.tools.javac.util.Names;
38 39
39 /** A class that defines codes/utilities for Java source tokens 40 /** A class that defines codes/utilities for Java source tokens
40 * returned from lexical analysis. 41 * returned from lexical analysis.
72 } 73 }
73 74
74 protected Tokens(Context context) { 75 protected Tokens(Context context) {
75 context.put(tokensKey, this); 76 context.put(tokensKey, this);
76 names = Names.instance(context); 77 names = Names.instance(context);
77
78 for (TokenKind t : TokenKind.values()) { 78 for (TokenKind t : TokenKind.values()) {
79 if (t.name != null) 79 if (t.name != null)
80 enterKeyword(t.name, t); 80 enterKeyword(t.name, t);
81 else 81 else
82 tokenName[t.ordinal()] = null; 82 tokenName[t.ordinal()] = null;
111 111
112 /** 112 /**
113 * This enum defines all tokens used by the javac scanner. A token is 113 * This enum defines all tokens used by the javac scanner. A token is
114 * optionally associated with a name. 114 * optionally associated with a name.
115 */ 115 */
116 public enum TokenKind implements Formattable { 116 public enum TokenKind implements Formattable, Filter<TokenKind> {
117 EOF(), 117 EOF(),
118 ERROR(), 118 ERROR(),
119 IDENTIFIER(Tag.NAMED), 119 IDENTIFIER(Tag.NAMED),
120 ABSTRACT("abstract"), 120 ABSTRACT("abstract"),
121 ASSERT("assert", Tag.NAMED), 121 ASSERT("assert", Tag.NAMED),
174 CHARLITERAL(Tag.NUMERIC), 174 CHARLITERAL(Tag.NUMERIC),
175 STRINGLITERAL(Tag.STRING), 175 STRINGLITERAL(Tag.STRING),
176 TRUE("true", Tag.NAMED), 176 TRUE("true", Tag.NAMED),
177 FALSE("false", Tag.NAMED), 177 FALSE("false", Tag.NAMED),
178 NULL("null", Tag.NAMED), 178 NULL("null", Tag.NAMED),
179 UNDERSCORE("_", Tag.NAMED),
179 ARROW("->"), 180 ARROW("->"),
180 COLCOL("::"), 181 COLCOL("::"),
181 LPAREN("("), 182 LPAREN("("),
182 RPAREN(")"), 183 RPAREN(")"),
183 LBRACE("{"), 184 LBRACE("{"),
281 } 282 }
282 283
283 public String toString(Locale locale, Messages messages) { 284 public String toString(Locale locale, Messages messages) {
284 return name != null ? toString() : messages.getLocalizedString(locale, "compiler.misc." + toString()); 285 return name != null ? toString() : messages.getLocalizedString(locale, "compiler.misc." + toString());
285 } 286 }
287
288 @Override
289 public boolean accepts(TokenKind that) {
290 return this == that;
291 }
286 } 292 }
287 293
288 public interface Comment { 294 public interface Comment {
289 295
290 enum CommentStyle { 296 enum CommentStyle {

mercurial