author | jlahoda |
Fri, 06 Jan 2017 14:16:45 +0100 | |
changeset 43037 | 3e1520a857fa |
parent 42824 | 89b14017e8d6 |
child 43149 | 047a57b0839a |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
43037
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
26 |
* @bug 8133884 8162711 8133896 8172158 |
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; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
40 |
import java.io.Writer; |
36526 | 41 |
import java.nio.file.Files; |
42 |
import java.nio.file.Path; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
43 |
import java.nio.file.Paths; |
36526 | 44 |
import java.util.Arrays; |
45 |
import java.util.HashMap; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
46 |
import java.util.HashSet; |
36526 | 47 |
import java.util.List; |
48 |
import java.util.Map; |
|
49 |
import java.util.Objects; |
|
50 |
import java.util.Set; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
51 |
import java.util.concurrent.Callable; |
42824 | 52 |
import java.util.function.Function; |
36526 | 53 |
import java.util.stream.Collectors; |
54 |
||
55 |
import javax.annotation.processing.AbstractProcessor; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
56 |
import javax.annotation.processing.Filer; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
57 |
import javax.annotation.processing.FilerException; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
58 |
import javax.annotation.processing.Messager; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
59 |
import javax.annotation.processing.ProcessingEnvironment; |
36526 | 60 |
import javax.annotation.processing.RoundEnvironment; |
61 |
import javax.annotation.processing.SupportedAnnotationTypes; |
|
62 |
import javax.annotation.processing.SupportedOptions; |
|
63 |
import javax.lang.model.SourceVersion; |
|
64 |
import javax.lang.model.element.Element; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
65 |
import javax.lang.model.element.ElementKind; |
36526 | 66 |
import javax.lang.model.element.ModuleElement; |
67 |
import javax.lang.model.element.ModuleElement.ProvidesDirective; |
|
68 |
import javax.lang.model.element.ModuleElement.UsesDirective; |
|
69 |
import javax.lang.model.element.PackageElement; |
|
70 |
import javax.lang.model.element.TypeElement; |
|
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
71 |
import javax.lang.model.element.VariableElement; |
36526 | 72 |
import javax.lang.model.type.TypeKind; |
73 |
import javax.lang.model.util.ElementFilter; |
|
74 |
import javax.lang.model.util.ElementScanner9; |
|
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
75 |
import javax.tools.Diagnostic.Kind; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
76 |
import javax.tools.FileObject; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
77 |
import javax.tools.JavaCompiler; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
78 |
import javax.tools.JavaCompiler.CompilationTask; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
79 |
import javax.tools.JavaFileManager; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
80 |
import javax.tools.JavaFileManager.Location; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
81 |
import javax.tools.JavaFileObject; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
82 |
import javax.tools.StandardJavaFileManager; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
83 |
import javax.tools.StandardLocation; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
84 |
import javax.tools.ToolProvider; |
36526 | 85 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
86 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
87 |
import toolbox.Task; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
88 |
import toolbox.Task.Mode; |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
89 |
import toolbox.Task.OutputKind; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
90 |
|
36526 | 91 |
public class AnnotationProcessing extends ModuleTestBase { |
92 |
||
93 |
public static void main(String... args) throws Exception { |
|
94 |
new AnnotationProcessing().runTests(); |
|
95 |
} |
|
96 |
||
97 |
@Test |
|
37758 | 98 |
public void testAPSingleModule(Path base) throws Exception { |
36526 | 99 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
100 |
Path m1 = moduleSrc.resolve("m1x"); |
36526 | 101 |
|
102 |
Path classes = base.resolve("classes"); |
|
103 |
||
104 |
Files.createDirectories(classes); |
|
105 |
||
106 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
107 |
"module m1x { }", |
36526 | 108 |
"package impl; public class Impl { }"); |
109 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
110 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
111 |
.options("--module-source-path", moduleSrc.toString(), |
36526 | 112 |
"-processor", AP.class.getName(), |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
113 |
"-AexpectedEnclosedElements=m1x=>impl") |
36526 | 114 |
.outdir(classes) |
115 |
.files(findJavaFiles(moduleSrc)) |
|
116 |
.run() |
|
117 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
118 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 119 |
|
120 |
if (!log.isEmpty()) |
|
121 |
throw new AssertionError("Unexpected output: " + log); |
|
122 |
} |
|
123 |
||
124 |
@Test |
|
37758 | 125 |
public void testAPMultiModule(Path base) throws Exception { |
36526 | 126 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
127 |
Path m1 = moduleSrc.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
128 |
Path m2 = moduleSrc.resolve("m2x"); |
36526 | 129 |
|
130 |
Path classes = base.resolve("classes"); |
|
131 |
||
132 |
Files.createDirectories(classes); |
|
133 |
||
134 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
135 |
"module m1x { }", |
36526 | 136 |
"package impl1; public class Impl1 { }"); |
137 |
||
138 |
tb.writeJavaFiles(m2, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
139 |
"module m2x { }", |
36526 | 140 |
"package impl2; public class Impl2 { }"); |
141 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
142 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
143 |
.options("--module-source-path", moduleSrc.toString(), |
36526 | 144 |
"-processor", AP.class.getName(), |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
145 |
"-AexpectedEnclosedElements=m1x=>impl1,m2x=>impl2") |
36526 | 146 |
.outdir(classes) |
147 |
.files(findJavaFiles(moduleSrc)) |
|
148 |
.run() |
|
149 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
150 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 151 |
|
152 |
if (!log.isEmpty()) |
|
153 |
throw new AssertionError("Unexpected output: " + log); |
|
154 |
} |
|
155 |
||
156 |
@SupportedAnnotationTypes("*") |
|
157 |
@SupportedOptions("expectedEnclosedElements") |
|
158 |
public static final class AP extends AbstractProcessor { |
|
159 |
||
160 |
private Map<String, List<String>> module2ExpectedEnclosedElements; |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
161 |
private Set<String> seenModules = new HashSet<>(); |
36526 | 162 |
|
163 |
@Override |
|
164 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
165 |
if (module2ExpectedEnclosedElements == null) { |
|
166 |
module2ExpectedEnclosedElements = new HashMap<>(); |
|
167 |
||
168 |
String expectedEnclosedElements = |
|
169 |
processingEnv.getOptions().get("expectedEnclosedElements"); |
|
170 |
||
171 |
for (String moduleDef : expectedEnclosedElements.split(",")) { |
|
172 |
String[] module2Packages = moduleDef.split("=>"); |
|
173 |
||
174 |
module2ExpectedEnclosedElements.put(module2Packages[0], |
|
175 |
Arrays.asList(module2Packages[1].split(":"))); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
//verify ModuleType and ModuleSymbol behavior: |
|
180 |
for (Element root : roundEnv.getRootElements()) { |
|
181 |
ModuleElement module = processingEnv.getElementUtils().getModuleOf(root); |
|
182 |
||
183 |
assertEquals(TypeKind.MODULE, module.asType().getKind()); |
|
184 |
||
185 |
boolean[] seenModule = new boolean[1]; |
|
186 |
||
187 |
module.accept(new ElementScanner9<Void, Void>() { |
|
188 |
@Override |
|
189 |
public Void visitModule(ModuleElement e, Void p) { |
|
190 |
seenModule[0] = true; |
|
191 |
return null; |
|
192 |
} |
|
193 |
@Override |
|
194 |
public Void scan(Element e, Void p) { |
|
195 |
throw new AssertionError("Shouldn't get here."); |
|
196 |
} |
|
197 |
}, null); |
|
198 |
||
199 |
assertEquals(true, seenModule[0]); |
|
200 |
||
201 |
List<String> actualElements = |
|
202 |
module.getEnclosedElements() |
|
203 |
.stream() |
|
204 |
.map(s -> (PackageElement) s) |
|
205 |
.map(p -> p.getQualifiedName().toString()) |
|
206 |
.collect(Collectors.toList()); |
|
207 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
208 |
String moduleName = module.getQualifiedName().toString(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
209 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
210 |
assertEquals(module2ExpectedEnclosedElements.get(moduleName), |
36526 | 211 |
actualElements); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
212 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
213 |
seenModules.add(moduleName); |
36526 | 214 |
} |
215 |
||
216 |
if (roundEnv.processingOver()) { |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
217 |
assertEquals(module2ExpectedEnclosedElements.keySet(), seenModules); |
36526 | 218 |
} |
219 |
||
220 |
return false; |
|
221 |
} |
|
222 |
||
223 |
@Override |
|
224 |
public SourceVersion getSupportedSourceVersion() { |
|
225 |
return SourceVersion.latest(); |
|
226 |
} |
|
227 |
||
228 |
} |
|
229 |
||
230 |
@Test |
|
37758 | 231 |
public void testVerifyUsesProvides(Path base) throws Exception { |
36526 | 232 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
233 |
Path m1 = moduleSrc.resolve("m1x"); |
36526 | 234 |
|
235 |
Path classes = base.resolve("classes"); |
|
236 |
||
237 |
Files.createDirectories(classes); |
|
238 |
||
239 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
240 |
"module m1x { exports api; uses api.Api; provides api.Api with impl.Impl; }", |
36526 | 241 |
"package api; public class Api { }", |
242 |
"package impl; public class Impl extends api.Api { }"); |
|
243 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
244 |
String log = new JavacTask(tb) |
36526 | 245 |
.options("-doe", "-processor", VerifyUsesProvidesAP.class.getName()) |
246 |
.outdir(classes) |
|
247 |
.files(findJavaFiles(moduleSrc)) |
|
248 |
.run() |
|
249 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
250 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 251 |
|
252 |
if (!log.isEmpty()) |
|
253 |
throw new AssertionError("Unexpected output: " + log); |
|
254 |
} |
|
255 |
||
256 |
@SupportedAnnotationTypes("*") |
|
257 |
public static final class VerifyUsesProvidesAP extends AbstractProcessor { |
|
258 |
||
259 |
@Override |
|
260 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
261 |
TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api"); |
|
262 |
||
263 |
assertNonNull("Cannot find api.Api", api); |
|
264 |
||
265 |
ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement(); |
|
266 |
||
267 |
assertNonNull("modle is null", modle); |
|
268 |
||
269 |
List<? extends UsesDirective> uses = ElementFilter.usesIn(modle.getDirectives()); |
|
270 |
assertEquals(1, uses.size()); |
|
271 |
assertEquals("api.Api", uses.iterator().next().getService().getQualifiedName().toString()); |
|
272 |
||
273 |
List<? extends ProvidesDirective> provides = ElementFilter.providesIn(modle.getDirectives()); |
|
274 |
assertEquals(1, provides.size()); |
|
275 |
assertEquals("api.Api", provides.iterator().next().getService().getQualifiedName().toString()); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40311
diff
changeset
|
276 |
assertEquals("impl.Impl", provides.iterator().next().getImplementations().get(0).getQualifiedName().toString()); |
36526 | 277 |
|
278 |
return false; |
|
279 |
} |
|
280 |
||
281 |
@Override |
|
282 |
public SourceVersion getSupportedSourceVersion() { |
|
283 |
return SourceVersion.latest(); |
|
284 |
} |
|
285 |
||
286 |
} |
|
287 |
||
288 |
@Test |
|
37758 | 289 |
public void testPackageNoModule(Path base) throws Exception { |
36526 | 290 |
Path src = base.resolve("src"); |
291 |
Path classes = base.resolve("classes"); |
|
292 |
||
293 |
Files.createDirectories(classes); |
|
294 |
||
295 |
tb.writeJavaFiles(src, |
|
296 |
"package api; public class Api { }"); |
|
297 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
298 |
String log = new JavacTask(tb) |
36526 | 299 |
.options("-processor", VerifyPackageNoModule.class.getName(), |
300 |
"-source", "8", |
|
301 |
"-Xlint:-options") |
|
302 |
.outdir(classes) |
|
303 |
.files(findJavaFiles(src)) |
|
304 |
.run() |
|
305 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
306 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 307 |
|
308 |
if (!log.isEmpty()) |
|
309 |
throw new AssertionError("Unexpected output: " + log); |
|
310 |
} |
|
311 |
||
312 |
@SupportedAnnotationTypes("*") |
|
313 |
public static final class VerifyPackageNoModule extends AbstractProcessor { |
|
314 |
||
315 |
@Override |
|
316 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
317 |
TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api"); |
|
318 |
||
319 |
assertNonNull("Cannot find api.Api", api); |
|
320 |
||
321 |
ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement(); |
|
322 |
||
323 |
assertNull("modle is not null", modle); |
|
324 |
||
325 |
return false; |
|
326 |
} |
|
327 |
||
328 |
@Override |
|
329 |
public SourceVersion getSupportedSourceVersion() { |
|
330 |
return SourceVersion.latest(); |
|
331 |
} |
|
332 |
||
333 |
} |
|
334 |
||
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
335 |
@Test |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
336 |
public void testQualifiedClassForProcessing(Path base) throws Exception { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
337 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
338 |
Path m1 = moduleSrc.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
339 |
Path m2 = moduleSrc.resolve("m2x"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
340 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
341 |
Path classes = base.resolve("classes"); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
342 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
343 |
Files.createDirectories(classes); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
344 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
345 |
tb.writeJavaFiles(m1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
346 |
"module m1x { }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
347 |
"package impl; public class Impl { int m1x; }"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
348 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
349 |
tb.writeJavaFiles(m2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
350 |
"module m2x { }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
351 |
"package impl; public class Impl { int m2x; }"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
352 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
353 |
new JavacTask(tb) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
354 |
.options("--module-source-path", moduleSrc.toString()) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
355 |
.outdir(classes) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
356 |
.files(findJavaFiles(moduleSrc)) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
357 |
.run() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
358 |
.writeAll() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
359 |
.getOutput(Task.OutputKind.DIRECT); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
360 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
361 |
List<String> expected = Arrays.asList("Note: field: m1x"); |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
362 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
363 |
for (Mode mode : new Mode[] {Mode.API, Mode.CMDLINE}) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
364 |
List<String> log = new JavacTask(tb, mode) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
365 |
.options("-processor", QualifiedClassForProcessing.class.getName(), |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
366 |
"--module-path", classes.toString()) |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
367 |
.classes("m1x/impl.Impl") |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
368 |
.outdir(classes) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
369 |
.run() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
370 |
.writeAll() |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
371 |
.getOutputLines(Task.OutputKind.DIRECT); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
372 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
373 |
if (!expected.equals(log)) |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
374 |
throw new AssertionError("Unexpected output: " + log); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
375 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
376 |
} |
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 |
@SupportedAnnotationTypes("*") |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
379 |
public static final class QualifiedClassForProcessing extends AbstractProcessor { |
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 |
@Override |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
382 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
383 |
if (processingEnv.getElementUtils().getModuleElement("m1x") == null) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
384 |
throw new AssertionError("No m1x module found."); |
40311
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 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
387 |
Messager messager = processingEnv.getMessager(); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
388 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
389 |
for (TypeElement clazz : ElementFilter.typesIn(roundEnv.getRootElements())) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
390 |
for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
391 |
messager.printMessage(Kind.NOTE, "field: " + field.getSimpleName()); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
392 |
} |
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 |
|
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
395 |
return false; |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
396 |
} |
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 |
@Override |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
399 |
public SourceVersion getSupportedSourceVersion() { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
400 |
return SourceVersion.latest(); |
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 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
404 |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
405 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
406 |
public void testModuleInRootElements(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
407 |
Path moduleSrc = base.resolve("module-src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
408 |
Path m1 = moduleSrc.resolve("m1"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
409 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
410 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
411 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
412 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
413 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
414 |
tb.writeJavaFiles(m1, |
42823 | 415 |
"module m1x { exports api; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
416 |
"package api; public class Api { }"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
417 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
418 |
List<String> log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
419 |
.options("-processor", ModuleInRootElementsAP.class.getName()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
420 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
421 |
.files(findJavaFiles(moduleSrc)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
422 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
423 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
424 |
.getOutputLines(Task.OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
425 |
|
42823 | 426 |
assertEquals(Arrays.asList("module: m1x"), log); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
427 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
428 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
429 |
@SupportedAnnotationTypes("*") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
430 |
public static final class ModuleInRootElementsAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
431 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
432 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
433 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
434 |
roundEnv.getRootElements() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
435 |
.stream() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
436 |
.filter(el -> el.getKind() == ElementKind.MODULE) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
437 |
.forEach(mod -> System.err.println("module: " + mod.getSimpleName())); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
438 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
439 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
440 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
441 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
442 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
443 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
444 |
return SourceVersion.latest(); |
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 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
448 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
449 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
450 |
public void testAnnotationsInModuleInfo(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
451 |
Path moduleSrc = base.resolve("module-src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
452 |
Path m1 = moduleSrc.resolve("m1"); |
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 |
tb.writeJavaFiles(m1, |
42823 | 455 |
"@Deprecated module m1x { }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
456 |
|
42823 | 457 |
Path m2 = moduleSrc.resolve("m2x"); |
42815
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(m2, |
42823 | 460 |
"@SuppressWarnings(\"\") module m2x { }"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
461 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
462 |
Path classes = base.resolve("classes"); |
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 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
465 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
466 |
List<String> log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
467 |
.options("-processor", AnnotationsInModuleInfoPrint.class.getName()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
468 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
469 |
.files(findJavaFiles(m1)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
470 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
471 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
472 |
.getOutputLines(Task.OutputKind.DIRECT); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
473 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
474 |
List<String> expectedLog = Arrays.asList("Note: AP Invoked", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
475 |
"Note: AP Invoked"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
476 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
477 |
assertEquals(expectedLog, log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
478 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
479 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
480 |
.options("-processor", AnnotationsInModuleInfoFail.class.getName()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
481 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
482 |
.files(findJavaFiles(m2)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
483 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
484 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
485 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
486 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
487 |
@SupportedAnnotationTypes("java.lang.Deprecated") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
488 |
public static final class AnnotationsInModuleInfoPrint extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
489 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
490 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
491 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
492 |
processingEnv.getMessager().printMessage(Kind.NOTE, "AP Invoked"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
493 |
return false; |
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 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
496 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
497 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
498 |
return SourceVersion.latest(); |
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 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
502 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
503 |
@SupportedAnnotationTypes("java.lang.Deprecated") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
504 |
public static final class AnnotationsInModuleInfoFail extends AbstractProcessor { |
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 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
507 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
508 |
throw new AssertionError(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
509 |
} |
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 SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
513 |
return SourceVersion.latest(); |
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 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
517 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
518 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
519 |
public void testGenerateInMultiModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
520 |
Path moduleSrc = base.resolve("module-src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
521 |
Path classes = base.resolve("classes"); |
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 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
524 |
|
42823 | 525 |
Path m1 = moduleSrc.resolve("m1x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
526 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
527 |
tb.writeJavaFiles(m1, |
42823 | 528 |
"module m1x { exports api1; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
529 |
"package api1; public class Api { GenApi ga; impl.Impl i; }"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
530 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
531 |
writeFile("1", m1, "api1", "api"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
532 |
writeFile("1", m1, "impl", "impl"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
533 |
|
42823 | 534 |
Path m2 = moduleSrc.resolve("m2x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
535 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
536 |
tb.writeJavaFiles(m2, |
42823 | 537 |
"module m2x { requires m1x; exports api2; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
538 |
"package api2; public class Api { api1.GenApi ga1; GenApi qa2; impl.Impl i;}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
539 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
540 |
writeFile("2", m2, "api2", "api"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
541 |
writeFile("2", m2, "impl", "impl"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
542 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
543 |
for (FileType fileType : FileType.values()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
544 |
if (Files.isDirectory(classes)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
545 |
tb.cleanDirectory(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
546 |
} else { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
547 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
548 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
549 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
550 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
551 |
.options("-processor", MultiModeAPITestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
552 |
"--module-source-path", moduleSrc.toString(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
553 |
"-Afiletype=" + fileType.name()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
554 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
555 |
.files(findJavaFiles(moduleSrc)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
556 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
557 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
558 |
|
42823 | 559 |
assertFileExists(classes, "m1x", "api1", "GenApi.class"); |
560 |
assertFileExists(classes, "m1x", "impl", "Impl.class"); |
|
561 |
assertFileExists(classes, "m1x", "api1", "gen1"); |
|
562 |
assertFileExists(classes, "m2x", "api2", "GenApi.class"); |
|
563 |
assertFileExists(classes, "m2x", "impl", "Impl.class"); |
|
564 |
assertFileExists(classes, "m2x", "api2", "gen1"); |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
565 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
566 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
567 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
568 |
enum FileType { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
569 |
SOURCE, |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
570 |
CLASS; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
571 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
572 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
573 |
public static abstract class GeneratingAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
574 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
575 |
void createSource(CreateFileObject file, String name, String content) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
576 |
try (Writer out = file.create().openWriter()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
577 |
out.write(content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
578 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
579 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
580 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
581 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
582 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
583 |
void createClass(CreateFileObject file, String name, String content) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
584 |
String fileNameStub = name.replace(".", File.separator); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
585 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
586 |
try (OutputStream out = file.create().openOutputStream()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
587 |
Path scratch = Files.createDirectories(Paths.get("")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
588 |
Path scratchSrc = scratch.resolve(fileNameStub + ".java").toAbsolutePath(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
589 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
590 |
Files.createDirectories(scratchSrc.getParent()); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
591 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
592 |
try (Writer w = Files.newBufferedWriter(scratchSrc)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
593 |
w.write(content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
594 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
595 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
596 |
Path scratchClasses = scratch.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
597 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
598 |
Files.createDirectories(scratchClasses); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
599 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
600 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
601 |
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
602 |
List<String> options = Arrays.asList("-d", scratchClasses.toString()); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
603 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(scratchSrc); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
604 |
CompilationTask task = comp.getTask(null, fm, null, options, null, files); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
605 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
606 |
if (!task.call()) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
607 |
throw new AssertionError("compilation failed"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
608 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
609 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
610 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
611 |
Path classfile = scratchClasses.resolve(fileNameStub + ".class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
612 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
613 |
Files.copy(classfile, out); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
614 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
615 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
616 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
617 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
618 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
619 |
void doReadResource(CreateFileObject file, String expectedContent) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
620 |
try { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
621 |
StringBuilder actualContent = new StringBuilder(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
622 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
623 |
try (Reader r = file.create().openReader(true)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
624 |
int read; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
625 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
626 |
while ((read = r.read()) != (-1)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
627 |
actualContent.append((char) read); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
628 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
629 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
630 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
631 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
632 |
assertEquals(expectedContent, actualContent.toString()); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
633 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
634 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
635 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
636 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
637 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
638 |
public interface CreateFileObject { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
639 |
public FileObject create() throws IOException; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
640 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
641 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
642 |
void expectFilerException(Callable<Object> c) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
643 |
try { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
644 |
c.call(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
645 |
throw new AssertionError("Expected exception not thrown"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
646 |
} catch (FilerException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
647 |
//expected |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
648 |
} catch (Exception ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
649 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
650 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
651 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
652 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
653 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
654 |
public SourceVersion getSupportedSourceVersion() { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
655 |
return SourceVersion.latest(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
656 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
657 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
658 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
659 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
660 |
@SupportedAnnotationTypes("*") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
661 |
@SupportedOptions({"filetype", "modulename"}) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
662 |
public static final class MultiModeAPITestAP extends GeneratingAP { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
663 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
664 |
int round; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
665 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
666 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
667 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
668 |
if (round++ != 0) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
669 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
670 |
|
42823 | 671 |
createClass("m1x", "api1.GenApi", "package api1; public class GenApi {}"); |
672 |
createClass("m1x", "impl.Impl", "package impl; public class Impl {}"); |
|
673 |
createClass("m2x", "api2.GenApi", "package api2; public class GenApi {}"); |
|
674 |
createClass("m2x", "impl.Impl", "package impl; public class Impl {}"); |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
675 |
|
42823 | 676 |
createResource("m1x", "api1", "gen1"); |
677 |
createResource("m2x", "api2", "gen1"); |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
678 |
|
42823 | 679 |
readResource("m1x", "api1", "api", "1"); |
680 |
readResource("m1x", "impl", "impl", "1"); |
|
681 |
readResource("m2x", "api2", "api", "2"); |
|
682 |
readResource("m2x", "impl", "impl", "2"); |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
683 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
684 |
Filer filer = processingEnv.getFiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
685 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
686 |
expectFilerException(() -> filer.createSourceFile("fail.Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
687 |
expectFilerException(() -> filer.createClassFile("fail.Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
688 |
expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "fail", "fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
689 |
expectFilerException(() -> filer.getResource(StandardLocation.MODULE_SOURCE_PATH, "fail", "fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
690 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
691 |
//must not generate to unnamed package: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
692 |
expectFilerException(() -> filer.createSourceFile("m1/Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
693 |
expectFilerException(() -> filer.createClassFile("m1/Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
694 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
695 |
//cannot generate resources to modules that are not root modules: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
696 |
expectFilerException(() -> filer.createSourceFile("java.base/fail.Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
697 |
expectFilerException(() -> filer.createClassFile("java.base/fail.Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
698 |
expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "java.base/fail", "Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
699 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
700 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
701 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
702 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
703 |
void createClass(String expectedModule, String name, String content) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
704 |
Filer filer = processingEnv.getFiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
705 |
FileType filetype = FileType.valueOf(processingEnv.getOptions().getOrDefault("filetype", "")); |
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 |
switch (filetype) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
708 |
case SOURCE: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
709 |
createSource(() -> filer.createSourceFile(expectedModule + "/" + name), name, content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
710 |
break; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
711 |
case CLASS: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
712 |
createClass(() -> filer.createClassFile(expectedModule + "/" + name), name, content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
713 |
break; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
714 |
default: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
715 |
throw new AssertionError("Unexpected filetype: " + filetype); |
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 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
718 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
719 |
void createResource(String expectedModule, String pkg, String relName) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
720 |
try { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
721 |
Filer filer = processingEnv.getFiler(); |
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 |
filer.createResource(StandardLocation.CLASS_OUTPUT, expectedModule + "/" + pkg, relName) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
724 |
.openOutputStream() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
725 |
.close(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
726 |
} catch (IOException ex) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
727 |
throw new IllegalStateException(ex); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
728 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
729 |
} |
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 |
void readResource(String expectedModule, String pkg, String relName, String expectedContent) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
732 |
Filer filer = processingEnv.getFiler(); |
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 |
doReadResource(() -> filer.getResource(StandardLocation.MODULE_SOURCE_PATH, expectedModule + "/" + pkg, relName), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
735 |
expectedContent); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
736 |
} |
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 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
739 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
740 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
741 |
public void testGenerateInSingleNameModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
742 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
743 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
744 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
745 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
746 |
Path m1 = base.resolve("module-src"); |
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 |
tb.writeJavaFiles(m1, |
42823 | 749 |
"module m1x { }"); |
42815
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 |
writeFile("3", m1, "impl", "resource"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
752 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
753 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
754 |
.options("-processor", SingleNameModeAPITestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
755 |
"-sourcepath", m1.toString()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
756 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
757 |
.files(findJavaFiles(m1)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
758 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
759 |
.writeAll(); |
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 |
assertFileExists(classes, "impl", "Impl1.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
762 |
assertFileExists(classes, "impl", "Impl2.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
763 |
assertFileExists(classes, "impl", "Impl3"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
764 |
assertFileExists(classes, "impl", "Impl4.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
765 |
assertFileExists(classes, "impl", "Impl5.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
766 |
assertFileExists(classes, "impl", "Impl6"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
767 |
assertFileExists(classes, "impl", "Impl7.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
768 |
assertFileExists(classes, "impl", "Impl8.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
769 |
assertFileExists(classes, "impl", "Impl9"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
770 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
771 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
772 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
773 |
@SupportedAnnotationTypes("*") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
774 |
public static final class SingleNameModeAPITestAP extends GeneratingAP { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
775 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
776 |
int round; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
777 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
778 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
779 |
public synchronized void init(ProcessingEnvironment processingEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
780 |
super.init(processingEnv); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
781 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
782 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
783 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
784 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
785 |
if (round++ != 0) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
786 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
787 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
788 |
Filer filer = processingEnv.getFiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
789 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
790 |
createSource(() -> filer.createSourceFile("impl.Impl1"), "impl.Impl1", "package impl; class Impl1 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
791 |
createClass(() -> filer.createClassFile("impl.Impl2"), "impl.Impl2", "package impl; class Impl2 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
792 |
createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "impl", "Impl3"), "impl.Impl3", ""); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
793 |
doReadResource(() -> filer.getResource(StandardLocation.SOURCE_PATH, "impl", "resource"), "3"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
794 |
|
42823 | 795 |
createSource(() -> filer.createSourceFile("m1x/impl.Impl4"), "impl.Impl4", "package impl; class Impl4 {}"); |
796 |
createClass(() -> filer.createClassFile("m1x/impl.Impl5"), "impl.Impl5", "package impl; class Impl5 {}"); |
|
797 |
createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "m1x/impl", "Impl6"), "impl.Impl6", ""); |
|
798 |
doReadResource(() -> filer.getResource(StandardLocation.SOURCE_PATH, "m1x/impl", "resource"), "3"); |
|
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
799 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
800 |
TypeElement jlObject = processingEnv.getElementUtils().getTypeElement("java.lang.Object"); |
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 |
//"broken" originating element: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
803 |
createSource(() -> filer.createSourceFile("impl.Impl7", jlObject), "impl.Impl7", "package impl; class Impl7 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
804 |
createClass(() -> filer.createClassFile("impl.Impl8", jlObject), "impl.Impl8", "package impl; class Impl8 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
805 |
createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "impl", "Impl9", jlObject), "impl.Impl9", ""); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
806 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
807 |
//must not generate to unnamed package: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
808 |
expectFilerException(() -> filer.createSourceFile("Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
809 |
expectFilerException(() -> filer.createClassFile("Fail")); |
42823 | 810 |
expectFilerException(() -> filer.createSourceFile("m1x/Fail")); |
811 |
expectFilerException(() -> filer.createClassFile("m1x/Fail")); |
|
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 |
//cannot generate resources to modules that are not root modules: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
814 |
expectFilerException(() -> filer.createSourceFile("java.base/fail.Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
815 |
expectFilerException(() -> filer.createClassFile("java.base/fail.Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
816 |
expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "java.base/fail", "Fail")); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
817 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
818 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
819 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
820 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
821 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
822 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
823 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
824 |
public void testGenerateInUnnamedModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
825 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
826 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
827 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
828 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
829 |
Path src = base.resolve("src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
830 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
831 |
tb.writeJavaFiles(src, |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
832 |
"class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
833 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
834 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
835 |
.options("-processor", UnnamedModeAPITestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
836 |
"-sourcepath", src.toString()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
837 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
838 |
.files(findJavaFiles(src)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
839 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
840 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
841 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
842 |
assertFileExists(classes, "Impl1.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
843 |
assertFileExists(classes, "Impl2.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
844 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
845 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
846 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
847 |
public void testGenerateInNoModeAPI(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
848 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
849 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
850 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
851 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
852 |
Path src = base.resolve("src"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
853 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
854 |
tb.writeJavaFiles(src, |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
855 |
"class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
856 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
857 |
new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
858 |
.options("-processor", UnnamedModeAPITestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
859 |
"-source", "8", "-target", "8", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
860 |
"-sourcepath", src.toString()) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
861 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
862 |
.files(findJavaFiles(src)) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
863 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
864 |
.writeAll(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
865 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
866 |
assertFileExists(classes, "Impl1.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
867 |
assertFileExists(classes, "Impl2.class"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
868 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
869 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
870 |
@SupportedAnnotationTypes("*") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
871 |
public static final class UnnamedModeAPITestAP extends GeneratingAP { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
872 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
873 |
int round; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
874 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
875 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
876 |
public synchronized void init(ProcessingEnvironment processingEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
877 |
super.init(processingEnv); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
878 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
879 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
880 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
881 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
882 |
if (round++ != 0) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
883 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
884 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
885 |
Filer filer = processingEnv.getFiler(); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
886 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
887 |
//must not generate to unnamed package: |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
888 |
createSource(() -> filer.createSourceFile("Impl1"), "Impl1", "class Impl1 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
889 |
createClass(() -> filer.createClassFile("Impl2"), "Impl2", "class Impl2 {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
890 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
891 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
892 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
893 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
894 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
895 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
896 |
@Test |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
897 |
public void testDisambiguateAnnotations(Path base) throws Exception { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
898 |
Path classes = base.resolve("classes"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
899 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
900 |
Files.createDirectories(classes); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
901 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
902 |
Path src = base.resolve("src"); |
42823 | 903 |
Path m1 = src.resolve("m1x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
904 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
905 |
tb.writeJavaFiles(m1, |
42823 | 906 |
"module m1x { exports api; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
907 |
"package api; public @interface A {}", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
908 |
"package api; public @interface B {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
909 |
|
42823 | 910 |
Path m2 = src.resolve("m2x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
911 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
912 |
tb.writeJavaFiles(m2, |
42823 | 913 |
"module m2x { exports api; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
914 |
"package api; public @interface A {}", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
915 |
"package api; public @interface B {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
916 |
|
42823 | 917 |
Path m3 = src.resolve("m3x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
918 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
919 |
tb.writeJavaFiles(m3, |
42823 | 920 |
"module m3x { requires m1x; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
921 |
"package impl; import api.*; @A @B public class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
922 |
|
42823 | 923 |
Path m4 = src.resolve("m4x"); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
924 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
925 |
tb.writeJavaFiles(m4, |
42823 | 926 |
"module m4x { requires m2x; }", |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
927 |
"package impl; import api.*; @A @B public class T {}"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
928 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
929 |
List<String> log; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
930 |
List<String> expected; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
931 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
932 |
log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
933 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
934 |
"--module-source-path", src.toString(), |
42823 | 935 |
"-m", "m1x,m2x") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
936 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
937 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
938 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
939 |
.getOutputLines(OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
940 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
941 |
expected = Arrays.asList(""); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
942 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
943 |
if (!expected.equals(log)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
944 |
throw new AssertionError("Output does not match; output: " + log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
945 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
946 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
947 |
log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
948 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
949 |
"--module-source-path", src.toString(), |
42823 | 950 |
"-m", "m3x") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
951 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
952 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
953 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
954 |
.getOutputLines(OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
955 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
956 |
expected = Arrays.asList("SelectAnnotationBTestAP", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
957 |
"SelectAnnotationBTestAP"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
958 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
959 |
if (!expected.equals(log)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
960 |
throw new AssertionError("Output does not match; output: " + log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
961 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
962 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
963 |
log = new JavacTask(tb) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
964 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(), |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
965 |
"--module-source-path", src.toString(), |
42823 | 966 |
"-m", "m4x") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
967 |
.outdir(classes) |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
968 |
.run() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
969 |
.writeAll() |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
970 |
.getOutputLines(OutputKind.STDERR); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
971 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
972 |
expected = Arrays.asList("SelectAnnotationATestAP", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
973 |
"SelectAnnotationBTestAP", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
974 |
"SelectAnnotationATestAP", |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
975 |
"SelectAnnotationBTestAP"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
976 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
977 |
if (!expected.equals(log)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
978 |
throw new AssertionError("Output does not match; output: " + log); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
979 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
980 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
981 |
|
43037
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
982 |
@Test |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
983 |
public void testDisambiguateAnnotationsNoModules(Path base) throws Exception { |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
984 |
Path classes = base.resolve("classes"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
985 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
986 |
Files.createDirectories(classes); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
987 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
988 |
Path src = base.resolve("src"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
989 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
990 |
tb.writeJavaFiles(src, |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
991 |
"package api; public @interface A {}", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
992 |
"package api; public @interface B {}", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
993 |
"package impl; import api.*; @A @B public class T {}"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
994 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
995 |
List<String> log = new JavacTask(tb) |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
996 |
.options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(), |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
997 |
"-source", "8", "-target", "8") |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
998 |
.outdir(classes) |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
999 |
.files(findJavaFiles(src)) |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1000 |
.run() |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1001 |
.writeAll() |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1002 |
.getOutputLines(OutputKind.STDERR); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1003 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1004 |
List<String> expected = Arrays.asList("SelectAnnotationATestAP", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1005 |
"SelectAnnotationBTestAP", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1006 |
"SelectAnnotationATestAP", |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1007 |
"SelectAnnotationBTestAP"); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1008 |
|
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1009 |
if (!expected.equals(log)) { |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1010 |
throw new AssertionError("Output does not match; output: " + log); |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1011 |
} |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1012 |
} |
3e1520a857fa
8172158: Annotation processor not run with -source <= 8
jlahoda
parents:
42824
diff
changeset
|
1013 |
|
42823 | 1014 |
@SupportedAnnotationTypes("m2x/api.A") |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1015 |
public static final class SelectAnnotationATestAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1016 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1017 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1018 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1019 |
System.err.println("SelectAnnotationATestAP"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1020 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1021 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1022 |
} |
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 |
} |
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 |
@SupportedAnnotationTypes("api.B") |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1027 |
public static final class SelectAnnotationBTestAP extends AbstractProcessor { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1028 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1029 |
@Override |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1030 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1031 |
System.err.println("SelectAnnotationBTestAP"); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1032 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1033 |
return false; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1034 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1035 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1036 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1037 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1038 |
private static void writeFile(String content, Path base, String... pathElements) throws IOException { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1039 |
Path file = resolveFile(base, pathElements); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1040 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1041 |
Files.createDirectories(file.getParent()); |
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 |
try (Writer out = Files.newBufferedWriter(file)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1044 |
out.append(content); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1045 |
} |
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 |
|
42824 | 1048 |
@Test |
1049 |
public void testUnboundLookup(Path base) throws Exception { |
|
1050 |
Path src = base.resolve("src"); |
|
1051 |
||
1052 |
tb.writeJavaFiles(src, |
|
1053 |
"package impl.conflict.src; public class Impl { }"); |
|
1054 |
||
1055 |
Path moduleSrc = base.resolve("module-src"); |
|
1056 |
Path m1 = moduleSrc.resolve("m1x"); |
|
1057 |
Path m2 = moduleSrc.resolve("m2x"); |
|
1058 |
||
1059 |
Path classes = base.resolve("classes"); |
|
1060 |
Path cpClasses = base.resolve("cpClasses"); |
|
1061 |
||
1062 |
Files.createDirectories(classes); |
|
1063 |
Files.createDirectories(cpClasses); |
|
1064 |
||
1065 |
tb.writeJavaFiles(m1, |
|
1066 |
"module m1x { }", |
|
1067 |
"package impl1; public class Impl { }", |
|
1068 |
"package impl.conflict.module; class Impl { }", |
|
1069 |
"package impl.conflict.clazz; public class pkg { public static class I { } }", |
|
1070 |
"package impl.conflict.src; public class Impl { }"); |
|
1071 |
||
1072 |
tb.writeJavaFiles(m2, |
|
1073 |
"module m2x { }", |
|
1074 |
"package impl2; public class Impl { }", |
|
1075 |
"package impl.conflict.module; class Impl { }", |
|
1076 |
"package impl.conflict; public class clazz { public static class pkg { } }"); |
|
1077 |
||
1078 |
//from source: |
|
1079 |
new JavacTask(tb) |
|
1080 |
.options("--module-source-path", moduleSrc.toString(), |
|
1081 |
"--source-path", src.toString(), |
|
1082 |
"-processorpath", System.getProperty("test.class.path"), |
|
1083 |
"-processor", UnboundLookup.class.getName()) |
|
1084 |
.outdir(classes) |
|
1085 |
.files(findJavaFiles(moduleSrc)) |
|
1086 |
.run() |
|
1087 |
.writeAll(); |
|
1088 |
||
1089 |
new JavacTask(tb) |
|
1090 |
.options("--source-path", src.toString()) |
|
1091 |
.outdir(cpClasses) |
|
1092 |
.files(findJavaFiles(src)) |
|
1093 |
.run() |
|
1094 |
.writeAll(); |
|
1095 |
||
1096 |
//from classfiles: |
|
1097 |
new JavacTask(tb) |
|
1098 |
.options("--module-path", classes.toString(), |
|
1099 |
"--class-path", cpClasses.toString(), |
|
1100 |
"--add-modules", "m1x,m2x", |
|
1101 |
"-processorpath", System.getProperty("test.class.path"), |
|
1102 |
"-processor", UnboundLookup.class.getName(), |
|
1103 |
"-proc:only") |
|
1104 |
.classes("java.lang.Object") |
|
1105 |
.run() |
|
1106 |
.writeAll(); |
|
1107 |
||
1108 |
//source 8: |
|
1109 |
new JavacTask(tb) |
|
1110 |
.options("--source-path", src.toString(), |
|
1111 |
"-source", "8", |
|
1112 |
"-processorpath", System.getProperty("test.class.path"), |
|
1113 |
"-processor", UnboundLookup8.class.getName()) |
|
1114 |
.outdir(cpClasses) |
|
1115 |
.files(findJavaFiles(src)) |
|
1116 |
.run() |
|
1117 |
.writeAll(); |
|
1118 |
||
1119 |
} |
|
1120 |
||
1121 |
@SupportedAnnotationTypes("*") |
|
1122 |
public static final class UnboundLookup extends AbstractProcessor { |
|
1123 |
||
1124 |
@Override |
|
1125 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
1126 |
assertTypeElementExists("impl1.Impl", "m1x"); |
|
1127 |
assertPackageElementExists("impl1", "m1x"); |
|
1128 |
assertTypeElementExists("impl2.Impl", "m2x"); |
|
1129 |
assertTypeElementExists("impl.conflict.clazz.pkg.I", "m1x"); |
|
1130 |
assertTypeElementExists("impl.conflict.clazz", "m2x"); |
|
1131 |
assertPackageElementExists("impl.conflict.clazz", "m1x"); |
|
1132 |
assertPackageElementExists("impl2", "m2x"); |
|
1133 |
assertTypeElementNotFound("impl.conflict.module.Impl"); |
|
1134 |
assertPackageElementNotFound("impl.conflict.module"); |
|
1135 |
assertTypeElementNotFound("impl.conflict.src.Impl"); |
|
1136 |
assertPackageElementNotFound("impl.conflict.src"); |
|
1137 |
assertTypeElementNotFound("impl.conflict.clazz.pkg"); |
|
1138 |
||
1139 |
return false; |
|
1140 |
} |
|
1141 |
||
1142 |
private void assertTypeElementExists(String name, String expectedModule) { |
|
1143 |
assertElementExists(name, "class", processingEnv.getElementUtils() :: getTypeElement, expectedModule); |
|
1144 |
} |
|
1145 |
||
1146 |
private void assertPackageElementExists(String name, String expectedModule) { |
|
1147 |
assertElementExists(name, "package", processingEnv.getElementUtils() :: getPackageElement, expectedModule); |
|
1148 |
} |
|
1149 |
||
1150 |
private void assertElementExists(String name, String type, Function<String, Element> getter, String expectedModule) { |
|
1151 |
Element clazz = getter.apply(name); |
|
1152 |
||
1153 |
if (clazz == null) { |
|
1154 |
throw new AssertionError("No " + name + " " + type + " found."); |
|
1155 |
} |
|
1156 |
||
1157 |
ModuleElement mod = processingEnv.getElementUtils().getModuleOf(clazz); |
|
1158 |
||
1159 |
if (!mod.getQualifiedName().contentEquals(expectedModule)) { |
|
1160 |
throw new AssertionError(name + " found in an unexpected module: " + mod.getQualifiedName()); |
|
1161 |
} |
|
1162 |
} |
|
1163 |
||
1164 |
private void assertTypeElementNotFound(String name) { |
|
1165 |
assertElementNotFound(name, processingEnv.getElementUtils() :: getTypeElement); |
|
1166 |
} |
|
1167 |
||
1168 |
private void assertPackageElementNotFound(String name) { |
|
1169 |
assertElementNotFound(name, processingEnv.getElementUtils() :: getPackageElement); |
|
1170 |
} |
|
1171 |
||
1172 |
private void assertElementNotFound(String name, Function<String, Element> getter) { |
|
1173 |
Element found = getter.apply(name); |
|
1174 |
||
1175 |
if (found != null) { |
|
1176 |
fail("Element found unexpectedly: " + found); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
||
1180 |
@Override |
|
1181 |
public SourceVersion getSupportedSourceVersion() { |
|
1182 |
return SourceVersion.latest(); |
|
1183 |
} |
|
1184 |
||
1185 |
} |
|
1186 |
||
1187 |
@SupportedAnnotationTypes("*") |
|
1188 |
public static final class UnboundLookup8 extends AbstractProcessor { |
|
1189 |
||
1190 |
@Override |
|
1191 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
1192 |
if (processingEnv.getElementUtils().getTypeElement("impl.conflict.src.Impl") == null) { |
|
1193 |
throw new AssertionError("impl.conflict.src.Impl."); |
|
1194 |
} |
|
1195 |
||
1196 |
if (processingEnv.getElementUtils().getModuleElement("java.base") != null) { |
|
1197 |
throw new AssertionError("getModuleElement != null for -source 8"); |
|
1198 |
} |
|
1199 |
||
1200 |
return false; |
|
1201 |
} |
|
1202 |
||
1203 |
@Override |
|
1204 |
public SourceVersion getSupportedSourceVersion() { |
|
1205 |
return SourceVersion.latest(); |
|
1206 |
} |
|
1207 |
||
1208 |
} |
|
1209 |
||
36526 | 1210 |
private static void assertNonNull(String msg, Object val) { |
1211 |
if (val == null) { |
|
1212 |
throw new AssertionError(msg); |
|
1213 |
} |
|
1214 |
} |
|
1215 |
||
1216 |
private static void assertNull(String msg, Object val) { |
|
1217 |
if (val != null) { |
|
1218 |
throw new AssertionError(msg); |
|
1219 |
} |
|
1220 |
} |
|
1221 |
||
1222 |
private static void assertEquals(Object expected, Object actual) { |
|
1223 |
if (!Objects.equals(expected, actual)) { |
|
1224 |
throw new AssertionError("expected: " + expected + "; actual=" + actual); |
|
1225 |
} |
|
1226 |
} |
|
1227 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1228 |
private static void assertFileExists(Path base, String... pathElements) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1229 |
Path file = resolveFile(base, pathElements); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1230 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1231 |
if (!Files.exists(file)) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1232 |
throw new AssertionError("Expected file: " + file + " exist, but it does not."); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1233 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1234 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1235 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1236 |
static Path resolveFile(Path base, String... pathElements) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1237 |
Path file = base; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1238 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1239 |
for (String el : pathElements) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1240 |
file = file.resolve(el); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1241 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1242 |
|
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1243 |
return file; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1244 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42407
diff
changeset
|
1245 |
|
42824 | 1246 |
private static void fail(String msg) { |
1247 |
throw new AssertionError(msg); |
|
1248 |
} |
|
1249 |
||
36526 | 1250 |
} |