8233096: Update javax.lang.model for switch expressions
Reviewed-by: jjg, jlahoda
This commit is contained in:
parent
19bed24b1f
commit
c64756158f
@ -58,9 +58,9 @@ public enum SourceVersion {
|
|||||||
* 9: modules, small cleanups to 1.7 and 1.8 changes
|
* 9: modules, small cleanups to 1.7 and 1.8 changes
|
||||||
* 10: local-variable type inference (var)
|
* 10: local-variable type inference (var)
|
||||||
* 11: local-variable syntax for lambda parameters
|
* 11: local-variable syntax for lambda parameters
|
||||||
* 12: no changes (switch expressions were in preview)
|
* 12: no changes (switch expressions in preview)
|
||||||
* 13: no changes (switch expressions and text blocks in preview)
|
* 13: no changes (switch expressions and text blocks in preview)
|
||||||
* 14: TBD
|
* 14: switch expressions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,6 +199,8 @@ public enum SourceVersion {
|
|||||||
* The version recognized by the Java Platform, Standard Edition
|
* The version recognized by the Java Platform, Standard Edition
|
||||||
* 14.
|
* 14.
|
||||||
*
|
*
|
||||||
|
* Additions in this release include switch expressions.
|
||||||
|
*
|
||||||
* @since 14
|
* @since 14
|
||||||
*/
|
*/
|
||||||
RELEASE_14;
|
RELEASE_14;
|
||||||
|
@ -84,7 +84,7 @@ public enum Source {
|
|||||||
/** 1.11 local-variable syntax for lambda parameters */
|
/** 1.11 local-variable syntax for lambda parameters */
|
||||||
JDK11("11"),
|
JDK11("11"),
|
||||||
|
|
||||||
/** 12, no language features; switch expression were in preview */
|
/** 12, no language features; switch expression in preview */
|
||||||
JDK12("12"),
|
JDK12("12"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,8 +94,7 @@ public enum Source {
|
|||||||
JDK13("13"),
|
JDK13("13"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 14 covers the to be determined language features that will be
|
* 14, switch expressions
|
||||||
* added in JDK 14.
|
|
||||||
*/
|
*/
|
||||||
JDK14("14");
|
JDK14("14");
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 7025809 8028543 6415644 8028544 8029942 8187951 8193291 8196551
|
* @bug 7025809 8028543 6415644 8028544 8029942 8187951 8193291 8196551 8233096
|
||||||
* @summary Test latest, latestSupported, underscore as keyword, etc.
|
* @summary Test latest, latestSupported, underscore as keyword, etc.
|
||||||
* @author Joseph D. Darcy
|
* @author Joseph D. Darcy
|
||||||
* @modules java.compiler
|
* @modules java.compiler
|
||||||
@ -31,11 +31,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import javax.lang.model.SourceVersion;
|
import javax.lang.model.SourceVersion;
|
||||||
import static javax.lang.model.SourceVersion.*;
|
import static javax.lang.model.SourceVersion.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify latest[Supported] behavior.
|
* Verify behavior of latest[Supported] and other methods.
|
||||||
*/
|
*/
|
||||||
public class TestSourceVersion {
|
public class TestSourceVersion {
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
@ -43,6 +44,7 @@ public class TestSourceVersion {
|
|||||||
testVersionVaryingKeywords();
|
testVersionVaryingKeywords();
|
||||||
testRestrictedKeywords();
|
testRestrictedKeywords();
|
||||||
testVar();
|
testVar();
|
||||||
|
testYield();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testLatestSupported() {
|
private static void testLatestSupported() {
|
||||||
@ -52,8 +54,10 @@ public class TestSourceVersion {
|
|||||||
SourceVersion latestSupported = SourceVersion.latestSupported();
|
SourceVersion latestSupported = SourceVersion.latestSupported();
|
||||||
|
|
||||||
if (latest == last &&
|
if (latest == last &&
|
||||||
latestSupported == SourceVersion.valueOf("RELEASE_" + Runtime.version().feature()) &&
|
latestSupported == SourceVersion.valueOf("RELEASE_" +
|
||||||
(latest == latestSupported || (latest.ordinal() - latestSupported.ordinal() == 1)) )
|
Runtime.version().feature()) &&
|
||||||
|
(latest == latestSupported ||
|
||||||
|
(latest.ordinal() - latestSupported.ordinal() == 1)) )
|
||||||
return;
|
return;
|
||||||
else {
|
else {
|
||||||
throw new RuntimeException("Unexpected release value(s) found:\n" +
|
throw new RuntimeException("Unexpected release value(s) found:\n" +
|
||||||
@ -73,14 +77,14 @@ public class TestSourceVersion {
|
|||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
SourceVersion value = entry.getValue();
|
SourceVersion value = entry.getValue();
|
||||||
|
|
||||||
check(true, isKeyword(key), "keyword", latest());
|
check(true, key, (String s) -> isKeyword(s), "keyword", latest());
|
||||||
check(false, isName(key), "name", latest());
|
check(false, key, (String s) -> isName(s), "name", latest());
|
||||||
|
|
||||||
for(SourceVersion version : SourceVersion.values()) {
|
for(SourceVersion version : SourceVersion.values()) {
|
||||||
boolean isKeyword = version.compareTo(value) >= 0;
|
boolean isKeyword = version.compareTo(value) >= 0;
|
||||||
|
|
||||||
check(isKeyword, isKeyword(key, version), "keyword", version);
|
check(isKeyword, key, (String s) -> isKeyword(s, version), "keyword", version);
|
||||||
check(!isKeyword, isName(key, version), "name", version);
|
check(!isKeyword, key, (String s) -> isName(s, version), "name", version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,31 +102,47 @@ public class TestSourceVersion {
|
|||||||
Set.of("open", "module", "requires", "transitive", "exports",
|
Set.of("open", "module", "requires", "transitive", "exports",
|
||||||
"opens", "to", "uses", "provides", "with");
|
"opens", "to", "uses", "provides", "with");
|
||||||
|
|
||||||
for(String key : restrictedKeywords) {
|
for (String key : restrictedKeywords) {
|
||||||
for(SourceVersion version : SourceVersion.values()) {
|
for (SourceVersion version : SourceVersion.values()) {
|
||||||
check(false, isKeyword(key, version), "keyword", version);
|
check(false, key, (String s) -> isKeyword(s, version), "keyword", version);
|
||||||
check(true, isName(key, version), "name", version);
|
check(true, key, (String s) -> isName(s, version), "name", version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testVar() {
|
private static void testVar() {
|
||||||
|
for (SourceVersion version : SourceVersion.values()) {
|
||||||
|
Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
|
||||||
|
Predicate<String> isNameVersion = (String s) -> isName(s, version);
|
||||||
|
|
||||||
for(SourceVersion version : SourceVersion.values()) {
|
for (String name : List.of("var", "foo.var", "var.foo")) {
|
||||||
check(false, isKeyword("var", version), "keyword", version);
|
check(false, name, isKeywordVersion, "keyword", version);
|
||||||
check(false, isKeyword("foo.var", version), "keyword", version);
|
check(true, name, isNameVersion, "name", 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,
|
private static void testYield() {
|
||||||
String message, SourceVersion version) {
|
for (SourceVersion version : SourceVersion.values()) {
|
||||||
|
Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
|
||||||
|
Predicate<String> isNameVersion = (String s) -> isName(s, version);
|
||||||
|
|
||||||
|
for (String name : List.of("yield", "foo.yield", "yield.foo")) {
|
||||||
|
check(false, name, isKeywordVersion, "keyword", version);
|
||||||
|
check(true, name, isNameVersion, "name", version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void check(boolean expected,
|
||||||
|
String input,
|
||||||
|
Predicate<String> predicate,
|
||||||
|
String message,
|
||||||
|
SourceVersion version) {
|
||||||
|
boolean result = predicate.test(input);
|
||||||
if (result != expected) {
|
if (result != expected) {
|
||||||
throw new RuntimeException("Unexpected " + message + "-ness of _ on " + version);
|
throw new RuntimeException("Unexpected " + message + "-ness of " + input +
|
||||||
|
" on " + version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user