API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.lang.model. SourceVersion View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

/*
 * @(#)SourceVersion.java	1.6 06/08/15
 *
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL.  Use is subject to license terms.
 */

package javax.lang.model;

import java.util.Collections;
import java.util.Set;
import java.util.HashSet;

/**
 * Source versions of the Java™ programming language.
 * 
 * See <a
 * href="http://java.sun.com/docs/books/jls/">http://java.sun.com/docs/books/jls/</a>
 * for information on editions of <i>The Java&trade; Language
 * Specification</i>, including updates and clarifications.
 *
 * <p>Note that additional source version constants will be added to
 * model future releases of the language.
 *
 * @author Joseph D. Darcy
 * @author Scott Seligman
 * @author Peter von der Ah&eacute;
 * @version 1.6 06/08/15
 * @since 1.6
 */
public enum SourceVersion {
    /*
     * Summary of language evoluation
     * 1.1: nested classes
     * 1.2: strictfp
     * 1.3: no changes
     * 1.4: assert
     * 1.5: annotations, generics, autoboxing, var-args... 
     * 1.6: no changes
     */

    /**
     * The original version.
     * 
     * The language described in the first edition of <i>The
     * Java&trade; Language Specification</i>.
     */
    RELEASE_0,

    /**
     * The version recognized by the Java Platform 1.1.
     *
     * The language is {@code RELEASE_0} <a
     * href="http://java.sun.com/docs/books/jls/first_edition/html/1.1Update.html">augmented</a>
     * with nested classes.
     */
    RELEASE_1,

    /**
     * The version recognized by the Java 2 Platform, Standard Edition,
     * v 1.2.
     *
     * The language described in <i>The Java&trade; Language
     * Specification, Second Edition</i>, which includes the {@code
     * strictfp} modifier.
     */
    RELEASE_2,

    /**
     * The version recognized by the Java 2 Platform, Standard Edition,
     * v 1.3.
     *
     * No major changes from {@code RELEASE_2}.
     */
    RELEASE_3,

    /**
     * The version recognized by the Java 2 Platform, Standard Edition,
     * v 1.4.
     *
     * Added a simple assertion facility.
     */
    RELEASE_4,

    /**
     * The version recognized by the Java 2 Platform, Standard
     * Edition 5.0.
     *
     * The language described in <i>The Java&trade; Language
     * Specification, Third Edition</i>.  First release to support
     * generics, annotations, autoboxing, var-args, enhanced {@code
     * for} loop, and hexadecimal floating-point literals.
     */
    RELEASE_5,

    /**
     * The version recognized by the Java Platform, Standard Edition
     * 6.
     *
     * No major changes from {@code RELEASE_5}.
     */
    RELEASE_6;


    /**
     * Returns the latest source version that can be modeled.
     *
     * @return the latest source version that can be modeled
     */
    public static SourceVersion latest() {
	return RELEASE_6;
    }

    /**
     * Returns the latest source version fully supported by the
     * current execution environment.  {@code RELEASE_5} or later must
     * be returned.
     *
     * @return the latest source version that is fully supported
     */
    public static SourceVersion latestSupported() {
	return RELEASE_6;
    }

    /**
     * Returns whether or not {@code name} is a syntactically valid
     * identifier (simple name) or keyword in the latest source
     * version.  The method returns {@code true} if the name consists
     * of an initial character for which {@link
     * Character#isJavaIdentifierStart(int)} returns {@code true},
     * followed only by characters for which {@link
     * Character#isJavaIdentifierPart(int)} returns {@code true}.
     * This pattern matches regular identifiers, keywords, and the
     * literals {@code "true"}, {@code "false"}, and {@code "null"}.
     * The method returns {@code false} for all other strings.
     *
     * @param name the string to check
     * @return {@code true} if this string is a
     * syntactically valid identifier or keyword, {@code false}
     * otherwise.
     */
    public static boolean isIdentifier(CharSequence name) {
	String id = name.toString();
	
	if (id.length() == 0) {
	    return false;
	}
	int cp = id.codePointAt(0);
        if (!Character.isJavaIdentifierStart(cp)) {
	    return false;
	}
        for (int i = Character.charCount(cp);
		i < id.length();
		i += Character.charCount(cp)) {
	    cp = id.codePointAt(i);
            if (!Character.isJavaIdentifierPart(cp)) {
		return false;
	    }
        }
        return true;
    }

    /**
     *  Returns whether or not {@code name} is a syntactically valid
     *  qualified name in the latest source version.  Unlike {@link
     *  #isIdentifier isIdentifier}, this method returns {@code false}
     *  for keywords and literals.
     *
     * @param name the string to check
     * @return {@code true} if this string is a
     * syntactically valid name, {@code false} otherwise.
     * @jls3 6.2 Names and Identifiers
     */
    public static boolean isName(CharSequence name) {
	String id = name.toString();
	
	for(String s : id.split("\\.", -1)) {
	    if (!isIdentifier(s) || isKeyword(s))
		return false;
	}
	return true;
    }

    private final static Set<String> keywords;
    static {
	Set<String> s = new HashSet<String>();
	String [] kws = {
	    "abstract",	"continue",	"for",		"new",		"switch",
	    "assert",	"default",	"if",		"package",	"synchronized",
	    "boolean",	"do",		"goto",		"private",	"this",
	    "break",	"double",	"implements",	"protected",	"throw",
	    "byte",	"else",		"import",	"public",	"throws",
	    "case",	"enum",		"instanceof",	"return",	"transient",
	    "catch",	"extends",	"int",		"short",	"try",
	    "char",	"final",	"interface",	"static",	"void",
	    "class",	"finally",	"long",		"strictfp",	"volatile",
	    "const",	"float",	"native",	"super",	"while",
	    // literals
	    "null",	"true",		"false"
	};
	for(String kw : kws)
	    s.add(kw);
	keywords = Collections.unmodifiableSet(s);
    }

    /**
     *  Returns whether or not {@code s} is a keyword or literal in the
     *  latest source version.
     *
     * @param s the string to check
     * @return {@code true} if {@code s} is a keyword or literal, {@code false} otherwise.
     */
    public static boolean isKeyword(CharSequence s) {
	String keywordOrLiteral = s.toString();
	return keywords.contains(keywordOrLiteral);
    }
} 

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar