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

Reviewed-by: jjg, mcimadamore
This commit is contained in:
Joe Darcy 2018-01-08 17:32:54 -08:00
parent a316ab9ef3
commit edd2c3b6ca
2 changed files with 26 additions and 9 deletions

View File

@ -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 @@ public enum SourceVersion {
* 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 @@ public enum SourceVersion {
* 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 @@ public enum SourceVersion {
* 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 @@ public enum SourceVersion {
* 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 @@ public enum SourceVersion {
* 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

View File

@ -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 @@ public class TestSourceVersion {
testLatestSupported();
testVersionVaryingKeywords();
testRestrictedKeywords();
testVar();
}
private static void testLatestSupported() {
@ -96,6 +97,19 @@ public class TestSourceVersion {
}
}
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) {