langtools/src/share/classes/javax/lang/model/SourceVersion.java
author jjh
Wed, 13 Apr 2011 11:35:43 -0700
changeset 9303 eae35c201e19
parent 5520 86e4b9a9da40
child 10180 b293c1f36ac4
permissions -rw-r--r--
7032975: API files in javax.annotation.processing need to be updated for references to JLS 7032972: API files in javax.tools need to updated for references to JVM Spec with editions/hyperlinks 7032978: API files in javax.tools need to be updated for references to JLS with editions/hyperlinks Summary: Removed URLs and 'edition' references Reviewed-by: jjg, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. 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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
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 javax.lang.model;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.HashSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * Source versions of the Java™ programming language.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    35
 * See the appropriate edition of
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    36
 * <cite>The Java&trade; Language Specification</cite>
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    37
 * for information about a particular source version.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * <p>Note that additional source version constants will be added to
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * model future releases of the language.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public enum SourceVersion {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * Summary of language evoluation
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * 1.1: nested classes
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * 1.2: strictfp
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     * 1.3: no changes
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * 1.4: assert
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * 1.5: annotations, generics, autoboxing, var-args...
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * 1.6: no changes
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * The original version.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    61
     * The language described in
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    62
     * <cite>The Java&trade; Language Specification, First Edition</cite>.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    RELEASE_0,
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * The version recognized by the Java Platform 1.1.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    69
     * The language is {@code RELEASE_0} augmented with nested classes as described in the 1.1 update to
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    70
     * <cite>The Java&trade; Language Specification, First Edition</cite>.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    RELEASE_1,
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * The version recognized by the Java 2 Platform, Standard Edition,
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * v 1.2.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    78
     * The language described in
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    79
     * <cite>The Java&trade; Language Specification,
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
    80
     * Second Edition</cite>, which includes the {@code
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * strictfp} modifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    RELEASE_2,
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * The version recognized by the Java 2 Platform, Standard Edition,
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * v 1.3.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * No major changes from {@code RELEASE_2}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    RELEASE_3,
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * The version recognized by the Java 2 Platform, Standard Edition,
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * v 1.4.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * Added a simple assertion facility.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    RELEASE_4,
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * The version recognized by the Java 2 Platform, Standard
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * Edition 5.0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   105
     * The language described in
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   106
     * <cite>The Java&trade; Language Specification,
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   107
     * Third Edition</cite>.  First release to support
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * generics, annotations, autoboxing, var-args, enhanced {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * for} loop, and hexadecimal floating-point literals.
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    RELEASE_5,
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * The version recognized by the Java Platform, Standard Edition
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * 6.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * No major changes from {@code RELEASE_5}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    RELEASE_6,
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     * The version recognized by the Java Platform, Standard Edition
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * 7.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * @since 1.7
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    RELEASE_7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    // Note that when adding constants for newer releases, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    // behavior of latest() and latestSupported() must be updated too.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * Returns the latest source version that can be modeled.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * @return the latest source version that can be modeled
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    public static SourceVersion latest() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        return RELEASE_7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    private static final SourceVersion latestSupported = getLatestSupported();
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    private static SourceVersion getLatestSupported() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            String specVersion = System.getProperty("java.specification.version");
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            if ("1.7".equals(specVersion))
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                return RELEASE_7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            else if ("1.6".equals(specVersion))
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                return RELEASE_6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        } catch (SecurityException se) {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        return RELEASE_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * Returns the latest source version fully supported by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * current execution environment.  {@code RELEASE_5} or later must
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * be returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * @return the latest source version that is fully supported
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public static SourceVersion latestSupported() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        return latestSupported;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * Returns whether or not {@code name} is a syntactically valid
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * identifier (simple name) or keyword in the latest source
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * version.  The method returns {@code true} if the name consists
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * of an initial character for which {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * Character#isJavaIdentifierStart(int)} returns {@code true},
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * followed only by characters for which {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * Character#isJavaIdentifierPart(int)} returns {@code true}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * This pattern matches regular identifiers, keywords, and the
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * literals {@code "true"}, {@code "false"}, and {@code "null"}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * The method returns {@code false} for all other strings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * @param name the string to check
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * @return {@code true} if this string is a
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * syntactically valid identifier or keyword, {@code false}
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public static boolean isIdentifier(CharSequence name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        String id = name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        if (id.length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        int cp = id.codePointAt(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        if (!Character.isJavaIdentifierStart(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        for (int i = Character.charCount(cp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                i < id.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                i += Character.charCount(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            cp = id.codePointAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            if (!Character.isJavaIdentifierPart(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     *  Returns whether or not {@code name} is a syntactically valid
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     *  qualified name in the latest source version.  Unlike {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     *  #isIdentifier isIdentifier}, this method returns {@code false}
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     *  for keywords and literals.
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * @param name the string to check
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * @return {@code true} if this string is a
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * syntactically valid name, {@code false} otherwise.
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 5520
diff changeset
   213
     * @jls 6.2 Names and Identifiers
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    public static boolean isName(CharSequence name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        String id = name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        for(String s : id.split("\\.", -1)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            if (!isIdentifier(s) || isKeyword(s))
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    private final static Set<String> keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        Set<String> s = new HashSet<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        String [] kws = {
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            "abstract", "continue",     "for",          "new",          "switch",
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            "assert",   "default",      "if",           "package",      "synchronized",
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            "boolean",  "do",           "goto",         "private",      "this",
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            "break",    "double",       "implements",   "protected",    "throw",
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            "byte",     "else",         "import",       "public",       "throws",
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            "case",     "enum",         "instanceof",   "return",       "transient",
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
            "catch",    "extends",      "int",          "short",        "try",
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            "char",     "final",        "interface",    "static",       "void",
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            "class",    "finally",      "long",         "strictfp",     "volatile",
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            "const",    "float",        "native",       "super",        "while",
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            // literals
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            "null",     "true",         "false"
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        };
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        for(String kw : kws)
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            s.add(kw);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        keywords = Collections.unmodifiableSet(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     *  Returns whether or not {@code s} is a keyword or literal in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     *  latest source version.
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * @param s the string to check
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * @return {@code true} if {@code s} is a keyword or literal, {@code false} otherwise.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    public static boolean isKeyword(CharSequence s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        String keywordOrLiteral = s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        return keywords.contains(keywordOrLiteral);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
}