44 * @author Peter von der Ahé
45 * @since 1.6
46 */
47 public enum SourceVersion {
48 /*
49 * Summary of language evolution
50 * 1.1: nested classes
51 * 1.2: strictfp
52 * 1.3: no changes
53 * 1.4: assert
54 * 1.5: annotations, generics, autoboxing, var-args...
55 * 1.6: no changes
56 * 1.7: diamond syntax, try-with-resources, etc.
57 * 1.8: lambda expressions and default methods
58 * 9: modules, small cleanups to 1.7 and 1.8 changes
59 * 10: local-variable type inference (var)
60 * 11: local-variable syntax for lambda parameters
61 * 12: no changes (switch expressions in preview)
62 * 13: no changes (switch expressions and text blocks in preview)
63 * 14: switch expressions
64 */
65
66 /**
67 * The original version.
68 *
69 * The language described in
70 * <cite>The Java™ Language Specification, First Edition</cite>.
71 */
72 RELEASE_0,
73
74 /**
75 * The version recognized by the Java Platform 1.1.
76 *
77 * The language is {@code RELEASE_0} augmented with nested classes as described in the 1.1 update to
78 * <cite>The Java™ Language Specification, First Edition</cite>.
79 */
80 RELEASE_1,
81
82 /**
83 * The version recognized by the Java 2 Platform, Standard Edition,
186 * @since 12
187 */
188 RELEASE_12,
189
190 /**
191 * The version recognized by the Java Platform, Standard Edition
192 * 13.
193 *
194 * @since 13
195 */
196 RELEASE_13,
197
198 /**
199 * The version recognized by the Java Platform, Standard Edition
200 * 14.
201 *
202 * Additions in this release include switch expressions.
203 *
204 * @since 14
205 */
206 RELEASE_14;
207
208 // Note that when adding constants for newer releases, the
209 // behavior of latest() and latestSupported() must be updated too.
210
211 /**
212 * Returns the latest source version that can be modeled.
213 *
214 * @return the latest source version that can be modeled
215 */
216 public static SourceVersion latest() {
217 return RELEASE_14;
218 }
219
220 private static final SourceVersion latestSupported = getLatestSupported();
221
222 /*
223 * The integer version to enum constant mapping implemented by
224 * this method assumes the JEP 322: "Time-Based Release
225 * Versioning" scheme is in effect. This scheme began in JDK
226 * 10. If the JDK versioning scheme is revised, this method may
227 * need to be updated accordingly.
228 */
229 private static SourceVersion getLatestSupported() {
230 int intVersion = Runtime.version().feature();
231 return (intVersion >= 11) ?
232 valueOf("RELEASE_" + Math.min(14, intVersion)):
233 RELEASE_10;
234 }
235
236 /**
237 * Returns the latest source version fully supported by the
238 * current execution environment. {@code RELEASE_9} or later must
239 * be returned.
240 *
241 * @apiNote This method is included alongside {@link latest} to
242 * allow identification of situations where the language model API
243 * is running on a platform version different than the latest
244 * version modeled by the API. One way that sort of situation can
245 * occur is if an IDE or similar tool is using the API to model
246 * source version <i>N</i> while running on platform version
247 * (<i>N</i> - 1). Running in this configuration is
248 * supported by the API. Running an API on platform versions
249 * earlier than (<i>N</i> - 1) or later than <i>N</i>
250 * may or may not work as an implementation detail. If an
251 * annotation processor was generating code to run under the
252 * current execution environment, the processor should only use
|
44 * @author Peter von der Ahé
45 * @since 1.6
46 */
47 public enum SourceVersion {
48 /*
49 * Summary of language evolution
50 * 1.1: nested classes
51 * 1.2: strictfp
52 * 1.3: no changes
53 * 1.4: assert
54 * 1.5: annotations, generics, autoboxing, var-args...
55 * 1.6: no changes
56 * 1.7: diamond syntax, try-with-resources, etc.
57 * 1.8: lambda expressions and default methods
58 * 9: modules, small cleanups to 1.7 and 1.8 changes
59 * 10: local-variable type inference (var)
60 * 11: local-variable syntax for lambda parameters
61 * 12: no changes (switch expressions in preview)
62 * 13: no changes (switch expressions and text blocks in preview)
63 * 14: switch expressions
64 * 15: TBD
65 */
66
67 /**
68 * The original version.
69 *
70 * The language described in
71 * <cite>The Java™ Language Specification, First Edition</cite>.
72 */
73 RELEASE_0,
74
75 /**
76 * The version recognized by the Java Platform 1.1.
77 *
78 * The language is {@code RELEASE_0} augmented with nested classes as described in the 1.1 update to
79 * <cite>The Java™ Language Specification, First Edition</cite>.
80 */
81 RELEASE_1,
82
83 /**
84 * The version recognized by the Java 2 Platform, Standard Edition,
187 * @since 12
188 */
189 RELEASE_12,
190
191 /**
192 * The version recognized by the Java Platform, Standard Edition
193 * 13.
194 *
195 * @since 13
196 */
197 RELEASE_13,
198
199 /**
200 * The version recognized by the Java Platform, Standard Edition
201 * 14.
202 *
203 * Additions in this release include switch expressions.
204 *
205 * @since 14
206 */
207 RELEASE_14,
208
209 /**
210 * The version recognized by the Java Platform, Standard Edition
211 * 15.
212 *
213 * Additions in this release include switch expressions.
214 *
215 * @since 15
216 */
217 RELEASE_15;
218
219 // Note that when adding constants for newer releases, the
220 // behavior of latest() and latestSupported() must be updated too.
221
222 /**
223 * Returns the latest source version that can be modeled.
224 *
225 * @return the latest source version that can be modeled
226 */
227 public static SourceVersion latest() {
228 return RELEASE_15;
229 }
230
231 private static final SourceVersion latestSupported = getLatestSupported();
232
233 /*
234 * The integer version to enum constant mapping implemented by
235 * this method assumes the JEP 322: "Time-Based Release
236 * Versioning" scheme is in effect. This scheme began in JDK
237 * 10. If the JDK versioning scheme is revised, this method may
238 * need to be updated accordingly.
239 */
240 private static SourceVersion getLatestSupported() {
241 int intVersion = Runtime.version().feature();
242 return (intVersion >= 11) ?
243 valueOf("RELEASE_" + Math.min(15, intVersion)):
244 RELEASE_10;
245 }
246
247 /**
248 * Returns the latest source version fully supported by the
249 * current execution environment. {@code RELEASE_9} or later must
250 * be returned.
251 *
252 * @apiNote This method is included alongside {@link latest} to
253 * allow identification of situations where the language model API
254 * is running on a platform version different than the latest
255 * version modeled by the API. One way that sort of situation can
256 * occur is if an IDE or similar tool is using the API to model
257 * source version <i>N</i> while running on platform version
258 * (<i>N</i> - 1). Running in this configuration is
259 * supported by the API. Running an API on platform versions
260 * earlier than (<i>N</i> - 1) or later than <i>N</i>
261 * may or may not work as an implementation detail. If an
262 * annotation processor was generating code to run under the
263 * current execution environment, the processor should only use
|