author | darcy |
Thu, 13 Jun 2019 11:50:45 -0700 | |
changeset 55387 | 761b86d5563d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
42407 | 1 |
/* |
55387
761b86d5563d
8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
42407 | 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 |
||
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
24 |
/* |
42407 | 25 |
* @test |
43279
9afb33b0a3ab
8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents:
42839
diff
changeset
|
26 |
* @bug 8159602 8170549 8171255 8171322 |
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
27 |
* @summary Test annotations on module declaration. |
42407 | 28 |
* @library /tools/lib |
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
31 |
* jdk.jdeps/com.sun.tools.classfile |
|
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
42407 | 33 |
* @run main AnnotationsOnModules |
34 |
*/ |
|
35 |
||
36 |
import java.io.File; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.util.Arrays; |
|
40 |
import java.util.HashSet; |
|
41 |
import java.util.List; |
|
42 |
import java.util.Objects; |
|
43 |
import java.util.Set; |
|
44 |
import java.util.stream.Collectors; |
|
45 |
||
46 |
import javax.annotation.processing.AbstractProcessor; |
|
47 |
import javax.annotation.processing.RoundEnvironment; |
|
48 |
import javax.annotation.processing.SupportedAnnotationTypes; |
|
49 |
import javax.annotation.processing.SupportedOptions; |
|
50 |
import javax.lang.model.element.AnnotationMirror; |
|
51 |
import javax.lang.model.element.ModuleElement; |
|
52 |
import javax.lang.model.element.TypeElement; |
|
53 |
||
54 |
import com.sun.tools.classfile.Attribute; |
|
55 |
import com.sun.tools.classfile.ClassFile; |
|
56 |
import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute; |
|
57 |
import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute; |
|
58 |
import toolbox.JavacTask; |
|
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
59 |
import toolbox.Task; |
42407 | 60 |
import toolbox.Task.OutputKind; |
61 |
||
62 |
public class AnnotationsOnModules extends ModuleTestBase { |
|
63 |
||
64 |
public static void main(String... args) throws Exception { |
|
65 |
AnnotationsOnModules t = new AnnotationsOnModules(); |
|
66 |
t.runTests(); |
|
67 |
} |
|
68 |
||
69 |
@Test |
|
70 |
public void testSimpleAnnotation(Path base) throws Exception { |
|
71 |
Path moduleSrc = base.resolve("module-src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
72 |
Path m1 = moduleSrc.resolve("m1x"); |
42407 | 73 |
|
74 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
75 |
"@Deprecated module m1x { }"); |
42407 | 76 |
|
77 |
Path modulePath = base.resolve("module-path"); |
|
78 |
||
79 |
Files.createDirectories(modulePath); |
|
80 |
||
81 |
new JavacTask(tb) |
|
82 |
.options("--module-source-path", moduleSrc.toString()) |
|
83 |
.outdir(modulePath) |
|
84 |
.files(findJavaFiles(m1)) |
|
85 |
.run() |
|
86 |
.writeAll(); |
|
87 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
88 |
ClassFile cf = ClassFile.read(modulePath.resolve("m1x").resolve("module-info.class")); |
42407 | 89 |
RuntimeVisibleAnnotations_attribute annotations = (RuntimeVisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeVisibleAnnotations); |
90 |
||
91 |
if (annotations == null || annotations.annotations.length != 1) { |
|
92 |
throw new AssertionError("Annotations not correct!"); |
|
93 |
} |
|
94 |
} |
|
95 |
||
42839
33f705c03879
8171255: Javac generates Deprecated class file attribute for @deprecated javadoc tag on module declaration.
jjg
parents:
42829
diff
changeset
|
96 |
@Test |
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
97 |
public void testSimpleJavadocDeprecationTag(Path base) throws Exception { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
98 |
Path moduleSrc = base.resolve("module-src"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
99 |
Path m1 = moduleSrc.resolve("src1/A"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
100 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
101 |
tb.writeJavaFiles(m1, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
102 |
"/** @deprecated */ module A { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
103 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
104 |
Path modulePath = base.resolve("module-path"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
105 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
106 |
Files.createDirectories(modulePath); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
107 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
108 |
List<String> warning = new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
109 |
.options("--module-source-path", m1.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
110 |
"-XDrawDiagnostics") |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
111 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
112 |
.files(findJavaFiles(m1)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
113 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
114 |
.writeAll() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
115 |
.getOutputLines(OutputKind.DIRECT); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
116 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
117 |
List<String> expected = List.of( |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
118 |
"module-info.java:1:20: compiler.warn.missing.deprecated.annotation", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
119 |
"1 warning"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
120 |
if (!warning.containsAll(expected)) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
121 |
throw new AssertionError("Expected output not found. Expected: " + expected); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
122 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
123 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
124 |
Path m2 = base.resolve("src2/B"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
125 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
126 |
tb.writeJavaFiles(m2, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
127 |
"module B { requires A; }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
128 |
String log = new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
129 |
.options("--module-source-path", m2.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
130 |
"--module-path", modulePath.toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
131 |
"-XDrawDiagnostics") |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
132 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
133 |
.files(findJavaFiles(m2)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
134 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
135 |
.writeAll() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
136 |
.getOutput(OutputKind.DIRECT); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
137 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
138 |
if (!log.isEmpty()) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
139 |
throw new AssertionError("Output is not empty. Expected no output and no warnings."); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
140 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
141 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
142 |
ClassFile cf = ClassFile.read(modulePath.resolve("A").resolve("module-info.class")); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
143 |
RuntimeVisibleAnnotations_attribute annotations = (RuntimeVisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeVisibleAnnotations); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
144 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
145 |
if (annotations != null && annotations.annotations.length > 0) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
146 |
throw new AssertionError("Found annotation attributes. Expected no annotations for javadoc @deprecated tag."); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
147 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
148 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
149 |
if (cf.attributes.map.get(Attribute.Deprecated) != null) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
150 |
throw new AssertionError("Found Deprecated attribute. Expected no Deprecated attribute for javadoc @deprecated tag."); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
151 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
152 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
153 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
154 |
@Test |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
155 |
public void testEnhancedDeprecatedAnnotation(Path base) throws Exception { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
156 |
Path moduleSrc = base.resolve("module-src"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
157 |
Path m1 = moduleSrc.resolve("src1/A"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
158 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
159 |
tb.writeJavaFiles(m1, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
160 |
"@Deprecated(since=\"10.X\", forRemoval=true) module A { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
161 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
162 |
Path modulePath = base.resolve("module-path"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
163 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
164 |
Files.createDirectories(modulePath); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
165 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
166 |
new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
167 |
.options("--module-source-path", m1.getParent().toString()) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
168 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
169 |
.files(findJavaFiles(m1)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
170 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
171 |
.writeAll(); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
172 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
173 |
Path m2 = base.resolve("src2/B"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
174 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
175 |
tb.writeJavaFiles(m2, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
176 |
"module B { requires A; }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
177 |
List<String> log = new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
178 |
.options("--module-source-path", m2.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
179 |
"--module-path", modulePath.toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
180 |
"-XDrawDiagnostics") |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
181 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
182 |
.files(findJavaFiles(m2)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
183 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
184 |
.writeAll() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
185 |
.getOutputLines(OutputKind.DIRECT); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
186 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
187 |
List<String> expected = List.of("module-info.java:1:21: compiler.warn.has.been.deprecated.for.removal.module: A", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
188 |
"1 warning"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
189 |
if (!log.containsAll(expected)) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
190 |
throw new AssertionError("Expected output not found. Expected: " + expected); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
191 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
192 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
193 |
ClassFile cf = ClassFile.read(modulePath.resolve("A").resolve("module-info.class")); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
194 |
RuntimeVisibleAnnotations_attribute annotations = (RuntimeVisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeVisibleAnnotations); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
195 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
196 |
if (annotations == null ) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
197 |
throw new AssertionError("Annotations not found!"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
198 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
199 |
int length = annotations.annotations.length; |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
200 |
if (length != 1 ) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
201 |
throw new AssertionError("Incorrect number of annotations: " + length); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
202 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
203 |
int pairsCount = annotations.annotations[0].num_element_value_pairs; |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
204 |
if (pairsCount != 2) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
205 |
throw new AssertionError("Incorrect number of key-value pairs in annotation: " + pairsCount + " Expected two: forRemoval and since."); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
206 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
207 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
208 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
209 |
@Test |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
210 |
public void testDeprecatedModuleRequiresDeprecatedForRemovalModule(Path base) throws Exception { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
211 |
Path moduleSrc = base.resolve("module-src"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
212 |
Path m1 = moduleSrc.resolve("src1/A"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
213 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
214 |
tb.writeJavaFiles(m1, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
215 |
"@Deprecated(forRemoval=true) module A { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
216 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
217 |
Path modulePath = base.resolve("module-path"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
218 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
219 |
Files.createDirectories(modulePath); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
220 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
221 |
new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
222 |
.options("--module-source-path", m1.getParent().toString()) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
223 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
224 |
.files(findJavaFiles(m1)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
225 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
226 |
.writeAll(); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
227 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
228 |
Path m2 = base.resolve("src2/B"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
229 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
230 |
tb.writeJavaFiles(m2, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
231 |
"@Deprecated(forRemoval=false) module B { requires A; }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
232 |
List<String> log = new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
233 |
.options("--module-source-path", m2.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
234 |
"--module-path", modulePath.toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
235 |
"-XDrawDiagnostics") |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
236 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
237 |
.files(findJavaFiles(m2)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
238 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
239 |
.writeAll() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
240 |
.getOutputLines(OutputKind.DIRECT); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
241 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
242 |
List<String> expected = List.of("module-info.java:1:51: compiler.warn.has.been.deprecated.for.removal.module: A", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
243 |
"1 warning"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
244 |
if (!log.containsAll(expected)) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
245 |
throw new AssertionError("Expected output not found. Expected: " + expected); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
246 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
247 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
248 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
249 |
@Test |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
250 |
public void testExportsAndOpensToDeprecatedModule(Path base) throws Exception { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
251 |
Path moduleSrc = base.resolve("module-src"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
252 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
253 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
254 |
tb.writeJavaFiles(moduleSrc.resolve("B"), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
255 |
"@Deprecated module B { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
256 |
tb.writeJavaFiles(moduleSrc.resolve("C"), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
257 |
"@Deprecated(forRemoval=true) module C { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
258 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
259 |
Path modulePath = base.resolve("module-path"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
260 |
Files.createDirectories(modulePath); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
261 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
262 |
new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
263 |
.options("--module-source-path", moduleSrc.toString()) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
264 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
265 |
.files(findJavaFiles(moduleSrc)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
266 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
267 |
.writeAll(); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
268 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
269 |
Path m1 = base.resolve("src1/A"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
270 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
271 |
tb.writeJavaFiles(m1, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
272 |
"module A { " + |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
273 |
"exports p1 to B; opens p1 to B;" + |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
274 |
"exports p2 to C; opens p2 to C;" + |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
275 |
"exports p3 to B,C; opens p3 to B,C;" + |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
276 |
"}", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
277 |
"package p1; public class A { }", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
278 |
"package p2; public class A { }", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
279 |
"package p3; public class A { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
280 |
String log = new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
281 |
.options("--module-source-path", m1.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
282 |
"--module-path", modulePath.toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
283 |
"-XDrawDiagnostics") |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
284 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
285 |
.files(findJavaFiles(m1)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
286 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
287 |
.writeAll() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
288 |
.getOutput(OutputKind.DIRECT); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
289 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
290 |
if (!log.isEmpty()) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
291 |
throw new AssertionError("Output is not empty! " + log); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
292 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
293 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
294 |
|
42407 | 295 |
@Test |
296 |
public void testAnnotationWithImport(Path base) throws Exception { |
|
297 |
Path moduleSrc = base.resolve("module-src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
298 |
Path m1 = moduleSrc.resolve("m1x"); |
42407 | 299 |
|
300 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
301 |
"import m1x.A; @A module m1x { }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
302 |
"package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A {}"); |
42407 | 303 |
|
304 |
Path modulePath = base.resolve("module-path"); |
|
305 |
||
306 |
Files.createDirectories(modulePath); |
|
307 |
||
308 |
new JavacTask(tb) |
|
309 |
.options("--module-source-path", moduleSrc.toString()) |
|
310 |
.outdir(modulePath) |
|
311 |
.files(findJavaFiles(m1)) |
|
312 |
.run() |
|
313 |
.writeAll(); |
|
314 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
315 |
ClassFile cf = ClassFile.read(modulePath.resolve("m1x").resolve("module-info.class")); |
42407 | 316 |
RuntimeInvisibleAnnotations_attribute annotations = (RuntimeInvisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeInvisibleAnnotations); |
317 |
||
318 |
if (annotations == null || annotations.annotations.length != 1) { |
|
319 |
throw new AssertionError("Annotations not correct!"); |
|
320 |
} |
|
321 |
} |
|
322 |
||
323 |
@Test |
|
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
324 |
public void testAnnotationWithImportFromAnotherModule(Path base) throws Exception { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
325 |
Path moduleSrc = base.resolve("module-src"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
326 |
Path m1 = moduleSrc.resolve("src1/A"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
327 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
328 |
tb.writeJavaFiles(m1, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
329 |
"module A { exports p1; exports p2; }", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
330 |
"package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A { }", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
331 |
"package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface B { }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
332 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
333 |
Path modulePath = base.resolve("module-path"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
334 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
335 |
Files.createDirectories(modulePath); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
336 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
337 |
new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
338 |
.options("--module-source-path", m1.getParent().toString()) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
339 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
340 |
.files(findJavaFiles(m1)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
341 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
342 |
.writeAll(); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
343 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
344 |
Path m2 = base.resolve("src2/B"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
345 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
346 |
tb.writeJavaFiles(m2, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
347 |
"import p1.A; @A @p2.B module B { requires A; }"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
348 |
new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
349 |
.options("--module-source-path", m2.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
350 |
"--module-path", modulePath.toString() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
351 |
) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
352 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
353 |
.files(findJavaFiles(m2)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
354 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
355 |
.writeAll(); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
356 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
357 |
ClassFile cf = ClassFile.read(modulePath.resolve("B").resolve("module-info.class")); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
358 |
RuntimeInvisibleAnnotations_attribute annotations = (RuntimeInvisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeInvisibleAnnotations); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
359 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
360 |
if (annotations == null ) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
361 |
throw new AssertionError("Annotations not found!"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
362 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
363 |
int length = annotations.annotations.length; |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
364 |
if (length != 2 ) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
365 |
throw new AssertionError("Incorrect number of annotations: " + length); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
366 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
367 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
368 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
369 |
@Test |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
370 |
public void testAnnotationWithImportAmbiguity(Path base) throws Exception { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
371 |
Path moduleSrc = base.resolve("module-src"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
372 |
Path m1 = moduleSrc.resolve("src1/A"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
373 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
374 |
tb.writeJavaFiles(m1, |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
375 |
"module A { exports p1; exports p2; }", |
43279
9afb33b0a3ab
8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents:
42839
diff
changeset
|
376 |
"package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }", |
9afb33b0a3ab
8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents:
42839
diff
changeset
|
377 |
"package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }"); |
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
378 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
379 |
Path modulePath = base.resolve("module-path"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
380 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
381 |
Files.createDirectories(modulePath); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
382 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
383 |
new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
384 |
.options("--module-source-path", m1.getParent().toString()) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
385 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
386 |
.files(findJavaFiles(m1)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
387 |
.run() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
388 |
.writeAll(); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
389 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
390 |
Path m2 = base.resolve("src2/B"); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
391 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
392 |
tb.writeJavaFiles(m2, |
43279
9afb33b0a3ab
8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents:
42839
diff
changeset
|
393 |
"import p1.*; import p2.*; @AAA module B { requires A; }"); |
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
394 |
List<String> log = new JavacTask(tb) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
395 |
.options("--module-source-path", m2.getParent().toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
396 |
"--module-path", modulePath.toString(), |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
397 |
"-XDrawDiagnostics" |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
398 |
) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
399 |
.outdir(modulePath) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
400 |
.files(findJavaFiles(m2)) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
401 |
.run(Task.Expect.FAIL) |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
402 |
.writeAll() |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
403 |
.getOutputLines(OutputKind.DIRECT); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
404 |
|
43279
9afb33b0a3ab
8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents:
42839
diff
changeset
|
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", |
9afb33b0a3ab
8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents:
42839
diff
changeset
|
406 |
"1 error"); |
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
407 |
if (!log.containsAll(expected)) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
408 |
throw new AssertionError("Expected output not found. Expected: " + expected); |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
409 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
410 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
411 |
} |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
412 |
|
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
413 |
@Test |
42407 | 414 |
public void testModuleInfoAnnotationsInAPI(Path base) throws Exception { |
415 |
Path moduleSrc = base.resolve("module-src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
416 |
Path m1 = moduleSrc.resolve("m1x"); |
42407 | 417 |
|
418 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
419 |
"import m1x.*; @A @Deprecated @E @E module m1x { }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
420 |
"package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A {}", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
421 |
"package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) @Repeatable(C.class) public @interface E {}", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
422 |
"package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface C { public E[] value(); }"); |
42407 | 423 |
|
424 |
Path modulePath = base.resolve("module-path"); |
|
425 |
||
426 |
Files.createDirectories(modulePath); |
|
427 |
||
428 |
new JavacTask(tb) |
|
429 |
.options("--module-source-path", moduleSrc.toString(), |
|
430 |
"-processor", AP.class.getName()) |
|
431 |
.outdir(modulePath) |
|
432 |
.files(findJavaFiles(m1)) |
|
433 |
.run() |
|
434 |
.writeAll(); |
|
435 |
||
436 |
Path src = base.resolve("src"); |
|
437 |
||
438 |
tb.writeJavaFiles(src, |
|
439 |
"class T {}"); |
|
440 |
||
441 |
Path out = base.resolve("out"); |
|
442 |
||
443 |
Files.createDirectories(out); |
|
444 |
||
445 |
new JavacTask(tb) |
|
446 |
.options("--module-path", modulePath.toString(), |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
447 |
"--add-modules", "m1x", |
42407 | 448 |
"-processor", AP.class.getName()) |
449 |
.outdir(out) |
|
450 |
.files(findJavaFiles(src)) |
|
451 |
.run() |
|
452 |
.writeAll(); |
|
453 |
||
454 |
new JavacTask(tb) |
|
455 |
.options("--module-path", modulePath.toString() + File.pathSeparator + out.toString(), |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
456 |
"--add-modules", "m1x", |
42407 | 457 |
"-processor", AP.class.getName(), |
458 |
"-proc:only") |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
459 |
.classes("m1x/m1x.A") |
42407 | 460 |
.files(findJavaFiles(src)) |
461 |
.run() |
|
462 |
.writeAll(); |
|
463 |
} |
|
464 |
||
465 |
@SupportedAnnotationTypes("*") |
|
466 |
public static final class AP extends AbstractProcessor { |
|
467 |
||
468 |
@Override |
|
469 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
470 |
ModuleElement m1 = processingEnv.getElementUtils().getModuleElement("m1x"); |
42407 | 471 |
Set<String> actualAnnotations = new HashSet<>(); |
472 |
Set<String> expectedAnnotations = |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
473 |
new HashSet<>(Arrays.asList("@m1x.A", "@java.lang.Deprecated", "@m1x.C({@m1x.E, @m1x.E})")); |
42407 | 474 |
|
475 |
for (AnnotationMirror am : m1.getAnnotationMirrors()) { |
|
476 |
actualAnnotations.add(am.toString()); |
|
477 |
} |
|
478 |
||
479 |
if (!expectedAnnotations.equals(actualAnnotations)) { |
|
480 |
throw new AssertionError("Incorrect annotations: " + actualAnnotations); |
|
481 |
} |
|
482 |
||
483 |
return false; |
|
484 |
} |
|
485 |
||
486 |
} |
|
487 |
||
488 |
@Test |
|
489 |
public void testModuleDeprecation(Path base) throws Exception { |
|
490 |
Path moduleSrc = base.resolve("module-src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
491 |
Path m1 = moduleSrc.resolve("m1x"); |
42407 | 492 |
|
493 |
tb.writeJavaFiles(m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
494 |
"@Deprecated module m1x { }"); |
42407 | 495 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
496 |
Path m2 = moduleSrc.resolve("m2x"); |
42407 | 497 |
|
498 |
tb.writeJavaFiles(m2, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
499 |
"@Deprecated module m2x { }"); |
42407 | 500 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
501 |
Path m3 = moduleSrc.resolve("m3x"); |
42407 | 502 |
|
503 |
Path modulePath = base.resolve("module-path"); |
|
504 |
||
505 |
Files.createDirectories(modulePath); |
|
506 |
||
507 |
List<String> actual; |
|
508 |
List<String> expected; |
|
509 |
||
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
510 |
String DEPRECATED_JAVADOC = "/** @deprecated */"; |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
511 |
for (String suppress : new String[] {"", DEPRECATED_JAVADOC, "@Deprecated ", "@SuppressWarnings(\"deprecation\") "}) { |
42407 | 512 |
tb.writeJavaFiles(m3, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
513 |
suppress + "module m3x {\n" + |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
514 |
" requires m1x;\n" + |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
515 |
" exports api to m1x, m2x;\n" + |
42407 | 516 |
"}", |
517 |
"package api; public class Api { }"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
518 |
System.err.println("compile m3x"); |
42407 | 519 |
actual = new JavacTask(tb) |
520 |
.options("--module-source-path", moduleSrc.toString(), |
|
521 |
"-XDrawDiagnostics") |
|
522 |
.outdir(modulePath) |
|
523 |
.files(findJavaFiles(moduleSrc)) |
|
524 |
.run() |
|
525 |
.writeAll() |
|
526 |
.getOutputLines(OutputKind.DIRECT); |
|
527 |
||
528 |
if (suppress.isEmpty()) { |
|
529 |
expected = Arrays.asList( |
|
530 |
"- compiler.note.deprecated.filename: module-info.java", |
|
531 |
"- compiler.note.deprecated.recompile"); |
|
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
532 |
} else if (suppress.equals(DEPRECATED_JAVADOC)) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
533 |
expected = Arrays.asList( |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
534 |
"module-info.java:1:19: compiler.warn.missing.deprecated.annotation", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
535 |
"- compiler.note.deprecated.filename: module-info.java", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
536 |
"- compiler.note.deprecated.recompile", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
537 |
"1 warning"); |
42407 | 538 |
} else { |
539 |
expected = Arrays.asList(""); |
|
540 |
} |
|
541 |
||
542 |
if (!expected.equals(actual)) { |
|
543 |
throw new AssertionError("Unexpected output: " + actual + "; suppress: " + suppress); |
|
544 |
} |
|
545 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
546 |
System.err.println("compile m3x with -Xlint:-deprecation"); |
42407 | 547 |
actual = new JavacTask(tb) |
548 |
.options("--module-source-path", moduleSrc.toString(), |
|
549 |
"-XDrawDiagnostics", |
|
550 |
"-Xlint:deprecation") |
|
551 |
.outdir(modulePath) |
|
552 |
.files(findJavaFiles(moduleSrc)) |
|
553 |
.run() |
|
554 |
.writeAll() |
|
555 |
.getOutputLines(OutputKind.DIRECT); |
|
556 |
||
557 |
if (suppress.isEmpty()) { |
|
558 |
expected = Arrays.asList( |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
559 |
"module-info.java:2:14: compiler.warn.has.been.deprecated.module: m1x", |
42407 | 560 |
"1 warning"); |
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
561 |
} else if (suppress.equals(DEPRECATED_JAVADOC)) { |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
562 |
expected = Arrays.asList( |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
563 |
"module-info.java:1:19: compiler.warn.missing.deprecated.annotation", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
564 |
"module-info.java:2:14: compiler.warn.has.been.deprecated.module: m1x", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
565 |
"2 warnings"); |
42407 | 566 |
} else { |
567 |
expected = Arrays.asList(""); |
|
568 |
} |
|
569 |
||
570 |
if (!expected.equals(actual)) { |
|
571 |
throw new AssertionError("Unexpected output: " + actual + "; suppress: " + suppress); |
|
572 |
} |
|
573 |
||
574 |
//load the deprecated module-infos from classfile: |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
575 |
System.err.println("compile m3x with -Xlint:-deprecation, loading deprecated modules from classes"); |
42407 | 576 |
actual = new JavacTask(tb) |
577 |
.options("--module-path", modulePath.toString(), |
|
578 |
"-XDrawDiagnostics", |
|
579 |
"-Xlint:deprecation") |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
580 |
.outdir(modulePath.resolve("m3x")) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
581 |
.files(findJavaFiles(moduleSrc.resolve("m3x"))) |
42407 | 582 |
.run() |
583 |
.writeAll() |
|
584 |
.getOutputLines(OutputKind.DIRECT); |
|
585 |
||
586 |
if (!expected.equals(actual)) { |
|
587 |
throw new AssertionError("Unexpected output: " + actual + "; suppress: " + suppress); |
|
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
@Test |
|
593 |
public void testAttributeValues(Path base) throws Exception { |
|
594 |
class TestCase { |
|
595 |
public final String extraDecl; |
|
596 |
public final String decl; |
|
597 |
public final String use; |
|
598 |
public final String expectedAnnotations; |
|
599 |
||
600 |
public TestCase(String extraDecl, String decl, String use, String expectedAnnotations) { |
|
601 |
this.extraDecl = extraDecl; |
|
602 |
this.decl = decl; |
|
603 |
this.use = use; |
|
604 |
this.expectedAnnotations = expectedAnnotations; |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
TestCase[] testCases = new TestCase[] { |
|
609 |
new TestCase("package test; public enum E {A, B;}", |
|
610 |
"public E value();", |
|
611 |
"test.E.A", |
|
55387
761b86d5563d
8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents:
47216
diff
changeset
|
612 |
"@test.A(A)"), |
42407 | 613 |
new TestCase("package test; public enum E {A, B;}", |
614 |
"public E[] value();", |
|
615 |
"{test.E.A, test.E.B}", |
|
55387
761b86d5563d
8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents:
47216
diff
changeset
|
616 |
"@test.A({A, B})"), |
42407 | 617 |
new TestCase("package test; public class Extra {}", |
618 |
"public Class value();", |
|
619 |
"test.Extra.class", |
|
620 |
"@test.A(test.Extra.class)"), |
|
621 |
new TestCase("package test; public class Extra {}", |
|
622 |
"public Class[] value();", |
|
623 |
"{test.Extra.class, String.class}", |
|
624 |
"@test.A({test.Extra.class, java.lang.String.class})"), |
|
625 |
new TestCase("package test; public @interface Extra { public Class value(); }", |
|
626 |
"public test.Extra value();", |
|
627 |
"@test.Extra(String.class)", |
|
628 |
"@test.A(@test.Extra(java.lang.String.class))"), |
|
629 |
new TestCase("package test; public @interface Extra { public Class value(); }", |
|
630 |
"public test.Extra[] value();", |
|
631 |
"{@test.Extra(String.class), @test.Extra(Integer.class)}", |
|
632 |
"@test.A({@test.Extra(java.lang.String.class), @test.Extra(java.lang.Integer.class)})"), |
|
633 |
new TestCase("package test; public class Any { }", |
|
634 |
"public int value();", |
|
635 |
"1", |
|
636 |
"@test.A(1)"), |
|
637 |
new TestCase("package test; public class Any { }", |
|
638 |
"public int[] value();", |
|
639 |
"{1, 2}", |
|
640 |
"@test.A({1, 2})"), |
|
42829
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
641 |
new TestCase("package test; public enum E {A;}", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
642 |
"int integer(); boolean flag(); double value(); String string(); E enumeration(); ", |
37fa35ab1907
8170549: Improve testing of annotations on modules
anazarov
parents:
42822
diff
changeset
|
643 |
"enumeration = test.E.A, integer = 42, flag = true, value = 3.5, string = \"Text\"", |
55387
761b86d5563d
8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents:
47216
diff
changeset
|
644 |
"@test.A(enumeration=A, integer=42, flag=true, value=3.5, string=\"Text\")"), |
42407 | 645 |
}; |
646 |
||
647 |
Path extraSrc = base.resolve("extra-src"); |
|
648 |
tb.writeJavaFiles(extraSrc, |
|
649 |
"class Any {}"); |
|
650 |
||
651 |
int count = 0; |
|
652 |
||
653 |
for (TestCase tc : testCases) { |
|
654 |
Path testBase = base.resolve(String.valueOf(count)); |
|
655 |
Path moduleSrc = testBase.resolve("module-src"); |
|
656 |
Path m = moduleSrc.resolve("m"); |
|
657 |
||
658 |
tb.writeJavaFiles(m, |
|
659 |
"@test.A(" + tc.use + ") module m { }", |
|
660 |
"package test; @java.lang.annotation.Target(java.lang.annotation.ElementType.MODULE) public @interface A { " + tc.decl + "}", |
|
661 |
tc.extraDecl); |
|
662 |
||
663 |
Path modulePath = testBase.resolve("module-path"); |
|
664 |
||
665 |
Files.createDirectories(modulePath); |
|
666 |
||
667 |
new JavacTask(tb) |
|
668 |
.options("--module-source-path", moduleSrc.toString()) |
|
669 |
.outdir(modulePath) |
|
670 |
.files(findJavaFiles(moduleSrc)) |
|
671 |
.run() |
|
672 |
.writeAll(); |
|
673 |
||
674 |
Path classes = testBase.resolve("classes"); |
|
675 |
||
676 |
Files.createDirectories(classes); |
|
677 |
||
678 |
new JavacTask(tb) |
|
679 |
.options("--module-path", modulePath.toString(), |
|
680 |
"--add-modules", "m", |
|
681 |
"-processorpath", System.getProperty("test.classes"), |
|
682 |
"-processor", ProxyTypeValidator.class.getName(), |
|
683 |
"-A" + OPT_EXPECTED_ANNOTATIONS + "=" + tc.expectedAnnotations) |
|
684 |
.outdir(classes) |
|
685 |
.files(findJavaFiles(extraSrc)) |
|
686 |
.run() |
|
687 |
.writeAll(); |
|
688 |
} |
|
689 |
} |
|
690 |
||
691 |
private static final String OPT_EXPECTED_ANNOTATIONS = "expectedAnnotations"; |
|
692 |
||
693 |
@SupportedAnnotationTypes("*") |
|
694 |
@SupportedOptions(OPT_EXPECTED_ANNOTATIONS) |
|
695 |
public static final class ProxyTypeValidator extends AbstractProcessor { |
|
696 |
||
697 |
@Override |
|
698 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
|
699 |
ModuleElement m = processingEnv.getElementUtils().getModuleElement("m"); |
|
700 |
String actualTypes = m.getAnnotationMirrors() |
|
701 |
.stream() |
|
702 |
.map(am -> am.toString()) |
|
703 |
.collect(Collectors.joining(", ")); |
|
704 |
if (!Objects.equals(actualTypes, processingEnv.getOptions().get(OPT_EXPECTED_ANNOTATIONS))) { |
|
705 |
throw new IllegalStateException("Expected annotations not found, actual: " + actualTypes); |
|
706 |
} |
|
707 |
return false; |
|
708 |
} |
|
709 |
||
710 |
} |
|
711 |
||
712 |
} |