< prev index next >

src/java.compiler/share/classes/javax/lang/model/SourceVersion.java

Print this page




  44  * @author Peter von der Ah&eacute;
  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 were in preview)
  62      *  13: no changes (switch expressions and text blocks in preview)
  63      *  14: TBD

  64      */
  65 
  66     /**
  67      * The original version.
  68      *
  69      * The language described in
  70      * <cite>The Java&trade; 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&trade; Language Specification, First Edition</cite>.
  79      */
  80     RELEASE_1,
  81 
  82     /**
  83      * The version recognized by the Java 2 Platform, Standard Edition,


 184      * 12.
 185      *
 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      * @since 14
 203      */
 204      RELEASE_14;








 205 
 206     // Note that when adding constants for newer releases, the
 207     // behavior of latest() and latestSupported() must be updated too.
 208 
 209     /**
 210      * Returns the latest source version that can be modeled.
 211      *
 212      * @return the latest source version that can be modeled
 213      */
 214     public static SourceVersion latest() {
 215         return RELEASE_14;
 216     }
 217 
 218     private static final SourceVersion latestSupported = getLatestSupported();
 219 
 220     /*
 221      * The integer version to enum constant mapping implemented by
 222      * this method assumes the JEP 322: "Time-Based Release
 223      * Versioning" scheme is in effect. This scheme began in JDK
 224      * 10. If the JDK versioning scheme is revised, this method may
 225      * need to be updated accordingly.
 226      */
 227     private static SourceVersion getLatestSupported() {
 228         int intVersion = Runtime.version().feature();
 229         return (intVersion >= 11) ?
 230             valueOf("RELEASE_" + Math.min(14, intVersion)):
 231             RELEASE_10;
 232     }
 233 
 234     /**
 235      * Returns the latest source version fully supported by the
 236      * current execution environment.  {@code RELEASE_9} or later must
 237      * be returned.
 238      *
 239      * @apiNote This method is included alongside {@link latest} to
 240      * allow identification of situations where the language model API
 241      * is running on a platform version different than the latest
 242      * version modeled by the API. One way that sort of situation can
 243      * occur is if an IDE or similar tool is using the API to model
 244      * source version <i>N</i> while running on platform version
 245      * (<i>N</i>&nbsp;-&nbsp;1). Running in this configuration is
 246      * supported by the API. Running an API on platform versions
 247      * earlier than (<i>N</i>&nbsp;-&nbsp;1) or later than <i>N</i>
 248      * may or may not work as an implementation detail. If an
 249      * annotation processor was generating code to run under the
 250      * current execution environment, the processor should only use




  44  * @author Peter von der Ah&eacute;
  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 were in preview)
  62      *  13: no changes (switch expressions and text blocks in preview)
  63      *  14: TBD
  64      *  15: TBD
  65      */
  66 
  67     /**
  68      * The original version.
  69      *
  70      * The language described in
  71      * <cite>The Java&trade; 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&trade; Language Specification, First Edition</cite>.
  80      */
  81     RELEASE_1,
  82 
  83     /**
  84      * The version recognized by the Java 2 Platform, Standard Edition,


 185      * 12.
 186      *
 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      * @since 14
 204      */
 205     RELEASE_14,
 206 
 207     /**
 208      * The version recognized by the Java Platform, Standard Edition
 209      * 15.
 210      *
 211      * @since 15
 212      */
 213      RELEASE_15;
 214 
 215     // Note that when adding constants for newer releases, the
 216     // behavior of latest() and latestSupported() must be updated too.
 217 
 218     /**
 219      * Returns the latest source version that can be modeled.
 220      *
 221      * @return the latest source version that can be modeled
 222      */
 223     public static SourceVersion latest() {
 224         return RELEASE_15;
 225     }
 226 
 227     private static final SourceVersion latestSupported = getLatestSupported();
 228 
 229     /*
 230      * The integer version to enum constant mapping implemented by
 231      * this method assumes the JEP 322: "Time-Based Release
 232      * Versioning" scheme is in effect. This scheme began in JDK
 233      * 10. If the JDK versioning scheme is revised, this method may
 234      * need to be updated accordingly.
 235      */
 236     private static SourceVersion getLatestSupported() {
 237         int intVersion = Runtime.version().feature();
 238         return (intVersion >= 11) ?
 239             valueOf("RELEASE_" + Math.min(15, intVersion)):
 240             RELEASE_10;
 241     }
 242 
 243     /**
 244      * Returns the latest source version fully supported by the
 245      * current execution environment.  {@code RELEASE_9} or later must
 246      * be returned.
 247      *
 248      * @apiNote This method is included alongside {@link latest} to
 249      * allow identification of situations where the language model API
 250      * is running on a platform version different than the latest
 251      * version modeled by the API. One way that sort of situation can
 252      * occur is if an IDE or similar tool is using the API to model
 253      * source version <i>N</i> while running on platform version
 254      * (<i>N</i>&nbsp;-&nbsp;1). Running in this configuration is
 255      * supported by the API. Running an API on platform versions
 256      * earlier than (<i>N</i>&nbsp;-&nbsp;1) or later than <i>N</i>
 257      * may or may not work as an implementation detail. If an
 258      * annotation processor was generating code to run under the
 259      * current execution environment, the processor should only use


< prev index next >