--- old/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java 2017-09-27 15:46:12.163959448 -0700 +++ new/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java 2017-09-27 15:46:11.847959437 -0700 @@ -157,6 +157,9 @@ * 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; @@ -217,8 +220,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 @@ -252,6 +256,7 @@ * 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 restricted * keywords. * @@ -270,9 +275,15 @@ * 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 restricted * keywords. * + * 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 @@ -284,10 +295,16 @@ 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; } @@ -295,7 +312,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 restricted - * keywords. + * keywords and {@code var}. * * @param s the string to check * @return {@code true} if {@code s} is a keyword, or boolean @@ -312,7 +329,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 restricted - * keywords. + * keywords and {@code var}. * * @param s the string to check * @param version the version to use