author | jlahoda |
Mon, 16 Jul 2018 12:35:25 +0200 | |
changeset 51094 | a49d106e9b7c |
parent 50967 | 1e24c7152e47 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
50704
1a3f1cf62456
8196425: tools/javac/modules/AnnotationProcessing.java failed
jjg
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
36526 | 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 |
|
51094
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
26 |
* @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747 |
36526 | 27 |
* @summary Verify that annotation processing works. |
28 |
* @library /tools/lib |
|
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 33 |
* @run main AnnotationProcessing |
34 |
*/ |
|
35 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
36 |
import java.io.File; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
37 |
import java.io.IOException; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
38 |
import java.io.OutputStream; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
39 |
import java.io.Reader; |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
40 |
import java.io.UncheckedIOException; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
41 |
import java.io.Writer; |
36526 | 42 |
import java.nio.file.Files; |
43 |
import java.nio.file.Path; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
44 |
import java.nio.file.Paths; |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
45 |
import java.util.ArrayList; |
36526 | 46 |
import java.util.Arrays; |
47 |
import java.util.HashMap; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
48 |
import java.util.HashSet; |
36526 | 49 |
import java.util.List; |
50 |
import java.util.Map; |
|
51 |
import java.util.Objects; |
|
52 |
import java.util.Set; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
53 |
import java.util.concurrent.Callable; |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
54 |
import java.util.function.Consumer; |
42824 | 55 |
import java.util.function.Function; |
43149 | 56 |
import java.util.regex.Pattern; |
36526 | 57 |
import java.util.stream.Collectors; |
58 |
||
59 |
import javax.annotation.processing.AbstractProcessor; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
60 |
import javax.annotation.processing.Filer; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
61 |
import javax.annotation.processing.FilerException; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
62 |
import javax.annotation.processing.Messager; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
63 |
import javax.annotation.processing.ProcessingEnvironment; |
36526 | 64 |
import javax.annotation.processing.RoundEnvironment; |
65 |
import javax.annotation.processing.SupportedAnnotationTypes; |
|
66 |
import javax.annotation.processing.SupportedOptions; |
|
67 |
import javax.lang.model.SourceVersion; |
|
68 |
import javax.lang.model.element.Element; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
69 |
import javax.lang.model.element.ElementKind; |
36526 | 70 |
import javax.lang.model.element.ModuleElement; |
71 |
import javax.lang.model.element.ModuleElement.ProvidesDirective; |
|
72 |
import javax.lang.model.element.ModuleElement.UsesDirective; |
|
73 |
import javax.lang.model.element.PackageElement; |
|
74 |
import javax.lang.model.element.TypeElement; |
|
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
75 |
import javax.lang.model.element.VariableElement; |
36526 | 76 |
import javax.lang.model.type.TypeKind; |
77 |
import javax.lang.model.util.ElementFilter; |
|
78 |
import javax.lang.model.util.ElementScanner9; |
|
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
79 |
import javax.tools.Diagnostic.Kind; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
80 |
import javax.tools.FileObject; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
81 |
import javax.tools.JavaCompiler; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
82 |
import javax.tools.JavaCompiler.CompilationTask; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
83 |
import javax.tools.JavaFileManager; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
84 |
import javax.tools.JavaFileManager.Location; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
85 |
import javax.tools.JavaFileObject; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
86 |
import javax.tools.StandardJavaFileManager; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
87 |
import javax.tools.StandardLocation; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
88 |
import javax.tools.ToolProvider; |
36526 | 89 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
90 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
91 |
import toolbox.Task; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
92 |
import toolbox.Task.Mode; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
93 |
import toolbox.Task.OutputKind; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
94 |
|
36526 | 95 |
public class AnnotationProcessing extends ModuleTestBase { |
96 |
||
97 |
public static void main(String... args) throws Exception { |
|
50967
1e24c7152e47
8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents:
50704
diff
changeset
|
98 |
System.out.println(System.getProperties()); |
36526 | 99 |
new AnnotationProcessing().runTests(); |
100 |
} |
|
101 |
||
102 |
@Test |
|
37758 | 103 |
public void testAPSingleModule(Path base) throws Exception { |
36526 | 104 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
105 |
Path m1 = moduleSrc.resolve("m1x"); |
36526 | 106 |
|
107 |
Path classes = base.resolve("classes"); |
|
108 |
||
109 |
Files.createDirectories(classes); |
|
110 |
||
111 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
112 |
"module m1x { }", |
36526 | 113 |
"package impl; public class Impl { }"); |
114 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
115 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
116 |
.options("--module-source-path", moduleSrc.toString(), |
36526 | 117 |
"-processor", AP.class.getName(), |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
118 |
"-AexpectedEnclosedElements=m1x=>impl") |
36526 | 119 |
.outdir(classes) |
120 |
.files(findJavaFiles(moduleSrc)) |
|
121 |
.run() |
|
122 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
123 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 124 |
|
125 |
if (!log.isEmpty()) |
|
126 |
throw new AssertionError("Unexpected output: " + log); |
|
127 |
} |
|
128 |
||
129 |
@Test |
|
37758 | 130 |
public void testAPMultiModule(Path base) throws Exception { |
36526 | 131 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
132 |
Path m1 = moduleSrc.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
133 |
Path m2 = moduleSrc.resolve("m2x"); |
36526 | 134 |
|
135 |
Path classes = base.resolve("classes"); |
|
136 |
||
137 |
Files.createDirectories(classes); |
|
138 |
||
139 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
140 |
"module m1x { }", |
36526 | 141 |
"package impl1; public class Impl1 { }"); |
142 |
||
143 |
tb.writeJavaFiles(m2, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
144 |
"module m2x { }", |
36526 | 145 |
"package impl2; public class Impl2 { }"); |
146 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
147 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
148 |
.options("--module-source-path", moduleSrc.toString(), |
36526 | 149 |
"-processor", AP.class.getName(), |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
150 |
"-AexpectedEnclosedElements=m1x=>impl1,m2x=>impl2") |
36526 | 151 |
.outdir(classes) |
152 |
.files(findJavaFiles(moduleSrc)) |
|
153 |
.run() |
|
154 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
155 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 156 |
|
157 |
if (!log.isEmpty()) |
|
158 |
throw new AssertionError("Unexpected output: " + log); |
|
159 |
} |
|
160 |
||
161 |
@SupportedAnnotationTypes("*") |
|
162 |
@SupportedOptions("expectedEnclosedElements") |
|
163 |
public static final class AP extends AbstractProcessor { |
|
164 |
||
165 |
private Map<String, List<String>> module2ExpectedEnclosedElements; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
166 |
private Set<String> seenModules = new HashSet<>(); |
36526 | 167 |
|
168 |
@Override |
|
169 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
170 |
if (module2ExpectedEnclosedElements == null) { |
|
171 |
module2ExpectedEnclosedElements = new HashMap<>(); |
|
172 |
||
173 |
String expectedEnclosedElements = |
|
174 |
processingEnv.getOptions().get("expectedEnclosedElements"); |
|
175 |
||
176 |
for (String moduleDef : expectedEnclosedElements.split(",")) { |
|
177 |
String[] module2Packages = moduleDef.split("=>"); |
|
178 |
||
179 |
module2ExpectedEnclosedElements.put(module2Packages[0], |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
180 |
List.of(module2Packages[1].split(":"))); |
36526 | 181 |
} |
182 |
} |
|
183 |
||
184 |
//verify ModuleType and ModuleSymbol behavior: |
|
185 |
for (Element root : roundEnv.getRootElements()) { |
|
186 |
ModuleElement module = processingEnv.getElementUtils().getModuleOf(root); |
|
187 |
||
188 |
assertEquals(TypeKind.MODULE, module.asType().getKind()); |
|
189 |
||
190 |
boolean[] seenModule = new boolean[1]; |
|
191 |
||
192 |
module.accept(new ElementScanner9<Void, Void>() { |
|
193 |
@Override |
|
194 |
public Void visitModule(ModuleElement e, Void p) { |
|
195 |
seenModule[0] = true; |
|
196 |
return null; |
|
197 |
} |
|
198 |
@Override |
|
199 |
public Void scan(Element e, Void p) { |
|
200 |
throw new AssertionError("Shouldn't get here."); |
|
201 |
} |
|
202 |
}, null); |
|
203 |
||
204 |
assertEquals(true, seenModule[0]); |
|
205 |
||
206 |
List<String> actualElements = |
|
207 |
module.getEnclosedElements() |
|
208 |
.stream() |
|
209 |
.map(s -> (PackageElement) s) |
|
210 |
.map(p -> p.getQualifiedName().toString()) |
|
211 |
.collect(Collectors.toList()); |
|
212 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
213 |
String moduleName = module.getQualifiedName().toString(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
214 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
215 |
assertEquals(module2ExpectedEnclosedElements.get(moduleName), |
36526 | 216 |
actualElements); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
217 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
218 |
seenModules.add(moduleName); |
36526 | 219 |
} |
220 |
||
221 |
if (roundEnv.processingOver()) { |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
222 |
assertEquals(module2ExpectedEnclosedElements.keySet(), seenModules); |
36526 | 223 |
} |
224 |
||
225 |
return false; |
|
226 |
} |
|
227 |
||
228 |
@Override |
|
229 |
public SourceVersion getSupportedSourceVersion() { |
|
230 |
return SourceVersion.latest(); |
|
231 |
} |
|
232 |
||
233 |
} |
|
234 |
||
235 |
@Test |
|
37758 | 236 |
public void testVerifyUsesProvides(Path base) throws Exception { |
36526 | 237 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
238 |
Path m1 = moduleSrc.resolve("m1x"); |
36526 | 239 |
|
240 |
Path classes = base.resolve("classes"); |
|
241 |
||
242 |
Files.createDirectories(classes); |
|
243 |
||
244 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
245 |
"module m1x { exports api; uses api.Api; provides api.Api with impl.Impl; }", |
36526 | 246 |
"package api; public class Api { }", |
247 |
"package impl; public class Impl extends api.Api { }"); |
|
248 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
249 |
String log = new JavacTask(tb) |
36526 | 250 |
.options("-doe", "-processor", VerifyUsesProvidesAP.class.getName()) |
251 |
.outdir(classes) |
|
252 |
.files(findJavaFiles(moduleSrc)) |
|
253 |
.run() |
|
254 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
255 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 256 |
|
257 |
if (!log.isEmpty()) |
|
258 |
throw new AssertionError("Unexpected output: " + log); |
|
259 |
} |
|
260 |
||
261 |
@SupportedAnnotationTypes("*") |
|
262 |
public static final class VerifyUsesProvidesAP extends AbstractProcessor { |
|
263 |
||
264 |
@Override |
|
265 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
266 |
TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api"); |
|
267 |
||
268 |
assertNonNull("Cannot find api.Api", api); |
|
269 |
||
270 |
ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement(); |
|
271 |
||
272 |
assertNonNull("modle is null", modle); |
|
273 |
||
274 |
List<? extends UsesDirective> uses = ElementFilter.usesIn(modle.getDirectives()); |
|
275 |
assertEquals(1, uses.size()); |
|
276 |
assertEquals("api.Api", uses.iterator().next().getService().getQualifiedName().toString()); |
|
277 |
||
278 |
List<? extends ProvidesDirective> provides = ElementFilter.providesIn(modle.getDirectives()); |
|
279 |
assertEquals(1, provides.size()); |
|
280 |
assertEquals("api.Api", provides.iterator().next().getService().getQualifiedName().toString()); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40311
diff
changeset
|
281 |
assertEquals("impl.Impl", provides.iterator().next().getImplementations().get(0).getQualifiedName().toString()); |
36526 | 282 |
|
283 |
return false; |
|
284 |
} |
|
285 |
||
286 |
@Override |
|
287 |
public SourceVersion getSupportedSourceVersion() { |
|
288 |
return SourceVersion.latest(); |
|
289 |
} |
|
290 |
||
291 |
} |
|
292 |
||
293 |
@Test |
|
37758 | 294 |
public void testPackageNoModule(Path base) throws Exception { |
36526 | 295 |
Path src = base.resolve("src"); |
296 |
Path classes = base.resolve("classes"); |
|
297 |
||
298 |
Files.createDirectories(classes); |
|
299 |
||
300 |
tb.writeJavaFiles(src, |
|
301 |
"package api; public class Api { }"); |
|
302 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
303 |
String log = new JavacTask(tb) |
36526 | 304 |
.options("-processor", VerifyPackageNoModule.class.getName(), |
305 |
"-source", "8", |
|
306 |
"-Xlint:-options") |
|
307 |
.outdir(classes) |
|
308 |
.files(findJavaFiles(src)) |
|
309 |
.run() |
|
310 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
311 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 312 |
|
313 |
if (!log.isEmpty()) |
|
314 |
throw new AssertionError("Unexpected output: " + log); |
|
315 |
} |
|
316 |
||
317 |
@SupportedAnnotationTypes("*") |
|
318 |
public static final class VerifyPackageNoModule extends AbstractProcessor { |
|
319 |
||
320 |
@Override |
|
321 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
322 |
TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api"); |
|
323 |
||
324 |
assertNonNull("Cannot find api.Api", api); |
|
325 |
||
326 |
ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement(); |
|
327 |
||
328 |
assertNull("modle is not null", modle); |
|
329 |
||
330 |
return false; |
|
331 |
} |
|
332 |
||
333 |
@Override |
|
334 |
public SourceVersion getSupportedSourceVersion() { |
|
335 |
return SourceVersion.latest(); |
|
336 |
} |
|
337 |
||
338 |
} |
|
339 |
||
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
340 |
@Test |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
341 |
public void testQualifiedClassForProcessing(Path base) throws Exception { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
342 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
343 |
Path m1 = moduleSrc.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
344 |
Path m2 = moduleSrc.resolve("m2x"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
345 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
346 |
Path classes = base.resolve("classes"); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
347 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
348 |
Files.createDirectories(classes); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
349 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
350 |
tb.writeJavaFiles(m1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
351 |
"module m1x { }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
352 |
"package impl; public class Impl { int m1x; }"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
353 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
354 |
tb.writeJavaFiles(m2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
355 |
"module m2x { }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
356 |
"package impl; public class Impl { int m2x; }"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
357 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
358 |
new JavacTask(tb) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
359 |
.options("--module-source-path", moduleSrc.toString()) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
360 |
.outdir(classes) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
361 |
.files(findJavaFiles(moduleSrc)) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
362 |
.run() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
363 |
.writeAll() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
364 |
.getOutput(Task.OutputKind.DIRECT); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
365 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
366 |
List<String> expected = List.of("Note: field: m1x"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
367 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
368 |
for (Mode mode : new Mode[] {Mode.API, Mode.CMDLINE}) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
369 |
List<String> log = new JavacTask(tb, mode) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
370 |
.options("-processor", QualifiedClassForProcessing.class.getName(), |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
371 |
"--module-path", classes.toString()) |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
372 |
.classes("m1x/impl.Impl") |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
373 |
.outdir(classes) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
374 |
.run() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
375 |
.writeAll() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
376 |
.getOutputLines(Task.OutputKind.DIRECT); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
377 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
378 |
if (!expected.equals(log)) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
379 |
throw new AssertionError("Unexpected output: " + log); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
380 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
381 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
382 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
383 |
@SupportedAnnotationTypes("*") |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
384 |
public static final class QualifiedClassForProcessing extends AbstractProcessor { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
385 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
386 |
@Override |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
387 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
388 |
if (processingEnv.getElementUtils().getModuleElement("m1x") == null) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
389 |
throw new AssertionError("No m1x module found."); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
390 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
391 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
392 |
Messager messager = processingEnv.getMessager(); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
393 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
394 |
for (TypeElement clazz : ElementFilter.typesIn(roundEnv.getRootElements())) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
395 |
for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
396 |
messager.printMessage(Kind.NOTE, "field: " + field.getSimpleName()); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
397 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
398 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
399 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
400 |
return false; |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
401 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
402 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
403 |
@Override |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
404 |
public SourceVersion getSupportedSourceVersion() { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
405 |
return SourceVersion.latest(); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
406 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
407 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
408 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
409 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
410 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
411 |
public void testModuleInRootElements(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
412 |
Path moduleSrc = base.resolve("module-src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
413 |
Path m1 = moduleSrc.resolve("m1"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
414 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
415 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
416 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
417 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
418 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
419 |
tb.writeJavaFiles(m1, |
42823 | 420 |
"module m1x { exports api; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
421 |
"package api; public class Api { }"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
422 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
423 |
List<String> log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
424 |
.options("-processor", ModuleInRootElementsAP.class.getName()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
425 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
426 |
.files(findJavaFiles(moduleSrc)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
427 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
428 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
429 |
.getOutputLines(Task.OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
430 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
431 |
assertEquals(List.of("module: m1x"), log); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
432 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
433 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
434 |
@SupportedAnnotationTypes("*") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
435 |
public static final class ModuleInRootElementsAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
436 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
437 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
438 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
439 |
roundEnv.getRootElements() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
440 |
.stream() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
441 |
.filter(el -> el.getKind() == ElementKind.MODULE) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
442 |
.forEach(mod -> System.err.println("module: " + mod.getSimpleName())); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
443 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
444 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
445 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
446 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
447 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
448 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
449 |
return SourceVersion.latest(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
450 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
451 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
452 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
453 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
454 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
455 |
public void testAnnotationsInModuleInfo(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
456 |
Path moduleSrc = base.resolve("module-src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
457 |
Path m1 = moduleSrc.resolve("m1"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
458 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
459 |
tb.writeJavaFiles(m1, |
42823 | 460 |
"@Deprecated module m1x { }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
461 |
|
42823 | 462 |
Path m2 = moduleSrc.resolve("m2x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
463 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
464 |
tb.writeJavaFiles(m2, |
42823 | 465 |
"@SuppressWarnings(\"\") module m2x { }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
466 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
467 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
468 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
469 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
470 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
471 |
List<String> log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
472 |
.options("-processor", AnnotationsInModuleInfoPrint.class.getName()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
473 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
474 |
.files(findJavaFiles(m1)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
475 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
476 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
477 |
.getOutputLines(Task.OutputKind.DIRECT); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
478 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
479 |
List<String> expectedLog = List.of("Note: AP Invoked", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
480 |
"Note: AP Invoked"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
481 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
482 |
assertEquals(expectedLog, log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
483 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
484 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
485 |
.options("-processor", AnnotationsInModuleInfoFail.class.getName()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
486 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
487 |
.files(findJavaFiles(m2)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
488 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
489 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
490 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
491 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
492 |
@SupportedAnnotationTypes("java.lang.Deprecated") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
493 |
public static final class AnnotationsInModuleInfoPrint extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
494 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
495 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
496 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
497 |
processingEnv.getMessager().printMessage(Kind.NOTE, "AP Invoked"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
498 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
499 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
500 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
501 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
502 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
503 |
return SourceVersion.latest(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
504 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
505 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
506 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
507 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
508 |
@SupportedAnnotationTypes("java.lang.Deprecated") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
509 |
public static final class AnnotationsInModuleInfoFail extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
510 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
511 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
512 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
513 |
throw new AssertionError(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
514 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
515 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
516 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
517 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
518 |
return SourceVersion.latest(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
519 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
520 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
521 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
522 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
523 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
524 |
public void testGenerateInMultiModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
525 |
Path moduleSrc = base.resolve("module-src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
526 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
527 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
528 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
529 |
|
42823 | 530 |
Path m1 = moduleSrc.resolve("m1x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
531 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
532 |
tb.writeJavaFiles(m1, |
42823 | 533 |
"module m1x { exports api1; }", |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
534 |
"package api1; public class Api { }", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
535 |
"package clash; public class C { }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
536 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
537 |
writeFile("1", m1, "api1", "api"); |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
538 |
writeFile("2", m1, "clash", "clash"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
539 |
|
42823 | 540 |
Path m2 = moduleSrc.resolve("m2x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
541 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
542 |
tb.writeJavaFiles(m2, |
42823 | 543 |
"module m2x { requires m1x; exports api2; }", |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
544 |
"package api2; public class Api { }", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
545 |
"package clash; public class C { }"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
546 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
547 |
writeFile("3", m2, "api2", "api"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
548 |
writeFile("4", m2, "clash", "api"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
549 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
550 |
//passing testcases: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
551 |
for (String module : Arrays.asList("", "m1x/")) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
552 |
for (String originating : Arrays.asList("", ", jlObject")) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
553 |
tb.writeJavaFiles(m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
554 |
"package test; class Test { api1.Impl i; }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
555 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
556 |
//source: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
557 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
558 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
559 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
560 |
"createSource(() -> filer.createSourceFile(\"" + module + "api1.Impl\"" + originating + "), \"api1.Impl\", \"package api1; public class Impl {}\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
561 |
"--module-source-path", moduleSrc.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
562 |
assertFileExists(classes, "m1x", "api1", "Impl.class"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
563 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
564 |
//class: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
565 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
566 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
567 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
568 |
"createClass(() -> filer.createClassFile(\"" + module + "api1.Impl\"" + originating + "), \"api1.Impl\", \"package api1; public class Impl {}\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
569 |
"--module-source-path", moduleSrc.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
570 |
assertFileExists(classes, "m1x", "api1", "Impl.class"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
571 |
|
50967
1e24c7152e47
8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents:
50704
diff
changeset
|
572 |
tb.deleteFiles(m1.resolve("test").resolve("Test.java")); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
573 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
574 |
//resource class output: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
575 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
576 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
577 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
578 |
"createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"" + module + "api1\", \"impl\"" + originating + "), \"impl\", \"impl\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
579 |
"--module-source-path", moduleSrc.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
580 |
assertFileExists(classes, "m1x", "api1", "impl"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
581 |
} |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
582 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
583 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
584 |
//get resource module source path: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
585 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
586 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
587 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
588 |
"doReadResource(() -> filer.getResource(StandardLocation.MODULE_SOURCE_PATH, \"m1x/api1\", \"api\"), \"1\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
589 |
"--module-source-path", moduleSrc.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
590 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
591 |
//can generate resources to the single root module: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
592 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
593 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
594 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
595 |
"createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"m1x/impl\", \"impl\"), \"impl\", \"impl\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
596 |
"--module-source-path", moduleSrc.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
597 |
assertFileExists(classes, "m1x", "impl", "impl"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
598 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
599 |
//check --default-module-for-created-files option: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
600 |
for (String pack : Arrays.asList("clash", "doesnotexist")) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
601 |
tb.writeJavaFiles(m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
602 |
"package test; class Test { " + pack + ".Pass i; }"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
603 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
604 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
605 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
606 |
"createSource(() -> filer.createSourceFile(\"" + pack + ".Pass\")," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
607 |
" \"" + pack + ".Pass\"," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
608 |
" \"package " + pack + ";" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
609 |
" public class Pass { }\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
610 |
"--module-source-path", moduleSrc.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
611 |
"--default-module-for-created-files=m1x"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
612 |
assertFileExists(classes, "m1x", pack, "Pass.class"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
613 |
assertFileNotExists(classes, "m2x", pack, "Pass.class"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
614 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
615 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
616 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
617 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
618 |
"createClass(() -> filer.createClassFile(\"" + pack + ".Pass\")," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
619 |
" \"" + pack + ".Pass\"," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
620 |
" \"package " + pack + ";" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
621 |
" public class Pass { }\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
622 |
"--module-source-path", moduleSrc.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
623 |
"--default-module-for-created-files=m1x"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
624 |
assertFileExists(classes, "m1x", pack, "Pass.class"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
625 |
assertFileNotExists(classes, "m2x", pack, "Pass.class"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
626 |
|
50967
1e24c7152e47
8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents:
50704
diff
changeset
|
627 |
tb.deleteFiles(m1.resolve("test").resolve("Test.java")); |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
628 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
629 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
630 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
631 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
632 |
"createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
633 |
" \"" + pack + "\", \"impl\"), \"impl\", \"impl\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
634 |
"--module-source-path", moduleSrc.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
635 |
"--default-module-for-created-files=m1x"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
636 |
assertFileExists(classes, "m1x", pack, "impl"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
637 |
assertFileNotExists(classes, "m2x", pack, "impl"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
638 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
639 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
640 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
641 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
642 |
"doReadResource(() -> filer.getResource(StandardLocation.CLASS_OUTPUT," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
643 |
" \"" + pack + "\", \"resource\"), \"1\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
644 |
p -> writeFile("1", p.resolve("m1x"), pack, "resource"), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
645 |
"--module-source-path", moduleSrc.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
646 |
"--default-module-for-created-files=m1x"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
647 |
} |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
648 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
649 |
//wrong default module: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
650 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
651 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
652 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
653 |
"expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT," + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
654 |
" \"clash\", \"impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
655 |
"--module-source-path", moduleSrc.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
656 |
"--default-module-for-created-files=doesnotexist"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
657 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
658 |
String[] failingCases = { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
659 |
//must not generate to unnamed package: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
660 |
"expectFilerException(() -> filer.createSourceFile(\"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
661 |
"expectFilerException(() -> filer.createClassFile(\"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
662 |
"expectFilerException(() -> filer.createSourceFile(\"m1x/Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
663 |
"expectFilerException(() -> filer.createClassFile(\"m1x/Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
664 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
665 |
//cannot infer module name, package clash: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
666 |
"expectFilerException(() -> filer.createSourceFile(\"clash.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
667 |
"expectFilerException(() -> filer.createClassFile(\"clash.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
668 |
"expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"clash\", \"impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
669 |
"expectFilerException(() -> filer.getResource(StandardLocation.CLASS_OUTPUT, \"clash\", \"impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
670 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
671 |
//cannot infer module name, package does not exist: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
672 |
"expectFilerException(() -> filer.createSourceFile(\"doesnotexist.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
673 |
"expectFilerException(() -> filer.createClassFile(\"doesnotexist.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
674 |
"expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"doesnotexist\", \"impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
675 |
"expectFilerException(() -> filer.getResource(StandardLocation.CLASS_OUTPUT, \"doesnotexist\", \"impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
676 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
677 |
//cannot generate sources/classes to modules that are not root modules: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
678 |
"expectFilerException(() -> filer.createSourceFile(\"java.base/fail.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
679 |
"expectFilerException(() -> filer.createClassFile(\"java.base/fail.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
680 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
681 |
//cannot read from module locations if module not given and not inferable: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
682 |
"expectFilerException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"fail\", \"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
683 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
684 |
//wrong module given: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
685 |
"expectException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.compiler/java.lang\", \"Object.class\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
686 |
}; |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
687 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
688 |
for (String failingCode : failingCases) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
689 |
System.err.println("failing code: " + failingCode); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
690 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
691 |
moduleSrc, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
692 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
693 |
failingCode, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
694 |
"--module-source-path", moduleSrc.toString()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
695 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
696 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
697 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
698 |
public static abstract class GeneratingAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
699 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
700 |
public void createSource(CreateFileObject file, String name, String content) { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
701 |
try (Writer out = file.create().openWriter()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
702 |
out.write(content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
703 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
704 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
705 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
706 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
707 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
708 |
public void createClass(CreateFileObject file, String name, String content) { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
709 |
String fileNameStub = name.replace(".", File.separator); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
710 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
711 |
try (OutputStream out = file.create().openOutputStream()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
712 |
Path scratch = Files.createDirectories(Paths.get("")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
713 |
Path scratchSrc = scratch.resolve(fileNameStub + ".java").toAbsolutePath(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
714 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
715 |
Files.createDirectories(scratchSrc.getParent()); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
716 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
717 |
try (Writer w = Files.newBufferedWriter(scratchSrc)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
718 |
w.write(content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
719 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
720 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
721 |
Path scratchClasses = scratch.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
722 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
723 |
Files.createDirectories(scratchClasses); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
724 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
725 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
726 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
727 |
List<String> options = List.of("-d", scratchClasses.toString()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
728 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(scratchSrc); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
729 |
CompilationTask task = comp.getTask(null, fm, null, options, null, files); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
730 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
731 |
if (!task.call()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
732 |
throw new AssertionError("compilation failed"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
733 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
734 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
735 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
736 |
Path classfile = scratchClasses.resolve(fileNameStub + ".class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
737 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
738 |
Files.copy(classfile, out); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
739 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
740 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
741 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
742 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
743 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
744 |
public void doReadResource(CreateFileObject file, String expectedContent) { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
745 |
try { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
746 |
StringBuilder actualContent = new StringBuilder(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
747 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
748 |
try (Reader r = file.create().openReader(true)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
749 |
int read; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
750 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
751 |
while ((read = r.read()) != (-1)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
752 |
actualContent.append((char) read); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
753 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
754 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
755 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
756 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
757 |
assertEquals(expectedContent, actualContent.toString()); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
758 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
759 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
760 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
761 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
762 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
763 |
public void checkResourceExists(CreateFileObject file) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
764 |
try { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
765 |
file.create().openInputStream().close(); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
766 |
} catch (IOException ex) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
767 |
throw new IllegalStateException(ex); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
768 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
769 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
770 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
771 |
public interface CreateFileObject { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
772 |
public FileObject create() throws IOException; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
773 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
774 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
775 |
public void expectFilerException(Callable<Object> c) { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
776 |
try { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
777 |
c.call(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
778 |
throw new AssertionError("Expected exception not thrown"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
779 |
} catch (FilerException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
780 |
//expected |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
781 |
} catch (Exception ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
782 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
783 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
784 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
785 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
786 |
public void expectException(Callable<Object> c) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
787 |
try { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
788 |
c.call(); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
789 |
throw new AssertionError("Expected exception not thrown"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
790 |
} catch (IOException ex) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
791 |
//expected |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
792 |
} catch (Exception ex) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
793 |
throw new IllegalStateException(ex); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
794 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
795 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
796 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
797 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
798 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
799 |
return SourceVersion.latest(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
800 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
801 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
802 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
803 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
804 |
@Test |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
805 |
public void testGenerateSingleModule(Path base) throws Exception { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
806 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
807 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
808 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
809 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
810 |
Path src = base.resolve("module-src"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
811 |
Path m1 = src.resolve("m1x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
812 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
813 |
tb.writeJavaFiles(m1, |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
814 |
"module m1x { }", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
815 |
"package test; class Test { impl.Impl i; }"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
816 |
Path m2 = src.resolve("m2x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
817 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
818 |
tb.writeJavaFiles(m2, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
819 |
"module m2x { }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
820 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
821 |
for (String[] options : new String[][] {new String[] {"-sourcepath", m1.toString()}, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
822 |
new String[] {"--module-source-path", src.toString()}}) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
823 |
String modulePath = options[0].equals("--module-source-path") ? "m1x" : ""; |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
824 |
//passing testcases: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
825 |
for (String module : Arrays.asList("", "m1x/")) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
826 |
for (String originating : Arrays.asList("", ", jlObject")) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
827 |
tb.writeJavaFiles(m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
828 |
"package test; class Test { impl.Impl i; }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
829 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
830 |
//source: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
831 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
832 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
833 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
834 |
"createSource(() -> filer.createSourceFile(\"" + module + "impl.Impl\"" + originating + "), \"impl.Impl\", \"package impl; public class Impl {}\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
835 |
options); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
836 |
assertFileExists(classes, modulePath, "impl", "Impl.class"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
837 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
838 |
//class: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
839 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
840 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
841 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
842 |
"createClass(() -> filer.createClassFile(\"" + module + "impl.Impl\"" + originating + "), \"impl.Impl\", \"package impl; public class Impl {}\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
843 |
options); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
844 |
assertFileExists(classes, modulePath, "impl", "Impl.class"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
845 |
|
50967
1e24c7152e47
8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents:
50704
diff
changeset
|
846 |
tb.deleteFiles(m1.resolve("test").resolve("Test.java")); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
847 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
848 |
//resource class output: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
849 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
850 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
851 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
852 |
"createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"impl\", \"impl\"" + originating + "), \"impl\", \"impl\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
853 |
options); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
854 |
assertFileExists(classes, modulePath, "impl", "impl"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
855 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
856 |
} |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
857 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
858 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
859 |
//get resource source path: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
860 |
writeFile("1", m1, "impl", "resource"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
861 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
862 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
863 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
864 |
"doReadResource(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"impl\", \"resource\"), \"1\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
865 |
"-sourcepath", m1.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
866 |
//must not specify module when reading non-module oriented locations: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
867 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
868 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
869 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
870 |
"expectFilerException(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"m1x/impl\", \"resource\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
871 |
"-sourcepath", m1.toString()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
872 |
|
50967
1e24c7152e47
8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents:
50704
diff
changeset
|
873 |
tb.deleteFiles(m1.resolve("impl").resolve("resource")); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
874 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
875 |
//can read resources from the system module path if module name given: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
876 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
877 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
878 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
879 |
"checkResourceExists(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.base/java.lang\", \"Object.class\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
880 |
"-sourcepath", m1.toString()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
881 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
882 |
//can read resources from the system module path if module inferable: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
883 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
884 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
885 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
886 |
"expectFilerException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.lang\", \"Object.class\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
887 |
"-sourcepath", m1.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
888 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
889 |
//cannot generate resources to modules that are not root modules: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
890 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
891 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
892 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
893 |
"expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"java.base/fail\", \"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
894 |
"--module-source-path", src.toString()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
895 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
896 |
//can generate resources to the single root module: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
897 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
898 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
899 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
900 |
"createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"impl\", \"impl\"), \"impl\", \"impl\")", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
901 |
"--module-source-path", src.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
902 |
assertFileExists(classes, "m1x", "impl", "impl"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
903 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
904 |
String[] failingCases = { |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
905 |
//must not generate to unnamed package: |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
906 |
"expectFilerException(() -> filer.createSourceFile(\"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
907 |
"expectFilerException(() -> filer.createClassFile(\"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
908 |
"expectFilerException(() -> filer.createSourceFile(\"m1x/Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
909 |
"expectFilerException(() -> filer.createClassFile(\"m1x/Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
910 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
911 |
//cannot generate sources/classes to modules that are not root modules: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
912 |
"expectFilerException(() -> filer.createSourceFile(\"java.base/fail.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
913 |
"expectFilerException(() -> filer.createClassFile(\"java.base/fail.Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
914 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
915 |
//cannot specify module name for class output when not in the multi-module mode: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
916 |
"expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"m1x/fail\", \"Fail\"))", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
917 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
918 |
//cannot read from module locations if module not given: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
919 |
"expectFilerException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"fail\", \"Fail\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
920 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
921 |
//wrong module given: |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
922 |
"expectException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.compiler/java.lang\", \"Object.class\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
923 |
}; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
924 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
925 |
for (String failingCode : failingCases) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
926 |
System.err.println("failing code: " + failingCode); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
927 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
928 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
929 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
930 |
failingCode, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
931 |
"-sourcepath", m1.toString()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
932 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
933 |
|
50967
1e24c7152e47
8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents:
50704
diff
changeset
|
934 |
tb.deleteFiles(m1.resolve("module-info.java")); |
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
935 |
tb.writeJavaFiles(m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
936 |
"package test; class Test { }"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
937 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
938 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
939 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
940 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
941 |
"expectFilerException(() -> filer.createSourceFile(\"m1x/impl.Impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
942 |
"-sourcepath", m1.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
943 |
"-source", "8"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
944 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
945 |
runCompiler(base, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
946 |
m1, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
947 |
classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
948 |
"expectFilerException(() -> filer.createClassFile(\"m1x/impl.Impl\"))", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
949 |
"-sourcepath", m1.toString(), |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
950 |
"-source", "8"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
951 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
952 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
953 |
private void runCompiler(Path base, Path src, Path classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
954 |
String code, String... options) throws IOException { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
955 |
runCompiler(base, src, classes, code, p -> {}, options); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
956 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
957 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
958 |
private void runCompiler(Path base, Path src, Path classes, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
959 |
String code, Consumer<Path> generateToClasses, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
960 |
String... options) throws IOException { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
961 |
Path apClasses = base.resolve("ap-classes"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
962 |
if (Files.exists(apClasses)) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
963 |
tb.cleanDirectory(apClasses); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
964 |
} else { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
965 |
Files.createDirectories(apClasses); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
966 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
967 |
compileAP(apClasses, code); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
968 |
if (Files.exists(classes)) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
969 |
tb.cleanDirectory(classes); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
970 |
} else { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
971 |
Files.createDirectories(classes); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
972 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
973 |
generateToClasses.accept(classes); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
974 |
List<String> opts = new ArrayList<>(); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
975 |
opts.addAll(Arrays.asList(options)); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
976 |
opts.add("-processorpath"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
977 |
opts.add(System.getProperty("test.class.path") + File.pathSeparator + apClasses.toString()); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
978 |
opts.add("-processor"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
979 |
opts.add("AP"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
980 |
new JavacTask(tb) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
981 |
.options(opts) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
982 |
.outdir(classes) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
983 |
.files(findJavaFiles(src)) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
984 |
.run() |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
985 |
.writeAll(); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
986 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
987 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
988 |
private void compileAP(Path target, String code) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
989 |
String processorCode = |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
990 |
"import java.util.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
991 |
"import javax.annotation.processing.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
992 |
"import javax.lang.model.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
993 |
"import javax.lang.model.element.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
994 |
"import javax.lang.model.type.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
995 |
"import javax.lang.model.util.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
996 |
"import javax.tools.*;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
997 |
"@SupportedAnnotationTypes(\"*\")\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
998 |
"public final class AP extends AnnotationProcessing.GeneratingAP {\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
999 |
"\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1000 |
" int round;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1001 |
"\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1002 |
" @Override\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1003 |
" public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1004 |
" if (round++ != 0)\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1005 |
" return false;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1006 |
" Filer filer = processingEnv.getFiler();\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1007 |
" TypeElement jlObject = processingEnv.getElementUtils().getTypeElement(\"java.lang.Object\");\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1008 |
code + ";\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1009 |
" return false;\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1010 |
" }\n" + |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1011 |
" }\n"; |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1012 |
new JavacTask(tb) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1013 |
.options("-classpath", System.getProperty("test.class.path")) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1014 |
.sources(processorCode) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1015 |
.outdir(target) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1016 |
.run() |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1017 |
.writeAll(); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1018 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1019 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1020 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1021 |
public void testGenerateInUnnamedModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1022 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1023 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1024 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1025 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1026 |
Path src = base.resolve("src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1027 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1028 |
tb.writeJavaFiles(src, |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1029 |
"class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1030 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1031 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1032 |
.options("-processor", UnnamedModeAPITestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1033 |
"-sourcepath", src.toString()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1034 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1035 |
.files(findJavaFiles(src)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1036 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1037 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1038 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1039 |
assertFileExists(classes, "Impl1.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1040 |
assertFileExists(classes, "Impl2.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1041 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1042 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1043 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1044 |
public void testGenerateInNoModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1045 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1046 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1047 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1048 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1049 |
Path src = base.resolve("src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1050 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1051 |
tb.writeJavaFiles(src, |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1052 |
"class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1053 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1054 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1055 |
.options("-processor", UnnamedModeAPITestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1056 |
"-source", "8", "-target", "8", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1057 |
"-sourcepath", src.toString()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1058 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1059 |
.files(findJavaFiles(src)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1060 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1061 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1062 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1063 |
assertFileExists(classes, "Impl1.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1064 |
assertFileExists(classes, "Impl2.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1065 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1066 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1067 |
@SupportedAnnotationTypes("*") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1068 |
public static final class UnnamedModeAPITestAP extends GeneratingAP { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1069 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1070 |
int round; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1071 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1072 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1073 |
public synchronized void init(ProcessingEnvironment processingEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1074 |
super.init(processingEnv); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1075 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1076 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1077 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1078 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1079 |
if (round++ != 0) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1080 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1081 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1082 |
Filer filer = processingEnv.getFiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1083 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1084 |
//must not generate to unnamed package: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1085 |
createSource(() -> filer.createSourceFile("Impl1"), "Impl1", "class Impl1 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1086 |
createClass(() -> filer.createClassFile("Impl2"), "Impl2", "class Impl2 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1087 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1088 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1089 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1090 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1091 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1092 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1093 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1094 |
public void testDisambiguateAnnotations(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1095 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1096 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1097 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1098 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1099 |
Path src = base.resolve("src"); |
42823 | 1100 |
Path m1 = src.resolve("m1x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1101 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1102 |
tb.writeJavaFiles(m1, |
42823 | 1103 |
"module m1x { exports api; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1104 |
"package api; public @interface A {}", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1105 |
"package api; public @interface B {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1106 |
|
42823 | 1107 |
Path m2 = src.resolve("m2x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1108 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1109 |
tb.writeJavaFiles(m2, |
42823 | 1110 |
"module m2x { exports api; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1111 |
"package api; public @interface A {}", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1112 |
"package api; public @interface B {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1113 |
|
42823 | 1114 |
Path m3 = src.resolve("m3x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1115 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1116 |
tb.writeJavaFiles(m3, |
42823 | 1117 |
"module m3x { requires m1x; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1118 |
"package impl; import api.*; @A @B public class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1119 |
|
42823 | 1120 |
Path m4 = src.resolve("m4x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1121 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1122 |
tb.writeJavaFiles(m4, |
42823 | 1123 |
"module m4x { requires m2x; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1124 |
"package impl; import api.*; @A @B public class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1125 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1126 |
List<String> log; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1127 |
List<String> expected; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1128 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1129 |
log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1130 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1131 |
"--module-source-path", src.toString(), |
42823 | 1132 |
"-m", "m1x,m2x") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1133 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1134 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1135 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1136 |
.getOutputLines(OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1137 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1138 |
expected = List.of(""); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1139 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1140 |
if (!expected.equals(log)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1141 |
throw new AssertionError("Output does not match; output: " + log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1142 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1143 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1144 |
log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1145 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1146 |
"--module-source-path", src.toString(), |
42823 | 1147 |
"-m", "m3x") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1148 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1149 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1150 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1151 |
.getOutputLines(OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1152 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1153 |
expected = List.of("SelectAnnotationBTestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1154 |
"SelectAnnotationBTestAP"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1155 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1156 |
if (!expected.equals(log)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1157 |
throw new AssertionError("Output does not match; output: " + log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1158 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1159 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1160 |
log = new JavacTask(tb) |
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1161 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1162 |
SelectAnnotationBTestAP.class.getName() + "," + |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1163 |
SelectAnnotationAStrictTestAP.class.getName(), |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1164 |
"--module-source-path", src.toString(), |
42823 | 1165 |
"-m", "m4x") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1166 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1167 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1168 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1169 |
.getOutputLines(OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1170 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1171 |
expected = List.of("SelectAnnotationATestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1172 |
"SelectAnnotationBTestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1173 |
"SelectAnnotationAStrictTestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1174 |
"SelectAnnotationATestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1175 |
"SelectAnnotationBTestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1176 |
"SelectAnnotationAStrictTestAP"); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1177 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1178 |
if (!expected.equals(log)) { |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1179 |
throw new AssertionError("Output does not match; output: " + log); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1180 |
} |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1181 |
} |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1182 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1183 |
@Test |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1184 |
public void testDisambiguateAnnotationsUnnamedModule(Path base) throws Exception { |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1185 |
Path classes = base.resolve("classes"); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1186 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1187 |
Files.createDirectories(classes); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1188 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1189 |
Path src = base.resolve("src"); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1190 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1191 |
tb.writeJavaFiles(src, |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1192 |
"package api; public @interface A {}", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1193 |
"package api; public @interface B {}", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1194 |
"package impl; import api.*; @A @B public class T {}"); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1195 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1196 |
List<String> log = new JavacTask(tb) |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1197 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1198 |
SelectAnnotationBTestAP.class.getName() + "," + |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1199 |
SelectAnnotationAStrictTestAP.class.getName()) |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1200 |
.outdir(classes) |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1201 |
.files(findJavaFiles(src)) |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1202 |
.run() |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1203 |
.writeAll() |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1204 |
.getOutputLines(OutputKind.STDERR); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1205 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1206 |
List<String> expected = List.of("SelectAnnotationBTestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1207 |
"SelectAnnotationBTestAP"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1208 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1209 |
if (!expected.equals(log)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1210 |
throw new AssertionError("Output does not match; output: " + log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1211 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1212 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1213 |
|
43037
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1214 |
@Test |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1215 |
public void testDisambiguateAnnotationsNoModules(Path base) throws Exception { |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1216 |
Path classes = base.resolve("classes"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1217 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1218 |
Files.createDirectories(classes); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1219 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1220 |
Path src = base.resolve("src"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1221 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1222 |
tb.writeJavaFiles(src, |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1223 |
"package api; public @interface A {}", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1224 |
"package api; public @interface B {}", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1225 |
"package impl; import api.*; @A @B public class T {}"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1226 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1227 |
List<String> log = new JavacTask(tb) |
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1228 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1229 |
SelectAnnotationBTestAP.class.getName() + "," + |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1230 |
SelectAnnotationAStrictTestAP.class.getName(), |
43037
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1231 |
"-source", "8", "-target", "8") |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1232 |
.outdir(classes) |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1233 |
.files(findJavaFiles(src)) |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1234 |
.run() |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1235 |
.writeAll() |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1236 |
.getOutputLines(OutputKind.STDERR); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1237 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1238 |
List<String> expected = List.of("SelectAnnotationATestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1239 |
"SelectAnnotationBTestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1240 |
"SelectAnnotationATestAP", |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1241 |
"SelectAnnotationBTestAP"); |
43037
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1242 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1243 |
if (!expected.equals(log)) { |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1244 |
throw new AssertionError("Output does not match; output: " + log); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1245 |
} |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1246 |
} |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1247 |
|
42823 | 1248 |
@SupportedAnnotationTypes("m2x/api.A") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1249 |
public static final class SelectAnnotationATestAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1250 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1251 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1252 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1253 |
System.err.println("SelectAnnotationATestAP"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1254 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1255 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1256 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1257 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1258 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1259 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1260 |
@SupportedAnnotationTypes("api.B") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1261 |
public static final class SelectAnnotationBTestAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1262 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1263 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1264 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1265 |
System.err.println("SelectAnnotationBTestAP"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1266 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1267 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1268 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1269 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1270 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1271 |
|
43585
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1272 |
public static final class SelectAnnotationAStrictTestAP extends AbstractProcessor { |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1273 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1274 |
@Override |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1275 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1276 |
System.err.println("SelectAnnotationAStrictTestAP"); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1277 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1278 |
return false; |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1279 |
} |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1280 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1281 |
@Override |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1282 |
public Set<String> getSupportedAnnotationTypes() { |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1283 |
return Set.of("m2x/api.A"); |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1284 |
} |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1285 |
|
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1286 |
} |
19e14d35add0
8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents:
43149
diff
changeset
|
1287 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1288 |
private static void writeFile(String content, Path base, String... pathElements) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1289 |
try { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1290 |
Path file = resolveFile(base, pathElements); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1291 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1292 |
Files.createDirectories(file.getParent()); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1293 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1294 |
try (Writer out = Files.newBufferedWriter(file)) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1295 |
out.append(content); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1296 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1297 |
} catch (IOException ex) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1298 |
throw new UncheckedIOException(ex); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1299 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1300 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1301 |
|
42824 | 1302 |
@Test |
1303 |
public void testUnboundLookup(Path base) throws Exception { |
|
1304 |
Path src = base.resolve("src"); |
|
1305 |
||
1306 |
tb.writeJavaFiles(src, |
|
1307 |
"package impl.conflict.src; public class Impl { }"); |
|
1308 |
||
1309 |
Path moduleSrc = base.resolve("module-src"); |
|
1310 |
Path m1 = moduleSrc.resolve("m1x"); |
|
1311 |
Path m2 = moduleSrc.resolve("m2x"); |
|
1312 |
||
1313 |
Path classes = base.resolve("classes"); |
|
1314 |
Path cpClasses = base.resolve("cpClasses"); |
|
1315 |
||
1316 |
Files.createDirectories(classes); |
|
1317 |
Files.createDirectories(cpClasses); |
|
1318 |
||
1319 |
tb.writeJavaFiles(m1, |
|
1320 |
"module m1x { }", |
|
1321 |
"package impl1; public class Impl { }", |
|
1322 |
"package impl.conflict.module; class Impl { }", |
|
1323 |
"package impl.conflict.clazz; public class pkg { public static class I { } }", |
|
43149 | 1324 |
"package impl.conflict.src; public class Impl { }", |
1325 |
"package nested.pack.pack; public class Impl { }", |
|
1326 |
"package unique.nested; public class Impl { }"); |
|
42824 | 1327 |
|
1328 |
tb.writeJavaFiles(m2, |
|
1329 |
"module m2x { }", |
|
1330 |
"package impl2; public class Impl { }", |
|
1331 |
"package impl.conflict.module; class Impl { }", |
|
43149 | 1332 |
"package impl.conflict; public class clazz { public static class pkg { } }", |
1333 |
"package nested.pack; public class Impl { }"); |
|
42824 | 1334 |
|
1335 |
//from source: |
|
43149 | 1336 |
String log = new JavacTask(tb) |
42824 | 1337 |
.options("--module-source-path", moduleSrc.toString(), |
1338 |
"--source-path", src.toString(), |
|
1339 |
"-processorpath", System.getProperty("test.class.path"), |
|
43149 | 1340 |
"-processor", UnboundLookup.class.getName(), |
1341 |
"-XDrawDiagnostics") |
|
42824 | 1342 |
.outdir(classes) |
1343 |
.files(findJavaFiles(moduleSrc)) |
|
1344 |
.run() |
|
43149 | 1345 |
.writeAll() |
1346 |
.getOutput(OutputKind.DIRECT); |
|
1347 |
||
1348 |
String moduleImplConflictString = |
|
1349 |
"- compiler.note.multiple.elements: getTypeElement, impl.conflict.module.Impl, m2x, m1x"; |
|
1350 |
String srcConflictString = |
|
1351 |
"- compiler.note.multiple.elements: getTypeElement, impl.conflict.src.Impl, m1x, unnamed module"; |
|
1352 |
||
1353 |
if (!log.contains(moduleImplConflictString) || |
|
1354 |
!log.contains(srcConflictString)) { |
|
1355 |
throw new AssertionError("Expected output not found: " + log); |
|
1356 |
} |
|
1357 |
||
1358 |
if (log.split(Pattern.quote(moduleImplConflictString)).length > 2) { |
|
1359 |
throw new AssertionError("Too many warnings in: " + log); |
|
1360 |
} |
|
42824 | 1361 |
|
1362 |
new JavacTask(tb) |
|
1363 |
.options("--source-path", src.toString()) |
|
1364 |
.outdir(cpClasses) |
|
1365 |
.files(findJavaFiles(src)) |
|
1366 |
.run() |
|
1367 |
.writeAll(); |
|
1368 |
||
1369 |
//from classfiles: |
|
1370 |
new JavacTask(tb) |
|
1371 |
.options("--module-path", classes.toString(), |
|
1372 |
"--class-path", cpClasses.toString(), |
|
1373 |
"--add-modules", "m1x,m2x", |
|
1374 |
"-processorpath", System.getProperty("test.class.path"), |
|
1375 |
"-processor", UnboundLookup.class.getName(), |
|
1376 |
"-proc:only") |
|
1377 |
.classes("java.lang.Object") |
|
1378 |
.run() |
|
1379 |
.writeAll(); |
|
1380 |
||
1381 |
//source 8: |
|
1382 |
new JavacTask(tb) |
|
1383 |
.options("--source-path", src.toString(), |
|
1384 |
"-source", "8", |
|
1385 |
"-processorpath", System.getProperty("test.class.path"), |
|
1386 |
"-processor", UnboundLookup8.class.getName()) |
|
1387 |
.outdir(cpClasses) |
|
1388 |
.files(findJavaFiles(src)) |
|
1389 |
.run() |
|
1390 |
.writeAll(); |
|
1391 |
||
51094
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1392 |
//from source: |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1393 |
new JavacTask(tb) |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1394 |
.options("--module-source-path", moduleSrc.toString(), |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1395 |
"--source-path", src.toString(), |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1396 |
"-processorpath", System.getProperty("test.class.path"), |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1397 |
"-processor", UnboundLookupGenerate.class.getName(), |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1398 |
"-XDrawDiagnostics") |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1399 |
.outdir(classes) |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1400 |
.files(findJavaFiles(moduleSrc)) |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1401 |
.run() |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1402 |
.writeAll() |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1403 |
.getOutput(OutputKind.DIRECT); |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1404 |
|
42824 | 1405 |
} |
1406 |
||
1407 |
@SupportedAnnotationTypes("*") |
|
1408 |
public static final class UnboundLookup extends AbstractProcessor { |
|
1409 |
||
1410 |
@Override |
|
1411 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
1412 |
assertTypeElementExists("impl1.Impl", "m1x"); |
|
1413 |
assertPackageElementExists("impl1", "m1x"); |
|
1414 |
assertTypeElementExists("impl2.Impl", "m2x"); |
|
1415 |
assertTypeElementExists("impl.conflict.clazz.pkg.I", "m1x"); |
|
1416 |
assertTypeElementExists("impl.conflict.clazz", "m2x"); |
|
1417 |
assertPackageElementExists("impl.conflict.clazz", "m1x"); |
|
1418 |
assertPackageElementExists("impl2", "m2x"); |
|
43149 | 1419 |
assertPackageElementExists("nested.pack.pack", "m1x"); |
1420 |
assertPackageElementExists("nested.pack", "m2x"); |
|
1421 |
assertTypeElementExists("unique.nested.Impl", "m1x"); |
|
42824 | 1422 |
assertTypeElementNotFound("impl.conflict.module.Impl"); |
43149 | 1423 |
assertTypeElementNotFound("impl.conflict.module.Impl"); //check that the warning/note is produced only once |
42824 | 1424 |
assertPackageElementNotFound("impl.conflict.module"); |
1425 |
assertTypeElementNotFound("impl.conflict.src.Impl"); |
|
1426 |
assertPackageElementNotFound("impl.conflict.src"); |
|
1427 |
assertTypeElementNotFound("impl.conflict.clazz.pkg"); |
|
43149 | 1428 |
assertPackageElementNotFound("unique"); //do not return packages without members in module mode |
1429 |
assertTypeElementNotFound("nested"); //cannot distinguish between m1x and m2x |
|
42824 | 1430 |
|
1431 |
return false; |
|
1432 |
} |
|
1433 |
||
1434 |
private void assertTypeElementExists(String name, String expectedModule) { |
|
1435 |
assertElementExists(name, "class", processingEnv.getElementUtils() :: getTypeElement, expectedModule); |
|
1436 |
} |
|
1437 |
||
1438 |
private void assertPackageElementExists(String name, String expectedModule) { |
|
1439 |
assertElementExists(name, "package", processingEnv.getElementUtils() :: getPackageElement, expectedModule); |
|
1440 |
} |
|
1441 |
||
1442 |
private void assertElementExists(String name, String type, Function<String, Element> getter, String expectedModule) { |
|
1443 |
Element clazz = getter.apply(name); |
|
1444 |
||
1445 |
if (clazz == null) { |
|
1446 |
throw new AssertionError("No " + name + " " + type + " found."); |
|
1447 |
} |
|
1448 |
||
1449 |
ModuleElement mod = processingEnv.getElementUtils().getModuleOf(clazz); |
|
1450 |
||
1451 |
if (!mod.getQualifiedName().contentEquals(expectedModule)) { |
|
1452 |
throw new AssertionError(name + " found in an unexpected module: " + mod.getQualifiedName()); |
|
1453 |
} |
|
1454 |
} |
|
1455 |
||
1456 |
private void assertTypeElementNotFound(String name) { |
|
1457 |
assertElementNotFound(name, processingEnv.getElementUtils() :: getTypeElement); |
|
1458 |
} |
|
1459 |
||
1460 |
private void assertPackageElementNotFound(String name) { |
|
1461 |
assertElementNotFound(name, processingEnv.getElementUtils() :: getPackageElement); |
|
1462 |
} |
|
1463 |
||
1464 |
private void assertElementNotFound(String name, Function<String, Element> getter) { |
|
1465 |
Element found = getter.apply(name); |
|
1466 |
||
1467 |
if (found != null) { |
|
1468 |
fail("Element found unexpectedly: " + found); |
|
1469 |
} |
|
1470 |
} |
|
1471 |
||
1472 |
@Override |
|
1473 |
public SourceVersion getSupportedSourceVersion() { |
|
1474 |
return SourceVersion.latest(); |
|
1475 |
} |
|
1476 |
||
1477 |
} |
|
1478 |
||
1479 |
@SupportedAnnotationTypes("*") |
|
1480 |
public static final class UnboundLookup8 extends AbstractProcessor { |
|
1481 |
||
1482 |
@Override |
|
1483 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
1484 |
if (processingEnv.getElementUtils().getTypeElement("impl.conflict.src.Impl") == null) { |
|
1485 |
throw new AssertionError("impl.conflict.src.Impl."); |
|
1486 |
} |
|
1487 |
||
1488 |
if (processingEnv.getElementUtils().getModuleElement("java.base") != null) { |
|
1489 |
throw new AssertionError("getModuleElement != null for -source 8"); |
|
1490 |
} |
|
1491 |
||
1492 |
return false; |
|
1493 |
} |
|
1494 |
||
1495 |
@Override |
|
1496 |
public SourceVersion getSupportedSourceVersion() { |
|
1497 |
return SourceVersion.latest(); |
|
1498 |
} |
|
1499 |
||
1500 |
} |
|
1501 |
||
51094
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1502 |
@SupportedAnnotationTypes("*") |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1503 |
public static final class UnboundLookupGenerate extends AbstractProcessor { |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1504 |
|
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1505 |
@Override |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1506 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1507 |
if (processingEnv.getElementUtils().getTypeElement("nue.Nue") == null) { |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1508 |
try (Writer w = processingEnv.getFiler().createSourceFile("m1x/nue.Nue").openWriter()) { |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1509 |
w.write("package nue; public class Nue {}"); |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1510 |
} catch (IOException ex) { |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1511 |
throw new IllegalStateException(ex); |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1512 |
} |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1513 |
} |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1514 |
|
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1515 |
return false; |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1516 |
} |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1517 |
|
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1518 |
@Override |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1519 |
public SourceVersion getSupportedSourceVersion() { |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1520 |
return SourceVersion.latest(); |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1521 |
} |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1522 |
|
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1523 |
} |
a49d106e9b7c
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents:
50967
diff
changeset
|
1524 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1525 |
@Test |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1526 |
public void testWrongDefaultTargetModule(Path base) throws Exception { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1527 |
Path src = base.resolve("src"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1528 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1529 |
tb.writeJavaFiles(src, |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1530 |
"package test; public class Test { }"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1531 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1532 |
Path classes = base.resolve("classes"); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1533 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1534 |
Files.createDirectories(classes); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1535 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1536 |
List<String> log = new JavacTask(tb) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1537 |
.options("--default-module-for-created-files=m!", |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1538 |
"-XDrawDiagnostics") |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1539 |
.outdir(classes) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1540 |
.files(findJavaFiles(src)) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1541 |
.run(Task.Expect.FAIL) |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1542 |
.writeAll() |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1543 |
.getOutputLines(OutputKind.DIRECT); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1544 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1545 |
List<String> expected = Arrays.asList( |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1546 |
"- compiler.err.bad.name.for.option: --default-module-for-created-files, m!" |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1547 |
); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1548 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1549 |
if (!log.equals(expected)) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1550 |
throw new AssertionError("Expected output not found."); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1551 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1552 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1553 |
|
36526 | 1554 |
private static void assertNonNull(String msg, Object val) { |
1555 |
if (val == null) { |
|
1556 |
throw new AssertionError(msg); |
|
1557 |
} |
|
1558 |
} |
|
1559 |
||
1560 |
private static void assertNull(String msg, Object val) { |
|
1561 |
if (val != null) { |
|
1562 |
throw new AssertionError(msg); |
|
1563 |
} |
|
1564 |
} |
|
1565 |
||
1566 |
private static void assertEquals(Object expected, Object actual) { |
|
1567 |
if (!Objects.equals(expected, actual)) { |
|
1568 |
throw new AssertionError("expected: " + expected + "; actual=" + actual); |
|
1569 |
} |
|
1570 |
} |
|
1571 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1572 |
private static void assertFileExists(Path base, String... pathElements) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1573 |
Path file = resolveFile(base, pathElements); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1574 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1575 |
if (!Files.exists(file)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1576 |
throw new AssertionError("Expected file: " + file + " exist, but it does not."); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1577 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1578 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1579 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1580 |
private static void assertFileNotExists(Path base, String... pathElements) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1581 |
Path file = resolveFile(base, pathElements); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1582 |
|
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1583 |
if (Files.exists(file)) { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1584 |
throw new AssertionError("Expected file: " + file + " exist, but it does not."); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1585 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1586 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
43585
diff
changeset
|
1587 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1588 |
static Path resolveFile(Path base, String... pathElements) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1589 |
Path file = base; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1590 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1591 |
for (String el : pathElements) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1592 |
file = file.resolve(el); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1593 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1594 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1595 |
return file; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1596 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1597 |
|
42824 | 1598 |
private static void fail(String msg) { |
1599 |
throw new AssertionError(msg); |
|
1600 |
} |
|
1601 |
||
36526 | 1602 |
} |