< prev index next >

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

Print this page

        

@@ -155,10 +155,13 @@
 
     /**
      * The version recognized by the Java Platform, Standard Edition
      * 10.
      *
+     * Additions in this release include local variable type
+     * inference, {@code "var"}.
+     *
      * @since 10
      */
      RELEASE_10;
 
     // Note that when adding constants for newer releases, the

@@ -215,12 +218,13 @@
      * of an initial character for which {@link
      * Character#isJavaIdentifierStart(int)} returns {@code true},
      * 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
      * @return {@code true} if this string is a
      * syntactically valid identifier or keyword, {@code false}

@@ -250,10 +254,11 @@
     /**
      * Returns whether or not {@code name} is a syntactically valid
      * 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>.
      *
      * @param name the string to check
      * @return {@code true} if this string is a

@@ -268,13 +273,19 @@
     /**
      * Returns whether or not {@code name} is a syntactically valid
      * 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>.
      *
+     * This method returns {@code false} if {@code "var"} is a
+     * trailing simple name component of the qualified name argument
+     * and {@code "var"} is used for local variable type inference in
+     * the argument version.
+     *
      * @param name the string to check
      * @param version the version to use
      * @return {@code true} if this string is a
      * syntactically valid name, {@code false} otherwise.
      * @jls 3.9 Keywords

@@ -282,22 +293,28 @@
      * @since 9
      */
     public static boolean isName(CharSequence name, SourceVersion version) {
         String id = name.toString();
 
-        for(String s : id.split("\\.", -1)) {
+        String[] splits = id.split("\\.", -1);
+        for(String s : splits) {
             if (!isIdentifier(s) || isKeyword(s, version))
                 return false;
         }
+        // The name "var" cannot be used for a type as of release 10.
+        if (version.compareTo(RELEASE_10) >= 0 &&
+            splits[splits.length - 1].equals("var") ) {
+            return false;
+        }
         return true;
     }
 
     /**
      * 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
      * literal, or null literal, {@code false} otherwise.
      * @jls 3.9 Keywords

@@ -310,11 +327,11 @@
 
     /**
      * 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
      * @return {@code true} if {@code s} is a keyword, or boolean
      * literal, or null literal, {@code false} otherwise.
< prev index next >