1 /* |
1 /* |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
26 * @bug 8038455 |
26 * @bug 8038455 |
27 * @summary Verify that annotation processor can overwrite source and class files it generated |
27 * @summary Verify that annotation processor can overwrite source and class files it generated |
28 * during previous compilations, and that the Symbols are updated appropriatelly. |
28 * during previous compilations, and that the Symbols are updated appropriatelly. |
29 * @library /tools/lib /tools/javac/lib/ |
29 * @library /tools/lib /tools/javac/lib/ |
30 * @modules jdk.compiler/com.sun.tools.javac.api |
30 * @modules jdk.compiler/com.sun.tools.javac.api |
31 * jdk.compiler/com.sun.tools.javac.file |
|
32 * jdk.compiler/com.sun.tools.javac.main |
31 * jdk.compiler/com.sun.tools.javac.main |
33 * jdk.compiler/com.sun.tools.javac.processing |
32 * jdk.compiler/com.sun.tools.javac.processing |
34 * jdk.compiler/com.sun.tools.javac.util |
33 * jdk.compiler/com.sun.tools.javac.util |
35 * jdk.jdeps/com.sun.tools.javap |
34 * jdk.jdeps/com.sun.tools.javap |
36 * @clean * |
35 * @clean * |
37 * @build OverwriteBetweenCompilations ToolBox JavacTestingAbstractProcessor |
36 * @build toolbox.ToolBox toolbox.JavacTask |
|
37 * @build OverwriteBetweenCompilations JavacTestingAbstractProcessor |
38 * @compile/ref=OverwriteBetweenCompilations_1.out -XDaccessInternalAPI -processor OverwriteBetweenCompilations -Apass=1 -parameters -XDrawDiagnostics OverwriteBetweenCompilationsSource.java |
38 * @compile/ref=OverwriteBetweenCompilations_1.out -XDaccessInternalAPI -processor OverwriteBetweenCompilations -Apass=1 -parameters -XDrawDiagnostics OverwriteBetweenCompilationsSource.java |
39 * @compile/ref=OverwriteBetweenCompilations_2.out -XDaccessInternalAPI -processor OverwriteBetweenCompilations -Apass=2 -parameters -XDrawDiagnostics OverwriteBetweenCompilationsSource.java |
39 * @compile/ref=OverwriteBetweenCompilations_2.out -XDaccessInternalAPI -processor OverwriteBetweenCompilations -Apass=2 -parameters -XDrawDiagnostics OverwriteBetweenCompilationsSource.java |
40 * @compile/ref=OverwriteBetweenCompilations_3.out -XDaccessInternalAPI -processor OverwriteBetweenCompilations -Apass=3 -parameters -XDrawDiagnostics OverwriteBetweenCompilationsSource.java |
40 * @compile/ref=OverwriteBetweenCompilations_3.out -XDaccessInternalAPI -processor OverwriteBetweenCompilations -Apass=3 -parameters -XDrawDiagnostics OverwriteBetweenCompilationsSource.java |
41 */ |
41 */ |
42 |
42 |
49 |
49 |
50 import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
50 import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
51 import com.sun.tools.javac.processing.PrintingProcessor.PrintingElementVisitor; |
51 import com.sun.tools.javac.processing.PrintingProcessor.PrintingElementVisitor; |
52 import com.sun.tools.javac.util.Log; |
52 import com.sun.tools.javac.util.Log; |
53 import com.sun.tools.javac.util.Log.WriterKind; |
53 import com.sun.tools.javac.util.Log.WriterKind; |
|
54 |
|
55 import toolbox.JavacTask; |
|
56 import toolbox.ToolBox; |
54 |
57 |
55 @SupportedOptions("pass") |
58 @SupportedOptions("pass") |
56 public class OverwriteBetweenCompilations extends JavacTestingAbstractProcessor { |
59 public class OverwriteBetweenCompilations extends JavacTestingAbstractProcessor { |
57 int round = 1; |
60 int round = 1; |
58 @Override |
61 @Override |
93 String code = pass != 2 ? GENERATED_INIT : GENERATED_UPDATE; |
96 String code = pass != 2 ? GENERATED_INIT : GENERATED_UPDATE; |
94 code = code.replace("NAME", "GeneratedClass"); |
97 code = code.replace("NAME", "GeneratedClass"); |
95 |
98 |
96 ToolBox tb = new ToolBox(); |
99 ToolBox tb = new ToolBox(); |
97 ToolBox.MemoryFileManager mfm = new ToolBox.MemoryFileManager(); |
100 ToolBox.MemoryFileManager mfm = new ToolBox.MemoryFileManager(); |
98 tb.new JavacTask() |
101 new JavacTask(tb) |
99 .fileManager(mfm) |
102 .fileManager(mfm) |
100 .options("-parameters") |
103 .options("-parameters") |
101 .sources(code) |
104 .sources(code) |
102 .run(); |
105 .run(); |
103 |
106 |