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

Fri, 04 Nov 2011 12:36:40 +0000

author
mcimadamore
date
Fri, 04 Nov 2011 12:36:40 +0000
changeset 1125
56830d5cb5bb
parent 1113
d346ab55031b
child 1144
9448fe783fd2
permissions
-rw-r--r--

7104201: Refactor DocCommentScanner
Summary: Add new Comment helper class to parse contents of comments in source code
Reviewed-by: jjg

mcimadamore@1113 1 /*
mcimadamore@1113 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
mcimadamore@1113 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mcimadamore@1113 4 *
mcimadamore@1113 5 * This code is free software; you can redistribute it and/or modify it
mcimadamore@1113 6 * under the terms of the GNU General Public License version 2 only, as
mcimadamore@1113 7 * published by the Free Software Foundation. Oracle designates this
mcimadamore@1113 8 * particular file as subject to the "Classpath" exception as provided
mcimadamore@1113 9 * by Oracle in the LICENSE file that accompanied this code.
mcimadamore@1113 10 *
mcimadamore@1113 11 * This code is distributed in the hope that it will be useful, but WITHOUT
mcimadamore@1113 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mcimadamore@1113 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mcimadamore@1113 14 * version 2 for more details (a copy is included in the LICENSE file that
mcimadamore@1113 15 * accompanied this code).
mcimadamore@1113 16 *
mcimadamore@1113 17 * You should have received a copy of the GNU General Public License version
mcimadamore@1113 18 * 2 along with this work; if not, write to the Free Software Foundation,
mcimadamore@1113 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mcimadamore@1113 20 *
mcimadamore@1113 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mcimadamore@1113 22 * or visit www.oracle.com if you need additional information or have any
mcimadamore@1113 23 * questions.
mcimadamore@1113 24 */
mcimadamore@1113 25
mcimadamore@1113 26 package com.sun.tools.javac.parser;
mcimadamore@1113 27
mcimadamore@1113 28 import java.util.Locale;
mcimadamore@1113 29
mcimadamore@1113 30 import com.sun.tools.javac.api.Formattable;
mcimadamore@1113 31 import com.sun.tools.javac.api.Messages;
mcimadamore@1113 32 import com.sun.tools.javac.parser.Tokens.Token.Tag;
mcimadamore@1125 33 import com.sun.tools.javac.util.List;
mcimadamore@1113 34 import com.sun.tools.javac.util.Name;
mcimadamore@1113 35 import com.sun.tools.javac.util.Context;
mcimadamore@1125 36 import com.sun.tools.javac.util.ListBuffer;
mcimadamore@1113 37 import com.sun.tools.javac.util.Names;
mcimadamore@1113 38
mcimadamore@1113 39 /** A class that defines codes/utilities for Java source tokens
mcimadamore@1113 40 * returned from lexical analysis.
mcimadamore@1113 41 *
mcimadamore@1113 42 * <p><b>This is NOT part of any supported API.
mcimadamore@1113 43 * If you write code that depends on this, you do so at your own risk.
mcimadamore@1113 44 * This code and its internal interfaces are subject to change or
mcimadamore@1113 45 * deletion without notice.</b>
mcimadamore@1113 46 */
mcimadamore@1113 47 public class Tokens {
mcimadamore@1113 48
mcimadamore@1113 49 private final Names names;
mcimadamore@1113 50
mcimadamore@1113 51 /**
mcimadamore@1113 52 * Keyword array. Maps name indices to Token.
mcimadamore@1113 53 */
mcimadamore@1113 54 private final TokenKind[] key;
mcimadamore@1113 55
mcimadamore@1113 56 /** The number of the last entered keyword.
mcimadamore@1113 57 */
mcimadamore@1113 58 private int maxKey = 0;
mcimadamore@1113 59
mcimadamore@1113 60 /** The names of all tokens.
mcimadamore@1113 61 */
mcimadamore@1113 62 private Name[] tokenName = new Name[TokenKind.values().length];
mcimadamore@1113 63
mcimadamore@1113 64 public static final Context.Key<Tokens> tokensKey =
mcimadamore@1113 65 new Context.Key<Tokens>();
mcimadamore@1113 66
mcimadamore@1113 67 public static Tokens instance(Context context) {
mcimadamore@1113 68 Tokens instance = context.get(tokensKey);
mcimadamore@1113 69 if (instance == null)
mcimadamore@1113 70 instance = new Tokens(context);
mcimadamore@1113 71 return instance;
mcimadamore@1113 72 }
mcimadamore@1113 73
mcimadamore@1113 74 protected Tokens(Context context) {
mcimadamore@1113 75 context.put(tokensKey, this);
mcimadamore@1113 76 names = Names.instance(context);
mcimadamore@1113 77
mcimadamore@1113 78 for (TokenKind t : TokenKind.values()) {
mcimadamore@1113 79 if (t.name != null)
mcimadamore@1113 80 enterKeyword(t.name, t);
mcimadamore@1113 81 else
mcimadamore@1113 82 tokenName[t.ordinal()] = null;
mcimadamore@1113 83 }
mcimadamore@1113 84
mcimadamore@1113 85 key = new TokenKind[maxKey+1];
mcimadamore@1113 86 for (int i = 0; i <= maxKey; i++) key[i] = TokenKind.IDENTIFIER;
mcimadamore@1113 87 for (TokenKind t : TokenKind.values()) {
mcimadamore@1113 88 if (t.name != null)
mcimadamore@1113 89 key[tokenName[t.ordinal()].getIndex()] = t;
mcimadamore@1113 90 }
mcimadamore@1113 91 }
mcimadamore@1113 92
mcimadamore@1113 93 private void enterKeyword(String s, TokenKind token) {
mcimadamore@1113 94 Name n = names.fromString(s);
mcimadamore@1113 95 tokenName[token.ordinal()] = n;
mcimadamore@1113 96 if (n.getIndex() > maxKey) maxKey = n.getIndex();
mcimadamore@1113 97 }
mcimadamore@1113 98
mcimadamore@1113 99 /**
mcimadamore@1113 100 * Create a new token given a name; if the name corresponds to a token name,
mcimadamore@1113 101 * a new token of the corresponding kind is returned; otherwise, an
mcimadamore@1113 102 * identifier token is returned.
mcimadamore@1113 103 */
mcimadamore@1113 104 TokenKind lookupKind(Name name) {
mcimadamore@1113 105 return (name.getIndex() > maxKey) ? TokenKind.IDENTIFIER : key[name.getIndex()];
mcimadamore@1113 106 }
mcimadamore@1113 107
mcimadamore@1113 108 TokenKind lookupKind(String name) {
mcimadamore@1113 109 return lookupKind(names.fromString(name));
mcimadamore@1113 110 }
mcimadamore@1113 111
mcimadamore@1113 112 /**
mcimadamore@1113 113 * This enum defines all tokens used by the javac scanner. A token is
mcimadamore@1113 114 * optionally associated with a name.
mcimadamore@1113 115 */
mcimadamore@1113 116 public enum TokenKind implements Formattable {
mcimadamore@1113 117 EOF(),
mcimadamore@1113 118 ERROR(),
mcimadamore@1113 119 IDENTIFIER(Tag.NAMED),
mcimadamore@1113 120 ABSTRACT("abstract"),
mcimadamore@1113 121 ASSERT("assert", Tag.NAMED),
mcimadamore@1113 122 BOOLEAN("boolean", Tag.NAMED),
mcimadamore@1113 123 BREAK("break"),
mcimadamore@1113 124 BYTE("byte", Tag.NAMED),
mcimadamore@1113 125 CASE("case"),
mcimadamore@1113 126 CATCH("catch"),
mcimadamore@1113 127 CHAR("char", Tag.NAMED),
mcimadamore@1113 128 CLASS("class"),
mcimadamore@1113 129 CONST("const"),
mcimadamore@1113 130 CONTINUE("continue"),
mcimadamore@1113 131 DEFAULT("default"),
mcimadamore@1113 132 DO("do"),
mcimadamore@1113 133 DOUBLE("double", Tag.NAMED),
mcimadamore@1113 134 ELSE("else"),
mcimadamore@1113 135 ENUM("enum", Tag.NAMED),
mcimadamore@1113 136 EXTENDS("extends"),
mcimadamore@1113 137 FINAL("final"),
mcimadamore@1113 138 FINALLY("finally"),
mcimadamore@1113 139 FLOAT("float", Tag.NAMED),
mcimadamore@1113 140 FOR("for"),
mcimadamore@1113 141 GOTO("goto"),
mcimadamore@1113 142 IF("if"),
mcimadamore@1113 143 IMPLEMENTS("implements"),
mcimadamore@1113 144 IMPORT("import"),
mcimadamore@1113 145 INSTANCEOF("instanceof"),
mcimadamore@1113 146 INT("int", Tag.NAMED),
mcimadamore@1113 147 INTERFACE("interface"),
mcimadamore@1113 148 LONG("long", Tag.NAMED),
mcimadamore@1113 149 NATIVE("native"),
mcimadamore@1113 150 NEW("new"),
mcimadamore@1113 151 PACKAGE("package"),
mcimadamore@1113 152 PRIVATE("private"),
mcimadamore@1113 153 PROTECTED("protected"),
mcimadamore@1113 154 PUBLIC("public"),
mcimadamore@1113 155 RETURN("return"),
mcimadamore@1113 156 SHORT("short", Tag.NAMED),
mcimadamore@1113 157 STATIC("static"),
mcimadamore@1113 158 STRICTFP("strictfp"),
mcimadamore@1113 159 SUPER("super", Tag.NAMED),
mcimadamore@1113 160 SWITCH("switch"),
mcimadamore@1113 161 SYNCHRONIZED("synchronized"),
mcimadamore@1113 162 THIS("this", Tag.NAMED),
mcimadamore@1113 163 THROW("throw"),
mcimadamore@1113 164 THROWS("throws"),
mcimadamore@1113 165 TRANSIENT("transient"),
mcimadamore@1113 166 TRY("try"),
mcimadamore@1113 167 VOID("void", Tag.NAMED),
mcimadamore@1113 168 VOLATILE("volatile"),
mcimadamore@1113 169 WHILE("while"),
mcimadamore@1113 170 INTLITERAL(Tag.NUMERIC),
mcimadamore@1113 171 LONGLITERAL(Tag.NUMERIC),
mcimadamore@1113 172 FLOATLITERAL(Tag.NUMERIC),
mcimadamore@1113 173 DOUBLELITERAL(Tag.NUMERIC),
mcimadamore@1113 174 CHARLITERAL(Tag.NUMERIC),
mcimadamore@1113 175 STRINGLITERAL(Tag.STRING),
mcimadamore@1113 176 TRUE("true", Tag.NAMED),
mcimadamore@1113 177 FALSE("false", Tag.NAMED),
mcimadamore@1113 178 NULL("null", Tag.NAMED),
mcimadamore@1113 179 LPAREN("("),
mcimadamore@1113 180 RPAREN(")"),
mcimadamore@1113 181 LBRACE("{"),
mcimadamore@1113 182 RBRACE("}"),
mcimadamore@1113 183 LBRACKET("["),
mcimadamore@1113 184 RBRACKET("]"),
mcimadamore@1113 185 SEMI(";"),
mcimadamore@1113 186 COMMA(","),
mcimadamore@1113 187 DOT("."),
mcimadamore@1113 188 ELLIPSIS("..."),
mcimadamore@1113 189 EQ("="),
mcimadamore@1113 190 GT(">"),
mcimadamore@1113 191 LT("<"),
mcimadamore@1113 192 BANG("!"),
mcimadamore@1113 193 TILDE("~"),
mcimadamore@1113 194 QUES("?"),
mcimadamore@1113 195 COLON(":"),
mcimadamore@1113 196 EQEQ("=="),
mcimadamore@1113 197 LTEQ("<="),
mcimadamore@1113 198 GTEQ(">="),
mcimadamore@1113 199 BANGEQ("!="),
mcimadamore@1113 200 AMPAMP("&&"),
mcimadamore@1113 201 BARBAR("||"),
mcimadamore@1113 202 PLUSPLUS("++"),
mcimadamore@1113 203 SUBSUB("--"),
mcimadamore@1113 204 PLUS("+"),
mcimadamore@1113 205 SUB("-"),
mcimadamore@1113 206 STAR("*"),
mcimadamore@1113 207 SLASH("/"),
mcimadamore@1113 208 AMP("&"),
mcimadamore@1113 209 BAR("|"),
mcimadamore@1113 210 CARET("^"),
mcimadamore@1113 211 PERCENT("%"),
mcimadamore@1113 212 LTLT("<<"),
mcimadamore@1113 213 GTGT(">>"),
mcimadamore@1113 214 GTGTGT(">>>"),
mcimadamore@1113 215 PLUSEQ("+="),
mcimadamore@1113 216 SUBEQ("-="),
mcimadamore@1113 217 STAREQ("*="),
mcimadamore@1113 218 SLASHEQ("/="),
mcimadamore@1113 219 AMPEQ("&="),
mcimadamore@1113 220 BAREQ("|="),
mcimadamore@1113 221 CARETEQ("^="),
mcimadamore@1113 222 PERCENTEQ("%="),
mcimadamore@1113 223 LTLTEQ("<<="),
mcimadamore@1113 224 GTGTEQ(">>="),
mcimadamore@1113 225 GTGTGTEQ(">>>="),
mcimadamore@1113 226 MONKEYS_AT("@"),
mcimadamore@1113 227 CUSTOM;
mcimadamore@1113 228
mcimadamore@1113 229 public final String name;
mcimadamore@1113 230 public final Tag tag;
mcimadamore@1113 231
mcimadamore@1113 232 TokenKind() {
mcimadamore@1113 233 this(null, Tag.DEFAULT);
mcimadamore@1113 234 }
mcimadamore@1113 235
mcimadamore@1113 236 TokenKind(String name) {
mcimadamore@1113 237 this(name, Tag.DEFAULT);
mcimadamore@1113 238 }
mcimadamore@1113 239
mcimadamore@1113 240 TokenKind(Tag tag) {
mcimadamore@1113 241 this(null, tag);
mcimadamore@1113 242 }
mcimadamore@1113 243
mcimadamore@1113 244 TokenKind(String name, Tag tag) {
mcimadamore@1113 245 this.name = name;
mcimadamore@1113 246 this.tag = tag;
mcimadamore@1113 247 }
mcimadamore@1113 248
mcimadamore@1113 249 public String toString() {
mcimadamore@1113 250 switch (this) {
mcimadamore@1113 251 case IDENTIFIER:
mcimadamore@1113 252 return "token.identifier";
mcimadamore@1113 253 case CHARLITERAL:
mcimadamore@1113 254 return "token.character";
mcimadamore@1113 255 case STRINGLITERAL:
mcimadamore@1113 256 return "token.string";
mcimadamore@1113 257 case INTLITERAL:
mcimadamore@1113 258 return "token.integer";
mcimadamore@1113 259 case LONGLITERAL:
mcimadamore@1113 260 return "token.long-integer";
mcimadamore@1113 261 case FLOATLITERAL:
mcimadamore@1113 262 return "token.float";
mcimadamore@1113 263 case DOUBLELITERAL:
mcimadamore@1113 264 return "token.double";
mcimadamore@1113 265 case ERROR:
mcimadamore@1113 266 return "token.bad-symbol";
mcimadamore@1113 267 case EOF:
mcimadamore@1113 268 return "token.end-of-input";
mcimadamore@1113 269 case DOT: case COMMA: case SEMI: case LPAREN: case RPAREN:
mcimadamore@1113 270 case LBRACKET: case RBRACKET: case LBRACE: case RBRACE:
mcimadamore@1113 271 return "'" + name + "'";
mcimadamore@1113 272 default:
mcimadamore@1113 273 return name;
mcimadamore@1113 274 }
mcimadamore@1113 275 }
mcimadamore@1113 276
mcimadamore@1113 277 public String getKind() {
mcimadamore@1113 278 return "Token";
mcimadamore@1113 279 }
mcimadamore@1113 280
mcimadamore@1113 281 public String toString(Locale locale, Messages messages) {
mcimadamore@1113 282 return name != null ? toString() : messages.getLocalizedString(locale, "compiler.misc." + toString());
mcimadamore@1113 283 }
mcimadamore@1113 284 }
mcimadamore@1113 285
mcimadamore@1125 286 public interface Comment {
mcimadamore@1125 287
mcimadamore@1125 288 enum CommentStyle {
mcimadamore@1125 289 LINE,
mcimadamore@1125 290 BLOCK,
mcimadamore@1125 291 JAVADOC,
mcimadamore@1125 292 }
mcimadamore@1125 293
mcimadamore@1125 294 String getText();
mcimadamore@1125 295 CommentStyle getStyle();
mcimadamore@1125 296 boolean isDeprecated();
mcimadamore@1125 297 }
mcimadamore@1125 298
mcimadamore@1113 299 /**
mcimadamore@1113 300 * This is the class representing a javac token. Each token has several fields
mcimadamore@1113 301 * that are set by the javac lexer (i.e. start/end position, string value, etc).
mcimadamore@1113 302 */
mcimadamore@1113 303 public static class Token {
mcimadamore@1113 304
mcimadamore@1113 305 /** tags constants **/
mcimadamore@1113 306 enum Tag {
mcimadamore@1113 307 DEFAULT,
mcimadamore@1113 308 NAMED,
mcimadamore@1113 309 STRING,
mcimadamore@1113 310 NUMERIC;
mcimadamore@1113 311 }
mcimadamore@1113 312
mcimadamore@1113 313 /** The token kind */
mcimadamore@1113 314 public final TokenKind kind;
mcimadamore@1113 315
mcimadamore@1113 316 /** The start position of this token */
mcimadamore@1113 317 public final int pos;
mcimadamore@1113 318
mcimadamore@1113 319 /** The end position of this token */
mcimadamore@1113 320 public final int endPos;
mcimadamore@1113 321
mcimadamore@1125 322 /** Comment reader associated with this token */
mcimadamore@1125 323 public final List<Comment> comments;
mcimadamore@1113 324
mcimadamore@1125 325 Token(TokenKind kind, int pos, int endPos, List<Comment> comments) {
mcimadamore@1113 326 this.kind = kind;
mcimadamore@1113 327 this.pos = pos;
mcimadamore@1113 328 this.endPos = endPos;
mcimadamore@1125 329 this.comments = comments;
mcimadamore@1113 330 checkKind();
mcimadamore@1113 331 }
mcimadamore@1113 332
mcimadamore@1113 333 Token[] split(Tokens tokens) {
mcimadamore@1113 334 if (kind.name.length() < 2 || kind.tag != Tag.DEFAULT) {
mcimadamore@1113 335 throw new AssertionError("Cant split" + kind);
mcimadamore@1113 336 }
mcimadamore@1113 337
mcimadamore@1113 338 TokenKind t1 = tokens.lookupKind(kind.name.substring(0, 1));
mcimadamore@1113 339 TokenKind t2 = tokens.lookupKind(kind.name.substring(1));
mcimadamore@1113 340
mcimadamore@1113 341 if (t1 == null || t2 == null) {
mcimadamore@1113 342 throw new AssertionError("Cant split - bad subtokens");
mcimadamore@1113 343 }
mcimadamore@1113 344 return new Token[] {
mcimadamore@1125 345 new Token(t1, pos, pos + t1.name.length(), comments),
mcimadamore@1125 346 new Token(t2, pos + t1.name.length(), endPos, null)
mcimadamore@1113 347 };
mcimadamore@1113 348 }
mcimadamore@1113 349
mcimadamore@1113 350 protected void checkKind() {
mcimadamore@1113 351 if (kind.tag != Tag.DEFAULT) {
mcimadamore@1113 352 throw new AssertionError("Bad token kind - expected " + Tag.STRING);
mcimadamore@1113 353 }
mcimadamore@1113 354 }
mcimadamore@1113 355
mcimadamore@1113 356 public Name name() {
mcimadamore@1113 357 throw new UnsupportedOperationException();
mcimadamore@1113 358 }
mcimadamore@1113 359
mcimadamore@1113 360 public String stringVal() {
mcimadamore@1113 361 throw new UnsupportedOperationException();
mcimadamore@1113 362 }
mcimadamore@1113 363
mcimadamore@1113 364 public int radix() {
mcimadamore@1113 365 throw new UnsupportedOperationException();
mcimadamore@1113 366 }
mcimadamore@1125 367
mcimadamore@1125 368 /**
mcimadamore@1125 369 * Preserve classic semantics - if multiple javadocs are found on the token
mcimadamore@1125 370 * the last one is returned
mcimadamore@1125 371 */
mcimadamore@1125 372 public String comment(Comment.CommentStyle style) {
mcimadamore@1125 373 List<Comment> readers = getReaders(Comment.CommentStyle.JAVADOC);
mcimadamore@1125 374 return readers.isEmpty() ?
mcimadamore@1125 375 null :
mcimadamore@1125 376 readers.head.getText();
mcimadamore@1125 377 }
mcimadamore@1125 378
mcimadamore@1125 379 /**
mcimadamore@1125 380 * Preserve classic semantics - deprecated should be set if at least one
mcimadamore@1125 381 * javadoc comment attached to this token contains the '@deprecated' string
mcimadamore@1125 382 */
mcimadamore@1125 383 public boolean deprecatedFlag() {
mcimadamore@1125 384 for (Comment r : getReaders(Comment.CommentStyle.JAVADOC)) {
mcimadamore@1125 385 if (r.isDeprecated()) {
mcimadamore@1125 386 return true;
mcimadamore@1125 387 }
mcimadamore@1125 388 }
mcimadamore@1125 389 return false;
mcimadamore@1125 390 }
mcimadamore@1125 391
mcimadamore@1125 392 private List<Comment> getReaders(Comment.CommentStyle style) {
mcimadamore@1125 393 if (comments == null) {
mcimadamore@1125 394 return List.nil();
mcimadamore@1125 395 } else {
mcimadamore@1125 396 ListBuffer<Comment> buf = ListBuffer.lb();
mcimadamore@1125 397 for (Comment r : comments) {
mcimadamore@1125 398 if (r.getStyle() == style) {
mcimadamore@1125 399 buf.add(r);
mcimadamore@1125 400 }
mcimadamore@1125 401 }
mcimadamore@1125 402 return buf.toList();
mcimadamore@1125 403 }
mcimadamore@1125 404 }
mcimadamore@1113 405 }
mcimadamore@1113 406
mcimadamore@1113 407 final static class NamedToken extends Token {
mcimadamore@1113 408 /** The name of this token */
mcimadamore@1113 409 public final Name name;
mcimadamore@1113 410
mcimadamore@1125 411 public NamedToken(TokenKind kind, int pos, int endPos, Name name, List<Comment> comments) {
mcimadamore@1125 412 super(kind, pos, endPos, comments);
mcimadamore@1113 413 this.name = name;
mcimadamore@1113 414 }
mcimadamore@1113 415
mcimadamore@1113 416 protected void checkKind() {
mcimadamore@1113 417 if (kind.tag != Tag.NAMED) {
mcimadamore@1113 418 throw new AssertionError("Bad token kind - expected " + Tag.NAMED);
mcimadamore@1113 419 }
mcimadamore@1113 420 }
mcimadamore@1113 421
mcimadamore@1113 422 @Override
mcimadamore@1113 423 public Name name() {
mcimadamore@1113 424 return name;
mcimadamore@1113 425 }
mcimadamore@1113 426 }
mcimadamore@1113 427
mcimadamore@1113 428 static class StringToken extends Token {
mcimadamore@1113 429 /** The string value of this token */
mcimadamore@1113 430 public final String stringVal;
mcimadamore@1113 431
mcimadamore@1125 432 public StringToken(TokenKind kind, int pos, int endPos, String stringVal, List<Comment> comments) {
mcimadamore@1125 433 super(kind, pos, endPos, comments);
mcimadamore@1113 434 this.stringVal = stringVal;
mcimadamore@1113 435 }
mcimadamore@1113 436
mcimadamore@1113 437 protected void checkKind() {
mcimadamore@1113 438 if (kind.tag != Tag.STRING) {
mcimadamore@1113 439 throw new AssertionError("Bad token kind - expected " + Tag.STRING);
mcimadamore@1113 440 }
mcimadamore@1113 441 }
mcimadamore@1113 442
mcimadamore@1113 443 @Override
mcimadamore@1113 444 public String stringVal() {
mcimadamore@1113 445 return stringVal;
mcimadamore@1113 446 }
mcimadamore@1113 447 }
mcimadamore@1113 448
mcimadamore@1113 449 final static class NumericToken extends StringToken {
mcimadamore@1113 450 /** The 'radix' value of this token */
mcimadamore@1113 451 public final int radix;
mcimadamore@1113 452
mcimadamore@1125 453 public NumericToken(TokenKind kind, int pos, int endPos, String stringVal, int radix, List<Comment> comments) {
mcimadamore@1125 454 super(kind, pos, endPos, stringVal, comments);
mcimadamore@1113 455 this.radix = radix;
mcimadamore@1113 456 }
mcimadamore@1113 457
mcimadamore@1113 458 protected void checkKind() {
mcimadamore@1113 459 if (kind.tag != Tag.NUMERIC) {
mcimadamore@1113 460 throw new AssertionError("Bad token kind - expected " + Tag.NUMERIC);
mcimadamore@1113 461 }
mcimadamore@1113 462 }
mcimadamore@1113 463
mcimadamore@1113 464 @Override
mcimadamore@1113 465 public int radix() {
mcimadamore@1113 466 return radix;
mcimadamore@1113 467 }
mcimadamore@1113 468 }
mcimadamore@1113 469
mcimadamore@1113 470 public static final Token DUMMY =
mcimadamore@1125 471 new Token(TokenKind.ERROR, 0, 0, null);
mcimadamore@1113 472 }

mercurial