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
26 * @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119
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
32 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
33 * @run main AnnotationProcessing
34 */
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.io.OutputStream;
39 import java.io.Reader;
40 import java.io.UncheckedIOException;
41 import java.io.Writer;
42 import java.nio.file.Files;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
45 import java.util.ArrayList;
46 import java.util.Arrays;
1401 "--class-path", cpClasses.toString(),
1402 "--add-modules", "m1x,m2x",
1403 "-processorpath", System.getProperty("test.class.path"),
1404 "-processor", UnboundLookup.class.getName(),
1405 "-proc:only")
1406 .classes("java.lang.Object")
1407 .run()
1408 .writeAll();
1409
1410 //source 8:
1411 new JavacTask(tb)
1412 .options("--source-path", src.toString(),
1413 "-source", "8",
1414 "-processorpath", System.getProperty("test.class.path"),
1415 "-processor", UnboundLookup8.class.getName())
1416 .outdir(cpClasses)
1417 .files(findJavaFiles(src))
1418 .run()
1419 .writeAll();
1420
1421 }
1422
1423 @SupportedAnnotationTypes("*")
1424 public static final class UnboundLookup extends AbstractProcessor {
1425
1426 @Override
1427 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
1428 assertTypeElementExists("impl1.Impl", "m1x");
1429 assertPackageElementExists("impl1", "m1x");
1430 assertTypeElementExists("impl2.Impl", "m2x");
1431 assertTypeElementExists("impl.conflict.clazz.pkg.I", "m1x");
1432 assertTypeElementExists("impl.conflict.clazz", "m2x");
1433 assertPackageElementExists("impl.conflict.clazz", "m1x");
1434 assertPackageElementExists("impl2", "m2x");
1435 assertPackageElementExists("nested.pack.pack", "m1x");
1436 assertPackageElementExists("nested.pack", "m2x");
1437 assertTypeElementExists("unique.nested.Impl", "m1x");
1438 assertTypeElementNotFound("impl.conflict.module.Impl");
1439 assertTypeElementNotFound("impl.conflict.module.Impl"); //check that the warning/note is produced only once
1440 assertPackageElementNotFound("impl.conflict.module");
1486 }
1487
1488 @Override
1489 public SourceVersion getSupportedSourceVersion() {
1490 return SourceVersion.latest();
1491 }
1492
1493 }
1494
1495 @SupportedAnnotationTypes("*")
1496 public static final class UnboundLookup8 extends AbstractProcessor {
1497
1498 @Override
1499 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
1500 if (processingEnv.getElementUtils().getTypeElement("impl.conflict.src.Impl") == null) {
1501 throw new AssertionError("impl.conflict.src.Impl.");
1502 }
1503
1504 if (processingEnv.getElementUtils().getModuleElement("java.base") != null) {
1505 throw new AssertionError("getModuleElement != null for -source 8");
1506 }
1507
1508 return false;
1509 }
1510
1511 @Override
1512 public SourceVersion getSupportedSourceVersion() {
1513 return SourceVersion.latest();
1514 }
1515
1516 }
1517
1518 @Test
1519 public void testWrongDefaultTargetModule(Path base) throws Exception {
1520 Path src = base.resolve("src");
1521
1522 tb.writeJavaFiles(src,
1523 "package test; public class Test { }");
1524
1525 Path classes = base.resolve("classes");
|
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
26 * @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747
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
32 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
33 * @run main AnnotationProcessing
34 */
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.io.OutputStream;
39 import java.io.Reader;
40 import java.io.UncheckedIOException;
41 import java.io.Writer;
42 import java.nio.file.Files;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
45 import java.util.ArrayList;
46 import java.util.Arrays;
1401 "--class-path", cpClasses.toString(),
1402 "--add-modules", "m1x,m2x",
1403 "-processorpath", System.getProperty("test.class.path"),
1404 "-processor", UnboundLookup.class.getName(),
1405 "-proc:only")
1406 .classes("java.lang.Object")
1407 .run()
1408 .writeAll();
1409
1410 //source 8:
1411 new JavacTask(tb)
1412 .options("--source-path", src.toString(),
1413 "-source", "8",
1414 "-processorpath", System.getProperty("test.class.path"),
1415 "-processor", UnboundLookup8.class.getName())
1416 .outdir(cpClasses)
1417 .files(findJavaFiles(src))
1418 .run()
1419 .writeAll();
1420
1421 //from source:
1422 new JavacTask(tb)
1423 .options("--module-source-path", moduleSrc.toString(),
1424 "--source-path", src.toString(),
1425 "-processorpath", System.getProperty("test.class.path"),
1426 "-processor", UnboundLookupGenerate.class.getName(),
1427 "-XDrawDiagnostics")
1428 .outdir(classes)
1429 .files(findJavaFiles(moduleSrc))
1430 .run()
1431 .writeAll()
1432 .getOutput(OutputKind.DIRECT);
1433
1434 }
1435
1436 @SupportedAnnotationTypes("*")
1437 public static final class UnboundLookup extends AbstractProcessor {
1438
1439 @Override
1440 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
1441 assertTypeElementExists("impl1.Impl", "m1x");
1442 assertPackageElementExists("impl1", "m1x");
1443 assertTypeElementExists("impl2.Impl", "m2x");
1444 assertTypeElementExists("impl.conflict.clazz.pkg.I", "m1x");
1445 assertTypeElementExists("impl.conflict.clazz", "m2x");
1446 assertPackageElementExists("impl.conflict.clazz", "m1x");
1447 assertPackageElementExists("impl2", "m2x");
1448 assertPackageElementExists("nested.pack.pack", "m1x");
1449 assertPackageElementExists("nested.pack", "m2x");
1450 assertTypeElementExists("unique.nested.Impl", "m1x");
1451 assertTypeElementNotFound("impl.conflict.module.Impl");
1452 assertTypeElementNotFound("impl.conflict.module.Impl"); //check that the warning/note is produced only once
1453 assertPackageElementNotFound("impl.conflict.module");
1499 }
1500
1501 @Override
1502 public SourceVersion getSupportedSourceVersion() {
1503 return SourceVersion.latest();
1504 }
1505
1506 }
1507
1508 @SupportedAnnotationTypes("*")
1509 public static final class UnboundLookup8 extends AbstractProcessor {
1510
1511 @Override
1512 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
1513 if (processingEnv.getElementUtils().getTypeElement("impl.conflict.src.Impl") == null) {
1514 throw new AssertionError("impl.conflict.src.Impl.");
1515 }
1516
1517 if (processingEnv.getElementUtils().getModuleElement("java.base") != null) {
1518 throw new AssertionError("getModuleElement != null for -source 8");
1519 }
1520
1521 return false;
1522 }
1523
1524 @Override
1525 public SourceVersion getSupportedSourceVersion() {
1526 return SourceVersion.latest();
1527 }
1528
1529 }
1530
1531 @SupportedAnnotationTypes("*")
1532 public static final class UnboundLookupGenerate extends AbstractProcessor {
1533
1534 @Override
1535 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
1536 if (processingEnv.getElementUtils().getTypeElement("nue.Nue") == null) {
1537 try (Writer w = processingEnv.getFiler().createSourceFile("m1x/nue.Nue").openWriter()) {
1538 w.write("package nue; public class Nue {}");
1539 } catch (IOException ex) {
1540 throw new IllegalStateException(ex);
1541 }
1542 }
1543
1544 return false;
1545 }
1546
1547 @Override
1548 public SourceVersion getSupportedSourceVersion() {
1549 return SourceVersion.latest();
1550 }
1551
1552 }
1553
1554 @Test
1555 public void testWrongDefaultTargetModule(Path base) throws Exception {
1556 Path src = base.resolve("src");
1557
1558 tb.writeJavaFiles(src,
1559 "package test; public class Test { }");
1560
1561 Path classes = base.resolve("classes");
|