1 /*
   2  * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.tools.javac.parser;
  27 
  28 import java.util.Locale;
  29 
  30 import com.sun.tools.javac.api.Formattable;
  31 import com.sun.tools.javac.api.Messages;
  32 
  33 /** An interface that defines codes for Java source tokens
  34  *  returned from lexical analysis.
  35  *
  36  *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
  37  *  you write code that depends on this, you do so at your own risk.
  38  *  This code and its internal interfaces are subject to change or
  39  *  deletion without notice.</b>
  40  */
  41 public enum Token implements Formattable {
  42     EOF,
  43     ERROR,
  44     IDENTIFIER,
  45     ABSTRACT("abstract"),
  46     ASSERT("assert"),
  47     BOOLEAN("boolean"),
  48     BREAK("break"),
  49     BYTE("byte"),
  50     CASE("case"),
  51     CATCH("catch"),
  52     CHAR("char"),
  53     CLASS("class"),
  54     CONST("const"),
  55     CONTINUE("continue"),
  56     DEFAULT("default"),
  57     DO("do"),
  58     DOUBLE("double"),
  59     ELSE("else"),
  60     ENUM("enum"),
  61     EXTENDS("extends"),
  62     FINAL("final"),
  63     FINALLY("finally"),
  64     FLOAT("float"),
  65     FOR("for"),
  66     GOTO("goto"),
  67     IF("if"),
  68     IMPLEMENTS("implements"),
  69     IMPORT("import"),
  70     INSTANCEOF("instanceof"),
  71     INT("int"),
  72     INTERFACE("interface"),
  73     LONG("long"),
  74     NATIVE("native"),
  75     NEW("new"),
  76     PACKAGE("package"),
  77     PRIVATE("private"),
  78     PROTECTED("protected"),
  79     PUBLIC("public"),
  80     RETURN("return"),
  81     SHORT("short"),
  82     STATIC("static"),
  83     STRICTFP("strictfp"),
  84     SUPER("super"),
  85     SWITCH("switch"),
  86     SYNCHRONIZED("synchronized"),
  87     THIS("this"),
  88     THROW("throw"),
  89     THROWS("throws"),
  90     TRANSIENT("transient"),
  91     TRY("try"),
  92     VOID("void"),
  93     VOLATILE("volatile"),
  94     WHILE("while"),
  95     INTLITERAL,
  96     LONGLITERAL,
  97     FLOATLITERAL,
  98     DOUBLELITERAL,
  99     CHARLITERAL,
 100     STRINGLITERAL,
 101     TRUE("true"),
 102     FALSE("false"),
 103     NULL("null"),
 104     LPAREN("("),
 105     RPAREN(")"),
 106     LBRACE("{"),
 107     RBRACE("}"),
 108     LBRACKET("["),
 109     RBRACKET("]"),
 110     SEMI(";"),
 111     COMMA(","),
 112     DOT("."),
 113     ELLIPSIS("..."),
 114     EQ("="),
 115     GT(">"),
 116     LT("<"),
 117     BANG("!"),
 118     TILDE("~"),
 119     QUES("?"),
 120     COLON(":"),
 121     EQEQ("=="),
 122     LTEQ("<="),
 123     GTEQ(">="),
 124     BANGEQ("!="),
 125     AMPAMP("&&"),
 126     BARBAR("||"),
 127     PLUSPLUS("++"),
 128     SUBSUB("--"),
 129     PLUS("+"),
 130     SUB("-"),
 131     STAR("*"),
 132     SLASH("/"),
 133     AMP("&"),
 134     BAR("|"),
 135     CARET("^"),
 136     PERCENT("%"),
 137     LTLT("<<"),
 138     GTGT(">>"),
 139     GTGTGT(">>>"),
 140     PLUSEQ("+="),
 141     SUBEQ("-="),
 142     STAREQ("*="),
 143     SLASHEQ("/="),
 144     AMPEQ("&="),
 145     BAREQ("|="),
 146     CARETEQ("^="),
 147     PERCENTEQ("%="),
 148     LTLTEQ("<<="),
 149     GTGTEQ(">>="),
 150     GTGTGTEQ(">>>="),
 151     MONKEYS_AT("@"),
 152     CUSTOM;
 153 
 154     Token() {
 155         this(null);
 156     }
 157     Token(String name) {
 158         this.name = name;
 159     }
 160 
 161     public final String name;
 162 
 163     public String toString() {
 164         switch (this) {
 165         case IDENTIFIER:
 166             return "token.identifier";
 167         case CHARLITERAL:
 168             return "token.character";
 169         case STRINGLITERAL:
 170             return "token.string";
 171         case INTLITERAL:
 172             return "token.integer";
 173         case LONGLITERAL:
 174             return "token.long-integer";
 175         case FLOATLITERAL:
 176             return "token.float";
 177         case DOUBLELITERAL:
 178             return "token.double";
 179         case ERROR:
 180             return "token.bad-symbol";
 181         case EOF:
 182             return "token.end-of-input";
 183         case DOT: case COMMA: case SEMI: case LPAREN: case RPAREN:
 184         case LBRACKET: case RBRACKET: case LBRACE: case RBRACE:
 185             return "'" + name + "'";
 186         default:
 187             return name;
 188         }
 189     }
 190 
 191     public String getKind() {
 192         return "Token";
 193     }
 194 
 195     public String toString(Locale locale, Messages messages) {
 196         return name != null ? toString() : messages.getLocalizedString(locale, "compiler.misc." + toString());
 197     }
 198 }