author | darcy |
Mon, 08 Jan 2018 17:32:54 -0800 | |
changeset 48499 | 239c7d9bb192 |
parent 47283 | ce5fd3ba3fea |
child 48538 | 82c3d4173a53 |
permissions | -rw-r--r-- |
10181 | 1 |
/* |
48499
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
2 |
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
10181 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
48499
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
26 |
* @bug 7025809 8028543 6415644 8028544 8029942 8187951 |
38534
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
27 |
* @summary Test latest, latestSupported, underscore as keyword, etc. |
10181 | 28 |
* @author Joseph D. Darcy |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22169
diff
changeset
|
29 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
22169
diff
changeset
|
30 |
* jdk.compiler |
10181 | 31 |
*/ |
32 |
||
38534
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
33 |
import java.util.*; |
10181 | 34 |
import javax.lang.model.SourceVersion; |
35 |
import static javax.lang.model.SourceVersion.*; |
|
36 |
||
37 |
/** |
|
38 |
* Verify latest[Supported] behavior. |
|
39 |
*/ |
|
40 |
public class TestSourceVersion { |
|
41 |
public static void main(String... args) { |
|
38534
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
42 |
testLatestSupported(); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
43 |
testVersionVaryingKeywords(); |
47283
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
44 |
testRestrictedKeywords(); |
48499
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
45 |
testVar(); |
38534
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
46 |
} |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
47 |
|
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
48 |
private static void testLatestSupported() { |
43646 | 49 |
if (SourceVersion.latest() != RELEASE_10 || |
43647
d21da31c6c0a
8173383: Update JDK build to use -source and -target 10
darcy
parents:
43646
diff
changeset
|
50 |
SourceVersion.latestSupported() != RELEASE_10) |
10181 | 51 |
throw new RuntimeException("Unexpected release value(s) found:\n" + |
52 |
"latest:\t" + SourceVersion.latest() + "\n" + |
|
53 |
"latestSupported:\t" + SourceVersion.latestSupported()); |
|
54 |
} |
|
38534
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
55 |
|
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
56 |
private static void testVersionVaryingKeywords() { |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
57 |
Map<String, SourceVersion> keyWordStart = |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
58 |
Map.of("strictfp", RELEASE_2, |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
59 |
"assert", RELEASE_4, |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
60 |
"enum", RELEASE_5, |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
61 |
"_", RELEASE_9); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
62 |
|
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
63 |
for (Map.Entry<String, SourceVersion> entry : keyWordStart.entrySet()) { |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
64 |
String key = entry.getKey(); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
65 |
SourceVersion value = entry.getValue(); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
66 |
|
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
67 |
check(true, isKeyword(key), "keyword", latest()); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
68 |
check(false, isName(key), "name", latest()); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
69 |
|
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
70 |
for(SourceVersion version : SourceVersion.values()) { |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
71 |
boolean isKeyword = version.compareTo(value) >= 0; |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
72 |
|
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
73 |
check(isKeyword, isKeyword(key, version), "keyword", version); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
74 |
check(!isKeyword, isName(key, version), "name", version); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
75 |
} |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
76 |
} |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
77 |
} |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
78 |
|
47283
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
79 |
private static void testRestrictedKeywords() { |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
80 |
// Restricted keywords are not full keywords |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
81 |
|
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
82 |
/* |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
83 |
* JLS 3.9 |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
84 |
* " A further ten character sequences are restricted |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
85 |
* keywords: open, module, requires, transitive, exports, |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
86 |
* opens, to, uses, provides, and with" |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
87 |
*/ |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
88 |
Set<String> restrictedKeywords = |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
89 |
Set.of("open", "module", "requires", "transitive", "exports", |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
90 |
"opens", "to", "uses", "provides", "with"); |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
91 |
|
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
92 |
for(String key : restrictedKeywords) { |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
93 |
for(SourceVersion version : SourceVersion.values()) { |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
94 |
check(false, isKeyword(key, version), "keyword", version); |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
95 |
check(true, isName(key, version), "name", version); |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
96 |
} |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
97 |
} |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
98 |
} |
ce5fd3ba3fea
8187982: Update SourceVersion to mention restricted keywords
darcy
parents:
47216
diff
changeset
|
99 |
|
48499
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
100 |
private static void testVar() { |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
101 |
|
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
102 |
for(SourceVersion version : SourceVersion.values()) { |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
103 |
check(false, isKeyword("var", version), "keyword", version); |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
104 |
check(false, isKeyword("foo.var", version), "keyword", version); |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
105 |
check(false, isKeyword("var.foo", version), "keyword", version); |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
106 |
|
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
107 |
check(true, isName("var", version), "name", version); |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
108 |
check(true, isName("foo.var", version), "name", version); |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
109 |
check(true, isName("var.foo", version), "name", version); |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
110 |
} |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
111 |
} |
239c7d9bb192
8187951: Update javax.lang.model.SourceVersion for "var" name
darcy
parents:
47283
diff
changeset
|
112 |
|
38534
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
113 |
private static void check(boolean result, boolean expected, |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
114 |
String message, SourceVersion version) { |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
115 |
if (result != expected) { |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
116 |
throw new RuntimeException("Unexpected " + message + "-ness of _ on " + version); |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
117 |
} |
425b30506f80
6415644: Make javax.lang.model.SourceVersion more informative
darcy
parents:
30730
diff
changeset
|
118 |
} |
10181 | 119 |
} |