changeset 48418:239c7d9bb192

8187951: Update javax.lang.model.SourceVersion for "var" name Reviewed-by: jjg, mcimadamore
author darcy
date Mon, 08 Jan 2018 17:32:54 -0800
parents c94c352dc400
children 899a137688b8 97db4ee6e59a
files src/java.compiler/share/classes/javax/lang/model/SourceVersion.java test/langtools/tools/javac/processing/model/TestSourceVersion.java
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java	Mon Jan 08 14:06:25 2018 -0500
+++ b/src/java.compiler/share/classes/javax/lang/model/SourceVersion.java	Mon Jan 08 17:32:54 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -219,8 +219,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
@@ -254,8 +255,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
@@ -272,8 +274,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
@@ -297,7 +300,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
@@ -314,7 +317,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
--- a/test/langtools/tools/javac/processing/model/TestSourceVersion.java	Mon Jan 08 14:06:25 2018 -0500
+++ b/test/langtools/tools/javac/processing/model/TestSourceVersion.java	Mon Jan 08 17:32:54 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 7025809 8028543 6415644 8028544 8029942
+ * @bug 7025809 8028543 6415644 8028544 8029942 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,19 @@
         }
     }
 
+    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);
+
+            check(true, isName("var", version),     "name", version);
+            check(true, 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) {