changeset 43279 | 9afb33b0a3ab |
parent 42839 | 33f705c03879 |
43278:e9f4ee9bfd86 | 43279:9afb33b0a3ab |
---|---|
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8159602 8170549 8171255 |
26 * @bug 8159602 8170549 8171255 8171322 |
27 * @summary Test annotations on module declaration. |
27 * @summary Test annotations on module declaration. |
28 * @library /tools/lib |
28 * @library /tools/lib |
29 * @modules jdk.compiler/com.sun.tools.javac.api |
29 * @modules jdk.compiler/com.sun.tools.javac.api |
30 * jdk.compiler/com.sun.tools.javac.main |
30 * jdk.compiler/com.sun.tools.javac.main |
31 * jdk.jdeps/com.sun.tools.classfile |
31 * jdk.jdeps/com.sun.tools.classfile |
371 Path moduleSrc = base.resolve("module-src"); |
371 Path moduleSrc = base.resolve("module-src"); |
372 Path m1 = moduleSrc.resolve("src1/A"); |
372 Path m1 = moduleSrc.resolve("src1/A"); |
373 |
373 |
374 tb.writeJavaFiles(m1, |
374 tb.writeJavaFiles(m1, |
375 "module A { exports p1; exports p2; }", |
375 "module A { exports p1; exports p2; }", |
376 "package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A { }", |
376 "package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }", |
377 "package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A { }"); |
377 "package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }"); |
378 |
378 |
379 Path modulePath = base.resolve("module-path"); |
379 Path modulePath = base.resolve("module-path"); |
380 |
380 |
381 Files.createDirectories(modulePath); |
381 Files.createDirectories(modulePath); |
382 |
382 |
388 .writeAll(); |
388 .writeAll(); |
389 |
389 |
390 Path m2 = base.resolve("src2/B"); |
390 Path m2 = base.resolve("src2/B"); |
391 |
391 |
392 tb.writeJavaFiles(m2, |
392 tb.writeJavaFiles(m2, |
393 "import p1.*; import p2.*; @A module B { requires A; }"); |
393 "import p1.*; import p2.*; @AAA module B { requires A; }"); |
394 List<String> log = new JavacTask(tb) |
394 List<String> log = new JavacTask(tb) |
395 .options("--module-source-path", m2.getParent().toString(), |
395 .options("--module-source-path", m2.getParent().toString(), |
396 "--module-path", modulePath.toString(), |
396 "--module-path", modulePath.toString(), |
397 "-XDrawDiagnostics" |
397 "-XDrawDiagnostics" |
398 ) |
398 ) |
400 .files(findJavaFiles(m2)) |
400 .files(findJavaFiles(m2)) |
401 .run(Task.Expect.FAIL) |
401 .run(Task.Expect.FAIL) |
402 .writeAll() |
402 .writeAll() |
403 .getOutputLines(OutputKind.DIRECT); |
403 .getOutputLines(OutputKind.DIRECT); |
404 |
404 |
405 List<String> expected = List.of("module-info.java:1:28: compiler.err.ref.ambiguous: A, kindname.class, p2.A, p2, kindname.class, p1.A, p1", |
405 List<String> expected = List.of("module-info.java:1:28: compiler.err.ref.ambiguous: AAA, kindname.class, p2.AAA, p2, kindname.class, p1.AAA, p1", |
406 "module-info.java:1:27: compiler.err.annotation.type.not.applicable", |
406 "1 error"); |
407 "2 errors"); |
|
408 if (!log.containsAll(expected)) { |
407 if (!log.containsAll(expected)) { |
409 throw new AssertionError("Expected output not found. Expected: " + expected); |
408 throw new AssertionError("Expected output not found. Expected: " + expected); |
410 } |
409 } |
411 |
410 |
412 } |
411 } |