86
87 check(isKeyword, key, (String s) -> isKeyword(s, version), "keyword", version);
88 check(!isKeyword, key, (String s) -> isName(s, version), "name", version);
89 }
90 }
91 }
92
93 private static void testRestrictedKeywords() {
94 // Restricted keywords are not full keywords
95
96 /*
97 * JLS 3.9
98 * " A further ten character sequences are restricted
99 * keywords: open, module, requires, transitive, exports,
100 * opens, to, uses, provides, and with"
101 */
102 Set<String> restrictedKeywords =
103 Set.of("open", "module", "requires", "transitive", "exports",
104 "opens", "to", "uses", "provides", "with",
105 // Assume "record" and "sealed" will be restricted keywords.
106 "record", "sealed");
107
108 for (String key : restrictedKeywords) {
109 for (SourceVersion version : SourceVersion.values()) {
110 check(false, key, (String s) -> isKeyword(s, version), "keyword", version);
111 check(true, key, (String s) -> isName(s, version), "name", version);
112 }
113 }
114 }
115
116 private static void testVar() {
117 for (SourceVersion version : SourceVersion.values()) {
118 Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
119 Predicate<String> isNameVersion = (String s) -> isName(s, version);
120
121 for (String name : List.of("var", "foo.var", "var.foo")) {
122 check(false, name, isKeywordVersion, "keyword", version);
123 check(true, name, isNameVersion, "name", version);
124 }
125 }
126 }
127
128 private static void testYield() {
129 for (SourceVersion version : SourceVersion.values()) {
130 Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
131 Predicate<String> isNameVersion = (String s) -> isName(s, version);
132
133 for (String name : List.of("yield", "foo.yield", "yield.foo")) {
134 check(false, name, isKeywordVersion, "keyword", version);
135 check(true, name, isNameVersion, "name", version);
136 }
137 }
138 }
139
140 private static void check(boolean expected,
141 String input,
142 Predicate<String> predicate,
143 String message,
144 SourceVersion version) {
145 boolean result = predicate.test(input);
146 if (result != expected) {
147 throw new RuntimeException("Unexpected " + message + "-ness of " + input +
148 " on " + version);
149 }
150 }
151
152 /**
153 * Test that SourceVersion.valueOf() maps a Runtime.Version to a
154 * SourceVersion properly. The SourceVersion result is only a
|
86
87 check(isKeyword, key, (String s) -> isKeyword(s, version), "keyword", version);
88 check(!isKeyword, key, (String s) -> isName(s, version), "name", version);
89 }
90 }
91 }
92
93 private static void testRestrictedKeywords() {
94 // Restricted keywords are not full keywords
95
96 /*
97 * JLS 3.9
98 * " A further ten character sequences are restricted
99 * keywords: open, module, requires, transitive, exports,
100 * opens, to, uses, provides, and with"
101 */
102 Set<String> restrictedKeywords =
103 Set.of("open", "module", "requires", "transitive", "exports",
104 "opens", "to", "uses", "provides", "with",
105 // Assume "record" and "sealed" will be restricted keywords.
106 "record", "sealed", "value");
107
108 for (String key : restrictedKeywords) {
109 for (SourceVersion version : SourceVersion.values()) {
110 check(false, key, (String s) -> isKeyword(s, version), "keyword", version);
111 check(true, key, (String s) -> isName(s, version), "name", version);
112 }
113 }
114 }
115
116 private static void testVar() {
117 for (SourceVersion version : SourceVersion.values()) {
118 Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
119 Predicate<String> isNameVersion = (String s) -> isName(s, version);
120
121 for (String name : List.of("var", "foo.var", "var.foo")) {
122 check(false, name, isKeywordVersion, "keyword", version);
123 check(true, name, isNameVersion, "name", version);
124 }
125 }
126 }
127
128 private static void testYield() {
129 for (SourceVersion version : SourceVersion.values()) {
130 Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
131 Predicate<String> isNameVersion = (String s) -> isName(s, version);
132
133 for (String name : List.of("yield", "foo.yield", "yield.foo")) {
134 check(false, name, isKeywordVersion, "keyword", version);
135 check(true, name, isNameVersion, "name", version);
136 }
137 }
138 }
139
140 private static void testValue() {
141 for (SourceVersion version : SourceVersion.values()) {
142 Predicate<String> isKeywordVersion = (String s) -> isKeyword(s, version);
143 Predicate<String> isNameVersion = (String s) -> isName(s, version);
144
145 for (String name : List.of("value", "foo.value", "value.foo")) {
146 check(false, name, isKeywordVersion, "keyword", version);
147 check(true, name, isNameVersion, "name", version);
148 }
149 }
150 }
151
152 private static void check(boolean expected,
153 String input,
154 Predicate<String> predicate,
155 String message,
156 SourceVersion version) {
157 boolean result = predicate.test(input);
158 if (result != expected) {
159 throw new RuntimeException("Unexpected " + message + "-ness of " + input +
160 " on " + version);
161 }
162 }
163
164 /**
165 * Test that SourceVersion.valueOf() maps a Runtime.Version to a
166 * SourceVersion properly. The SourceVersion result is only a
|