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