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