--- 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
--- old/test/langtools/tools/javac/processing/model/TestSourceVersion.java 2017-09-27 15:46:12.811959472 -0700
+++ new/test/langtools/tools/javac/processing/model/TestSourceVersion.java 2017-09-27 15:46:12.483959460 -0700
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 7025809 8028543 6415644 8028544 8029942
+ * @bug 7025809 8028543 6415644 8028544 8029942 8187982 8187951
* @summary Test latest, latestSupported, underscore as keyword, etc.
* @author Joseph D. Darcy
* @modules java.compiler
@@ -42,6 +42,7 @@
testLatestSupported();
testVersionVaryingKeywords();
testRestrictedKeywords();
+ testVar();
}
private static void testLatestSupported() {
@@ -96,6 +97,21 @@
}
}
+ private static void testVar() {
+
+ for(SourceVersion version : SourceVersion.values()) {
+ check(false, isKeyword("var", version), "keyword", version);
+ check(false, isKeyword("foo.var", version), "keyword", version);
+ check(false, isKeyword("var.foo", version), "keyword", version);
+
+ // The string "var" doesn't have special handling until release 10.
+ boolean lessThan10 = version.compareTo(RELEASE_10) < 0;
+ check(lessThan10, isName("var", version), "name", version);
+ check(lessThan10, isName("foo.var", version), "name", version);
+ check(true, isName("var.foo", version), "name", version);
+ }
+ }
+
private static void check(boolean result, boolean expected,
String message, SourceVersion version) {
if (result != expected) {