Enum Class SourceVersion

java.lang.Object
java.lang.Enum<SourceVersion>
javax.lang.model.SourceVersion
All Implemented Interfaces:
Serializable, Comparable<SourceVersion>, Constable

public enum SourceVersion extends Enum<SourceVersion>
Source versions of the Java programming language. See the appropriate edition of The Java Language Specification for information about a particular source version.

Note that additional source version constants will be added to model future releases of the language.

Since:
1.6
See Also:
  • Nested Class Summary

    Nested classes/interfaces declared in class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    The original version.
    The version recognized by the Java Platform 1.1.
    The version recognized by the Java Platform, Standard Edition 10.
    The version recognized by the Java Platform, Standard Edition 11.
    The version recognized by the Java Platform, Standard Edition 12.
    The version recognized by the Java Platform, Standard Edition 13.
    The version recognized by the Java Platform, Standard Edition 14.
    The version recognized by the Java Platform, Standard Edition 15.
    The version recognized by the Java Platform, Standard Edition 16.
    The version recognized by the Java Platform, Standard Edition 17.
    The version recognized by the Java Platform, Standard Edition 18.
    The version recognized by the Java Platform, Standard Edition 19.
    The version recognized by the Java 2 Platform, Standard Edition, v 1.2.
    The version recognized by the Java Platform, Standard Edition 20.
    The version recognized by the Java 2 Platform, Standard Edition, v 1.3.
    The version recognized by the Java 2 Platform, Standard Edition, v 1.4.
    The version recognized by the Java 2 Platform, Standard Edition 5.0.
    The version recognized by the Java Platform, Standard Edition 6.
    The version recognized by the Java Platform, Standard Edition 7.
    The version recognized by the Java Platform, Standard Edition 8.
    The version recognized by the Java Platform, Standard Edition 9.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Returns whether or not name is a syntactically valid identifier (simple name) or keyword in the latest source version.
    static boolean
    Returns whether or not s is a keyword, boolean literal, or null literal in the latest source version.
    static boolean
    Returns whether or not s is a keyword, boolean literal, or null literal in the given source version.
    static boolean
    Returns whether or not name is a syntactically valid qualified name in the latest source version.
    static boolean
    Returns whether or not name is a syntactically valid qualified name in the given source version.
    Returns the latest source version that can be modeled.
    Returns the latest source version fully supported by the current execution environment.
    Returns the least runtime version that supports this source version; otherwise null.
    Returns the latest source version that is usable under the runtime version argument.
    Returns the enum constant of this class with the specified name.
    static SourceVersion[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods declared in class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

  • Method Details

    • values

      public static SourceVersion[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SourceVersion valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • latest

      public static SourceVersion latest()
      Returns the latest source version that can be modeled.
      Returns:
      the latest source version that can be modeled
    • latestSupported

      public static SourceVersion latestSupported()
      Returns the latest source version fully supported by the current execution environment. RELEASE_9 or later must be returned.
      API Note:
      This method is included alongside latest() to allow identification of situations where the language model API is running on a platform version different than the latest version modeled by the API. One way that sort of situation can occur is if an IDE or similar tool is using the API to model source version N while running on platform version (N - 1). Running in this configuration is supported by the API. Running an API on platform versions earlier than (N - 1) or later than N may or may not work as an implementation detail. If an annotation processor was generating code to run under the current execution environment, the processor should only use platform features up to the latestSupported release, which may be earlier than the latest release.
      Returns:
      the latest source version fully supported by the current execution environment
    • isIdentifier

      public static boolean isIdentifier(CharSequence name)
      Returns whether or not name is a syntactically valid identifier (simple name) or keyword in the latest source version. The method returns true if the name consists of an initial character for which Character.isJavaIdentifierStart(int) returns true, followed only by characters for which Character.isJavaIdentifierPart(int) returns true. This pattern matches regular identifiers, keywords, contextual keywords, and the literals "true", "false", "null". The method returns false for all other strings.
      Parameters:
      name - the string to check
      Returns:
      true if this string is a syntactically valid identifier or keyword, false otherwise.
      See Java Language Specification:
      3.8 Identifiers
    • isName

      public static boolean isName(CharSequence name)
      Returns whether or not name is a syntactically valid qualified name in the latest source version. Syntactically, a qualified name is a sequence of identifiers separated by period characters ("."). This method splits the input string into period-separated segments and applies checks to each segment in turn. Unlike isIdentifier, this method returns false for keywords, boolean literals, and the null literal in any segment. This method returns true for contextual keywords.
      Parameters:
      name - the string to check
      Returns:
      true if this string is a syntactically valid name, false otherwise.
      See Java Language Specification:
      3.9 Keywords
      6.2 Names and Identifiers
    • isName

      public static boolean isName(CharSequence name, SourceVersion version)
      Returns whether or not name is a syntactically valid qualified name in the given source version. Syntactically, a qualified name is a sequence of identifiers separated by period characters ("."). This method splits the input string into period-separated segments and applies checks to each segment in turn. Unlike isIdentifier, this method returns false for keywords, boolean literals, and the null literal in any segment. This method returns true for contextual keywords.
      Parameters:
      name - the string to check
      version - the version to use
      Returns:
      true if this string is a syntactically valid name, false otherwise.
      See Java Language Specification:
      3.9 Keywords
      6.2 Names and Identifiers
      Since:
      9
    • isKeyword

      public static boolean isKeyword(CharSequence s)
      Returns whether or not s is a keyword, boolean literal, or null literal in the latest source version. This method returns false for contextual keywords.
      Parameters:
      s - the string to check
      Returns:
      true if s is a keyword, or boolean literal, or null literal, false otherwise.
      See Java Language Specification:
      3.9 Keywords
      3.10.3 Boolean Literals
      3.10.8 The Null Literal
    • isKeyword

      public static boolean isKeyword(CharSequence s, SourceVersion version)
      Returns whether or not s is a keyword, boolean literal, or null literal in the given source version. This method returns false for contextual keywords.
      Parameters:
      s - the string to check
      version - the version to use
      Returns:
      true if s is a keyword, or boolean literal, or null literal, false otherwise.
      See Java Language Specification:
      3.9 Keywords
      3.10.3 Boolean Literals
      3.10.8 The Null Literal
      Since:
      9
    • valueOf

      public static SourceVersion valueOf(Runtime.Version rv)
      Returns the latest source version that is usable under the runtime version argument. If the runtime version's feature is greater than the feature of the runtime version of the latest source version, an IllegalArgumentException is thrown.

      Because the source versions of the Java programming language have so far followed a linear progression, only the feature component of a runtime version is queried to determine the mapping to a source version. If that linearity changes in the future, other components of the runtime version may influence the result.

      API Note:
      An expression to convert from a string value, for example "17", to the corresponding source version, RELEASE_17, is:
      SourceVersion.valueOf(Runtime.Version.parse("17"))
      Parameters:
      rv - runtime version to map to a source version
      Returns:
      the latest source version that is usable under the runtime version argument
      Throws:
      IllegalArgumentException - if the feature of version argument is greater than the feature of the platform version.
      Since:
      18
    • runtimeVersion

      public Runtime.Version runtimeVersion()
      Returns the least runtime version that supports this source version; otherwise null. The returned runtime version has a feature large enough to support this source version and has no other elements set. Source versions greater than or equal to RELEASE_6 have non-null results.
      Returns:
      the least runtime version that supports this source version; otherwise null
      Since:
      18