< prev index next >

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

Print this page




  43  * @author Scott Seligman
  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 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&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,


 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>&nbsp;-&nbsp;1). Running in this configuration is
 248      * supported by the API. Running an API on platform versions
 249      * earlier than (<i>N</i>&nbsp;-&nbsp;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




  43  * @author Scott Seligman
  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 in preview)
  62      *  13: no changes (switch expressions and text blocks in preview)
  63      *  14: switch expressions (pattern matching and records in
  64      *      preview, text blocks in preview again)
  65      *  15: TBD
  66      */
  67 
  68     /**
  69      * The original version.
  70      *
  71      * The language described in
  72      * <cite>The Java&trade; Language Specification, First Edition</cite>.
  73      */
  74     RELEASE_0,
  75 
  76     /**
  77      * The version recognized by the Java Platform 1.1.
  78      *
  79      * The language is {@code RELEASE_0} augmented with nested classes as described in the 1.1 update to
  80      * <cite>The Java&trade; Language Specification, First Edition</cite>.
  81      */
  82     RELEASE_1,
  83 
  84     /**
  85      * The version recognized by the Java 2 Platform, Standard Edition,


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


< prev index next >