Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8194523

Update javax.lang.model.SourceVersion for "var" name

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 10
    • core-libs
    • None
    • minimal
    • Java API
    • SE

      Summary

      The specifications of the name-related predicates in SourceVersion are updated to explicitly describe their handling of the string "var".

      Problem

      Local-variable type inference adds special handling to the name "var" in some contexts and SourceVersion should be updated accordingly.

      Solution

      Treat "var" similarly to restricted keywords, that is, without any complicated checking. Fully precise determination of whether or not "var" can be used as a name requires both version-dependent and context-dependent checking.

      Specification

      public static boolean isIdentifier(CharSequence name):

      --- old/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java 2018-01-02 19:10:45.130122929 -0800
      +++ new/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java 2018-01-02 19:10:44.806122915 -0800
      @@ -230,8 +230,9 @@
            * followed only by characters for which {@link
            * Character#isJavaIdentifierPart(int)} returns {@code true}.
            * This pattern matches regular identifiers, keywords, restricted
      -     * keywords, and the literals {@code "true"}, {@code "false"}, and
      -     * {@code "null"}.
      +     * keywords, and the literals {@code "true"}, {@code "false"},
      +     * {@code "null"}, and {@code "var"}.
      +     *
            * The method returns {@code false} for all other strings.
            *
            * @param name the string to check

      public static boolean isName(CharSequence name):

      @@ -265,8 +266,9 @@
            * qualified name in the latest source version.  Unlike {@link
            * #isIdentifier isIdentifier}, this method returns {@code false}
            * for keywords, boolean literals, and the null literal.
      +     *
            * This method returns {@code true} for <i>restricted
      -     * keywords</i>.
      +     * keywords</i> and {@code "var"}.
            *
            * @param name the string to check
            * @return {@code true} if this string is a

      public static boolean isName(CharSequence name, SourceVersion version):

      @@ -283,8 +285,9 @@
            * qualified name in the given source version.  Unlike {@link
            * #isIdentifier isIdentifier}, this method returns {@code false}
            * for keywords, boolean literals, and the null literal.
      +     *
            * This method returns {@code true} for <i>restricted
      -     * keywords</i>.
      +     * keywords</i> and {@code "var"}.
            *
            * @param name the string to check
            * @param version the version to use

      public static boolean isKeyword(CharSequence s):

      @@ -308,7 +311,7 @@
            * Returns whether or not {@code s} is a keyword, boolean literal,
            * or null literal in the latest source version.
            * This method returns {@code false} for <i>restricted
      -     * keywords</i>.
      +     * keywords</i> and {@code "var"}.
            *
            * @param s the string to check
            * @return {@code true} if {@code s} is a keyword, or boolean

      public static boolean isKeyword(CharSequence s, SourceVersion version):

      @@ -325,7 +328,7 @@
            * Returns whether or not {@code s} is a keyword, boolean literal,
            * or null literal in the given source version.
            * This method returns {@code false} for <i>restricted
      -     * keywords</i>.
      +     * keywords</i> and {@code "var"}.
            *
            * @param s the string to check
            * @param version the version to use

            darcy Joe Darcy
            darcy Joe Darcy
            Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: