duke@1: /* ohair@554: * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.javac.parser; duke@1: mcimadamore@136: import java.util.Locale; mcimadamore@80: mcimadamore@80: import com.sun.tools.javac.api.Formattable; mcimadamore@136: import com.sun.tools.javac.api.Messages; duke@1: duke@1: /** An interface that defines codes for Java source tokens duke@1: * returned from lexical analysis. duke@1: * jjg@581: *

This is NOT part of any supported API. jjg@581: * If you write code that depends on this, you do so at your own risk. duke@1: * This code and its internal interfaces are subject to change or duke@1: * deletion without notice. duke@1: */ mcimadamore@80: public enum Token implements Formattable { duke@1: EOF, duke@1: ERROR, duke@1: IDENTIFIER, duke@1: ABSTRACT("abstract"), duke@1: ASSERT("assert"), duke@1: BOOLEAN("boolean"), duke@1: BREAK("break"), duke@1: BYTE("byte"), duke@1: CASE("case"), duke@1: CATCH("catch"), duke@1: CHAR("char"), duke@1: CLASS("class"), duke@1: CONST("const"), duke@1: CONTINUE("continue"), duke@1: DEFAULT("default"), duke@1: DO("do"), duke@1: DOUBLE("double"), duke@1: ELSE("else"), duke@1: ENUM("enum"), duke@1: EXTENDS("extends"), duke@1: FINAL("final"), duke@1: FINALLY("finally"), duke@1: FLOAT("float"), duke@1: FOR("for"), duke@1: GOTO("goto"), duke@1: IF("if"), duke@1: IMPLEMENTS("implements"), duke@1: IMPORT("import"), duke@1: INSTANCEOF("instanceof"), duke@1: INT("int"), duke@1: INTERFACE("interface"), duke@1: LONG("long"), duke@1: NATIVE("native"), duke@1: NEW("new"), duke@1: PACKAGE("package"), duke@1: PRIVATE("private"), duke@1: PROTECTED("protected"), duke@1: PUBLIC("public"), duke@1: RETURN("return"), duke@1: SHORT("short"), duke@1: STATIC("static"), duke@1: STRICTFP("strictfp"), duke@1: SUPER("super"), duke@1: SWITCH("switch"), duke@1: SYNCHRONIZED("synchronized"), duke@1: THIS("this"), duke@1: THROW("throw"), duke@1: THROWS("throws"), duke@1: TRANSIENT("transient"), duke@1: TRY("try"), duke@1: VOID("void"), duke@1: VOLATILE("volatile"), duke@1: WHILE("while"), duke@1: INTLITERAL, duke@1: LONGLITERAL, duke@1: FLOATLITERAL, duke@1: DOUBLELITERAL, duke@1: CHARLITERAL, duke@1: STRINGLITERAL, duke@1: TRUE("true"), duke@1: FALSE("false"), duke@1: NULL("null"), duke@1: LPAREN("("), duke@1: RPAREN(")"), duke@1: LBRACE("{"), duke@1: RBRACE("}"), duke@1: LBRACKET("["), duke@1: RBRACKET("]"), duke@1: SEMI(";"), duke@1: COMMA(","), duke@1: DOT("."), duke@1: ELLIPSIS("..."), duke@1: EQ("="), duke@1: GT(">"), duke@1: LT("<"), duke@1: BANG("!"), duke@1: TILDE("~"), duke@1: QUES("?"), duke@1: COLON(":"), duke@1: EQEQ("=="), duke@1: LTEQ("<="), duke@1: GTEQ(">="), duke@1: BANGEQ("!="), duke@1: AMPAMP("&&"), duke@1: BARBAR("||"), duke@1: PLUSPLUS("++"), duke@1: SUBSUB("--"), duke@1: PLUS("+"), duke@1: SUB("-"), duke@1: STAR("*"), duke@1: SLASH("/"), duke@1: AMP("&"), duke@1: BAR("|"), duke@1: CARET("^"), duke@1: PERCENT("%"), duke@1: LTLT("<<"), duke@1: GTGT(">>"), duke@1: GTGTGT(">>>"), duke@1: PLUSEQ("+="), duke@1: SUBEQ("-="), duke@1: STAREQ("*="), duke@1: SLASHEQ("/="), duke@1: AMPEQ("&="), duke@1: BAREQ("|="), duke@1: CARETEQ("^="), duke@1: PERCENTEQ("%="), duke@1: LTLTEQ("<<="), duke@1: GTGTEQ(">>="), duke@1: GTGTGTEQ(">>>="), duke@1: MONKEYS_AT("@"), duke@1: CUSTOM; duke@1: duke@1: Token() { duke@1: this(null); duke@1: } duke@1: Token(String name) { duke@1: this.name = name; duke@1: } duke@1: duke@1: public final String name; mcimadamore@80: mcimadamore@80: public String toString() { mcimadamore@80: switch (this) { mcimadamore@80: case IDENTIFIER: mcimadamore@80: return "token.identifier"; mcimadamore@80: case CHARLITERAL: mcimadamore@80: return "token.character"; mcimadamore@80: case STRINGLITERAL: mcimadamore@80: return "token.string"; mcimadamore@80: case INTLITERAL: mcimadamore@80: return "token.integer"; mcimadamore@80: case LONGLITERAL: mcimadamore@80: return "token.long-integer"; mcimadamore@80: case FLOATLITERAL: mcimadamore@80: return "token.float"; mcimadamore@80: case DOUBLELITERAL: mcimadamore@80: return "token.double"; mcimadamore@80: case ERROR: mcimadamore@80: return "token.bad-symbol"; mcimadamore@80: case EOF: mcimadamore@80: return "token.end-of-input"; mcimadamore@80: case DOT: case COMMA: case SEMI: case LPAREN: case RPAREN: mcimadamore@80: case LBRACKET: case RBRACKET: case LBRACE: case RBRACE: mcimadamore@80: return "'" + name + "'"; mcimadamore@80: default: mcimadamore@80: return name; mcimadamore@80: } mcimadamore@80: } mcimadamore@80: mcimadamore@80: public String getKind() { mcimadamore@80: return "Token"; mcimadamore@80: } mcimadamore@80: mcimadamore@136: public String toString(Locale locale, Messages messages) { mcimadamore@136: return name != null ? toString() : messages.getLocalizedString(locale, "compiler.misc." + toString()); mcimadamore@80: } duke@1: }