137
138 /* simplest annotation processor just to force a round of annotation processing for all tests
139 */
140 @SupportedAnnotationTypes("*")
141 public static class SimplestAP extends AbstractProcessor {
142 @Override
143 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
144 return true;
145 }
146 }
147
148 public RecordCompilationTests() {
149 boolean useAP = System.getProperty("useAP") == null ? false : System.getProperty("useAP").equals("true");
150 setDefaultFilename("R.java");
151 setCompileOptions(useAP ? PREVIEW_OPTIONS_WITH_AP : PREVIEW_OPTIONS);
152 System.out.println(useAP ? "running all tests using an annotation processor" : "running all tests without annotation processor");
153 }
154
155 public void testMalformedDeclarations() {
156 assertFail("compiler.err.premature.eof", "record R()");
157 assertFail("compiler.err.premature.eof", "record R();");
158 assertFail("compiler.err.illegal.start.of.type", "record R(,) { }");
159 assertFail("compiler.err.illegal.start.of.type", "record R((int x)) { }");
160 assertFail("compiler.err.record.header.expected", "record R { }");
161 assertFail("compiler.err.expected", "record R(foo) { }");
162 assertFail("compiler.err.expected", "record R(int int) { }");
163 assertFail("compiler.err.mod.not.allowed.here", "abstract record R(String foo) { }");
164 //assertFail("compiler.err.illegal.combination.of.modifiers", "non-sealed record R(String foo) { }");
165 assertFail("compiler.err.repeated.modifier", "public public record R(String foo) { }");
166 assertFail("compiler.err.repeated.modifier", "private private record R(String foo) { }");
167 assertFail("compiler.err.already.defined", "record R(int x, int x) {}");
168 for (String s : List.of("var", "record"))
169 assertFail("compiler.err.restricted.type.not.allowed.here", "record R(# x) { }", s);
170 for (String s : List.of("public", "protected", "private", "static", "final", "transient", "volatile",
171 "abstract", "synchronized", "native", "strictfp")) // missing: sealed and non-sealed
172 assertFail("compiler.err.record.cant.declare.field.modifiers", "record R(# String foo) { }", s);
173 assertFail("compiler.err.varargs.must.be.last", "record R(int... x, int... y) {}");
174 assertFail("compiler.err.instance.initializer.not.allowed.in.records", "record R(int i) { {} }");
175 }
176
177 public void testGoodDeclarations() {
|
137
138 /* simplest annotation processor just to force a round of annotation processing for all tests
139 */
140 @SupportedAnnotationTypes("*")
141 public static class SimplestAP extends AbstractProcessor {
142 @Override
143 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
144 return true;
145 }
146 }
147
148 public RecordCompilationTests() {
149 boolean useAP = System.getProperty("useAP") == null ? false : System.getProperty("useAP").equals("true");
150 setDefaultFilename("R.java");
151 setCompileOptions(useAP ? PREVIEW_OPTIONS_WITH_AP : PREVIEW_OPTIONS);
152 System.out.println(useAP ? "running all tests using an annotation processor" : "running all tests without annotation processor");
153 }
154
155 public void testMalformedDeclarations() {
156 assertFail("compiler.err.premature.eof", "record R()");
157 assertFail("compiler.err.expected", "record R();");
158 assertFail("compiler.err.illegal.start.of.type", "record R(,) { }");
159 assertFail("compiler.err.illegal.start.of.type", "record R((int x)) { }");
160 assertFail("compiler.err.record.header.expected", "record R { }");
161 assertFail("compiler.err.expected", "record R(foo) { }");
162 assertFail("compiler.err.expected", "record R(int int) { }");
163 assertFail("compiler.err.mod.not.allowed.here", "abstract record R(String foo) { }");
164 //assertFail("compiler.err.illegal.combination.of.modifiers", "non-sealed record R(String foo) { }");
165 assertFail("compiler.err.repeated.modifier", "public public record R(String foo) { }");
166 assertFail("compiler.err.repeated.modifier", "private private record R(String foo) { }");
167 assertFail("compiler.err.already.defined", "record R(int x, int x) {}");
168 for (String s : List.of("var", "record"))
169 assertFail("compiler.err.restricted.type.not.allowed.here", "record R(# x) { }", s);
170 for (String s : List.of("public", "protected", "private", "static", "final", "transient", "volatile",
171 "abstract", "synchronized", "native", "strictfp")) // missing: sealed and non-sealed
172 assertFail("compiler.err.record.cant.declare.field.modifiers", "record R(# String foo) { }", s);
173 assertFail("compiler.err.varargs.must.be.last", "record R(int... x, int... y) {}");
174 assertFail("compiler.err.instance.initializer.not.allowed.in.records", "record R(int i) { {} }");
175 }
176
177 public void testGoodDeclarations() {
|