001    /*
002     * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.tools.javac.parser;
027    
028    import java.util.Locale;
029    
030    import com.sun.tools.javac.api.Formattable;
031    import com.sun.tools.javac.api.Messages;
032    
033    /** An interface that defines codes for Java source tokens
034     *  returned from lexical analysis.
035     *
036     *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
037     *  you write code that depends on this, you do so at your own risk.
038     *  This code and its internal interfaces are subject to change or
039     *  deletion without notice.</b>
040     */
041    public enum Token implements Formattable {
042        EOF,
043        ERROR,
044        IDENTIFIER,
045        ABSTRACT("abstract"),
046        ASSERT("assert"),
047        BOOLEAN("boolean"),
048        BREAK("break"),
049        BYTE("byte"),
050        CASE("case"),
051        CATCH("catch"),
052        CHAR("char"),
053        CLASS("class"),
054        CONST("const"),
055        CONTINUE("continue"),
056        DEFAULT("default"),
057        DO("do"),
058        DOUBLE("double"),
059        ELSE("else"),
060        ENUM("enum"),
061        EXTENDS("extends"),
062        FINAL("final"),
063        FINALLY("finally"),
064        FLOAT("float"),
065        FOR("for"),
066        GOTO("goto"),
067        IF("if"),
068        IMPLEMENTS("implements"),
069        IMPORT("import"),
070        INSTANCEOF("instanceof"),
071        INT("int"),
072        INTERFACE("interface"),
073        LET("let"),
074        LONG("long"),
075        NATIVE("native"),
076        NEW("new"),
077        PACKAGE("package"),
078        PRIVATE("private"),
079        PROTECTED("protected"),
080        PUBLIC("public"),
081        RETURN("return"),
082        SHORT("short"),
083        STATIC("static"),
084        STRICTFP("strictfp"),
085        SUPER("super"),
086        SWITCH("switch"),
087        SYNCHRONIZED("synchronized"),
088        THIS("this"),
089        THROW("throw"),
090        THROWS("throws"),
091        TRANSIENT("transient"),
092        TRY("try"),
093        VOID("void"),
094        VOLATILE("volatile"),
095        WHILE("while"),
096        INTLITERAL,
097        LONGLITERAL,
098        FLOATLITERAL,
099        DOUBLELITERAL,
100        CHARLITERAL,
101        STRINGLITERAL,
102        TRUE("true"),
103        FALSE("false"),
104        NULL("null"),
105        LPAREN("("),
106        RPAREN(")"),
107        LBRACE("{"),
108        RBRACE("}"),
109        LBRACKET("["),
110        RBRACKET("]"),
111            /* emw4: staging constructs */
112        L_CODE_BRACKET("<|"),
113        R_CODE_BRACKET("|>"),
114        ESCAPE("`"),
115        SEPARABLE("separable"),
116        SEMI(";"),
117        COMMA(","),
118        DOT("."),
119        ELLIPSIS("..."),
120        EQ("="),
121        GT(">"),
122        LT("<"),
123        BANG("!"),
124        TILDE("~"),
125        QUES("?"),
126        COLON(":"),
127        EQEQ("=="),
128        LTEQ("<="),
129        GTEQ(">="),
130        BANGEQ("!="),
131        AMPAMP("&&"),
132        BARBAR("||"),
133        PLUSPLUS("++"),
134        SUBSUB("--"),
135        PLUS("+"),
136        SUB("-"),
137        STAR("*"),
138        SLASH("/"),
139        AMP("&"),
140        BAR("|"),
141        CARET("^"),
142        PERCENT("%"),
143        LTLT("<<"),
144        GTGT(">>"),
145        GTGTGT(">>>"),
146        PLUSEQ("+="),
147        SUBEQ("-="),
148        STAREQ("*="),
149        SLASHEQ("/="),
150        AMPEQ("&="),
151        BAREQ("|="),
152        CARETEQ("^="),
153        PERCENTEQ("%="),
154        LTLTEQ("<<="),
155        GTGTEQ(">>="),
156        GTGTGTEQ(">>>="),
157        MONKEYS_AT("@"),
158        CUSTOM;
159    
160        Token() {
161            this(null);
162        }
163        Token(String name) {
164            this.name = name;
165        }
166    
167        public final String name;
168    
169        public String toString() {
170            switch (this) {
171            case IDENTIFIER:
172                return "token.identifier";
173            case CHARLITERAL:
174                return "token.character";
175            case STRINGLITERAL:
176                return "token.string";
177            case INTLITERAL:
178                return "token.integer";
179            case LONGLITERAL:
180                return "token.long-integer";
181            case FLOATLITERAL:
182                return "token.float";
183            case DOUBLELITERAL:
184                return "token.double";
185            case ERROR:
186                return "token.bad-symbol";
187            case EOF:
188                return "token.end-of-input";
189            case DOT: case COMMA: case SEMI: case LPAREN: case RPAREN:
190            case LBRACKET: case RBRACKET: case LBRACE: case RBRACE:
191                return "'" + name + "'";
192            default:
193                return name;
194            }
195        }
196    
197        public String getKind() {
198            return "Token";
199        }
200    
201        public String toString(Locale locale, Messages messages) {
202            return name != null ? toString() : messages.getLocalizedString(locale, "compiler.misc." + toString());
203        }
204    }