author | aeremeev |
Fri, 06 Jun 2014 16:08:46 -0400 | |
changeset 24896 | 986d876a9121 |
parent 24396 | 3c36c6afcbca |
permissions | -rw-r--r-- |
15385 | 1 |
/* |
22443
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
2 |
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
15385 | 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 |
import java.io.BufferedWriter; |
|
25 |
import java.io.File; |
|
26 |
import java.io.FileWriter; |
|
27 |
import java.io.IOException; |
|
28 |
import java.io.PrintStream; |
|
29 |
import java.io.PrintWriter; |
|
30 |
import java.lang.annotation.*; |
|
31 |
import java.lang.reflect.*; |
|
32 |
import java.util.ArrayList; |
|
22443
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
33 |
import java.util.Arrays; |
15385 | 34 |
import java.util.Collections; |
35 |
import java.util.HashMap; |
|
36 |
import java.util.List; |
|
37 |
import java.util.Map; |
|
38 |
||
39 |
import com.sun.tools.classfile.ClassFile; |
|
40 |
import com.sun.tools.classfile.TypeAnnotation; |
|
41 |
import com.sun.tools.classfile.TypeAnnotation.TargetType; |
|
42 |
||
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
43 |
import static java.lang.String.format; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
44 |
|
15385 | 45 |
public class Driver { |
46 |
||
24396 | 47 |
private static final PrintStream out = System.err; |
15385 | 48 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
49 |
private final Object testObject; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
50 |
|
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
51 |
public Driver(Class<?> clazz) throws IllegalAccessException, InstantiationException { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
52 |
testObject = clazz.newInstance(); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
53 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
54 |
|
15385 | 55 |
public static void main(String[] args) throws Exception { |
56 |
if (args.length == 0 || args.length > 1) |
|
57 |
throw new IllegalArgumentException("Usage: java Driver <test-name>"); |
|
58 |
String name = args[0]; |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
59 |
new Driver(Class.forName(name)).runDriver(); |
15385 | 60 |
} |
61 |
||
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
62 |
private final String[][] extraParamsCombinations = new String[][] { |
22443
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
63 |
new String[] { }, |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
64 |
new String[] { "-g" }, |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
65 |
}; |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
66 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
67 |
private final String[] retentionPolicies = {RetentionPolicy.CLASS.toString(), RetentionPolicy.RUNTIME.toString()}; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
68 |
|
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
69 |
protected void runDriver() { |
15385 | 70 |
int passed = 0, failed = 0; |
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
71 |
Class<?> clazz = testObject.getClass(); |
15385 | 72 |
out.println("Tests for " + clazz.getName()); |
73 |
||
74 |
// Find methods |
|
75 |
for (Method method : clazz.getMethods()) { |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
76 |
try { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
77 |
Map<String, TypeAnnotation.Position> expected = expectedOf(method); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
78 |
if (expected == null) |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
79 |
continue; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
80 |
if (method.getReturnType() != String.class) |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
81 |
throw new IllegalArgumentException("Test method needs to return a string: " + method); |
15385 | 82 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
83 |
String compact = (String) method.invoke(testObject); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
84 |
for (String retentionPolicy : retentionPolicies) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
85 |
String testClassName = getTestClassName(method, retentionPolicy); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
86 |
String testClass = testClassOf(method, testClassName); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
87 |
String fullFile = wrap(compact, new HashMap<String, String>() {{ |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
88 |
put("%RETENTION_POLICY%", retentionPolicy); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
89 |
put("%TEST_CLASS_NAME%", testClassName); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
90 |
}}); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
91 |
for (String[] extraParams : extraParamsCombinations) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
92 |
try { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
93 |
ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
94 |
List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
95 |
ReferenceInfoUtil.compare(expected, actual, cf); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
96 |
out.format("PASSED: %s %s%n", testClassName, Arrays.toString(extraParams)); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
97 |
++passed; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
98 |
} catch (Throwable e) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
99 |
out.format("FAILED: %s %s%n", testClassName, Arrays.toString(extraParams)); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
100 |
out.println(fullFile); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
101 |
out.println(" " + e.toString()); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
102 |
e.printStackTrace(out); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
103 |
++failed; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
104 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
105 |
} |
22443
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
106 |
} |
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
107 |
} catch (IllegalAccessException | InvocationTargetException e) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
108 |
out.println("FAILED: " + method.getName()); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
109 |
out.println(" " + e.toString()); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
110 |
e.printStackTrace(out); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
111 |
++failed; |
15385 | 112 |
} |
113 |
} |
|
114 |
||
115 |
out.println(); |
|
116 |
int total = passed + failed; |
|
117 |
out.println(total + " total tests: " + passed + " PASSED, " + failed + " FAILED"); |
|
118 |
||
119 |
out.flush(); |
|
120 |
||
121 |
if (failed != 0) |
|
122 |
throw new RuntimeException(failed + " tests failed"); |
|
123 |
} |
|
124 |
||
125 |
private Map<String, TypeAnnotation.Position> expectedOf(Method m) { |
|
126 |
TADescription ta = m.getAnnotation(TADescription.class); |
|
127 |
TADescriptions tas = m.getAnnotation(TADescriptions.class); |
|
128 |
||
129 |
if (ta == null && tas == null) |
|
130 |
return null; |
|
131 |
||
132 |
Map<String, TypeAnnotation.Position> result = |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
133 |
new HashMap<>(); |
15385 | 134 |
|
135 |
if (ta != null) |
|
136 |
result.putAll(expectedOf(ta)); |
|
137 |
||
138 |
if (tas != null) { |
|
139 |
for (TADescription a : tas.value()) { |
|
140 |
result.putAll(expectedOf(a)); |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
return result; |
|
145 |
} |
|
146 |
||
147 |
private Map<String, TypeAnnotation.Position> expectedOf(TADescription d) { |
|
148 |
String annoName = d.annotation(); |
|
149 |
||
150 |
TypeAnnotation.Position p = new TypeAnnotation.Position(); |
|
151 |
p.type = d.type(); |
|
152 |
if (d.offset() != NOT_SET) |
|
153 |
p.offset = d.offset(); |
|
154 |
if (d.lvarOffset().length != 0) |
|
155 |
p.lvarOffset = d.lvarOffset(); |
|
156 |
if (d.lvarLength().length != 0) |
|
157 |
p.lvarLength = d.lvarLength(); |
|
158 |
if (d.lvarIndex().length != 0) |
|
159 |
p.lvarIndex = d.lvarIndex(); |
|
160 |
if (d.boundIndex() != NOT_SET) |
|
161 |
p.bound_index = d.boundIndex(); |
|
162 |
if (d.paramIndex() != NOT_SET) |
|
163 |
p.parameter_index = d.paramIndex(); |
|
164 |
if (d.typeIndex() != NOT_SET) |
|
165 |
p.type_index = d.typeIndex(); |
|
166 |
if (d.exceptionIndex() != NOT_SET) |
|
167 |
p.exception_index = d.exceptionIndex(); |
|
168 |
if (d.genericLocation().length != 0) { |
|
169 |
p.location = TypeAnnotation.Position.getTypePathFromBinary(wrapIntArray(d.genericLocation())); |
|
170 |
} |
|
171 |
||
172 |
return Collections.singletonMap(annoName, p); |
|
173 |
} |
|
174 |
||
175 |
private List<Integer> wrapIntArray(int[] ints) { |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
176 |
List<Integer> list = new ArrayList<>(ints.length); |
15385 | 177 |
for (int i : ints) |
178 |
list.add(i); |
|
179 |
return list; |
|
180 |
} |
|
181 |
||
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
182 |
private String getTestClassName(Method m, String retentionPolicy) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
183 |
return format("%s_%s_%s", testObject.getClass().getSimpleName(), |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
184 |
m.getName(), retentionPolicy); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
185 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
186 |
|
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
187 |
private String testClassOf(Method m, String testClassName) { |
15385 | 188 |
TestClass tc = m.getAnnotation(TestClass.class); |
189 |
if (tc != null) { |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
190 |
return tc.value().replace("%TEST_CLASS_NAME%", testClassName); |
15385 | 191 |
} else { |
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
192 |
return testClassName; |
15385 | 193 |
} |
194 |
} |
|
195 |
||
22443
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
196 |
private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception { |
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
197 |
File source = writeTestFile(fullFile, testClass); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
198 |
File clazzFile = compileTestFile(source, testClass, extraParams); |
15385 | 199 |
return ClassFile.read(clazzFile); |
200 |
} |
|
201 |
||
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
202 |
protected File writeTestFile(String fullFile, String testClass) throws IOException { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
203 |
File f = new File(getClassDir(), format("%s.java", testClass)); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
204 |
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)))) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
205 |
out.println(fullFile); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
206 |
return f; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
207 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
208 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
209 |
|
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
210 |
private String getClassDir() { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
211 |
return System.getProperty("test.classes", Driver.class.getResource(".").getPath()); |
15385 | 212 |
} |
213 |
||
22443
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
214 |
protected File compileTestFile(File f, String testClass, String... extraParams) { |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
215 |
List<String> options = new ArrayList<>(); |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
216 |
options.addAll(Arrays.asList(extraParams)); |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
217 |
options.add(f.getPath()); |
0922d94d0576
8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents:
17578
diff
changeset
|
218 |
int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()])); |
15385 | 219 |
if (rc != 0) |
220 |
throw new Error("compilation failed. rc=" + rc); |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
221 |
String path = f.getParent() != null ? f.getParent() : ""; |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
222 |
return new File(path, format("%s.class", testClass)); |
15385 | 223 |
} |
224 |
||
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
225 |
private String wrap(String compact, Map<String, String> replacements) { |
15385 | 226 |
StringBuilder sb = new StringBuilder(); |
227 |
||
228 |
// Automatically import java.util |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
229 |
sb.append("\nimport java.io.*;"); |
15385 | 230 |
sb.append("\nimport java.util.*;"); |
231 |
sb.append("\nimport java.lang.annotation.*;"); |
|
232 |
||
233 |
sb.append("\n\n"); |
|
234 |
boolean isSnippet = !(compact.startsWith("class") |
|
235 |
|| compact.contains(" class")) |
|
236 |
&& !compact.contains("interface") |
|
237 |
&& !compact.contains("enum"); |
|
238 |
if (isSnippet) |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
239 |
sb.append("class %TEST_CLASS_NAME% {\n"); |
15385 | 240 |
|
241 |
sb.append(compact); |
|
242 |
sb.append("\n"); |
|
243 |
||
244 |
if (isSnippet) |
|
245 |
sb.append("}\n\n"); |
|
246 |
||
247 |
if (isSnippet) { |
|
248 |
// Have a few common nested types for testing |
|
17578 | 249 |
sb.append("class Outer { class Inner {} class Middle { class MInner {} } }"); |
15385 | 250 |
sb.append("class SOuter { static class SInner {} }"); |
251 |
sb.append("class GOuter<X, Y> { class GInner<X, Y> {} }"); |
|
252 |
} |
|
253 |
||
254 |
// create A ... F annotation declarations |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
255 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface A {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
256 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface B {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
257 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface C {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
258 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface D {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
259 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface E {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
260 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface F {}"); |
15385 | 261 |
|
262 |
// create TA ... TF proper type annotations |
|
263 |
sb.append("\n"); |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
264 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
265 |
" @Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TA {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
266 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
267 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TB {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
268 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
269 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TC {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
270 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
271 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TD {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
272 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
273 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TE {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
274 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
275 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TF {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
276 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
277 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TG {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
278 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
279 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TH {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
280 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
281 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TI {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
282 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
283 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TJ {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
284 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
285 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TK {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
286 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
287 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TL {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
288 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
289 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TM {}"); |
15385 | 290 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
291 |
// create RT?, RT?s for repeating type annotations |
15385 | 292 |
sb.append("\n"); |
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
293 |
sb.append("\n@Repeatable(RTAs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
294 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTA {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
295 |
sb.append("\n@Repeatable(RTBs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
296 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTB {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
297 |
sb.append("\n@Repeatable(RTCs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
298 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTC {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
299 |
sb.append("\n@Repeatable(RTDs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
300 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTD {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
301 |
sb.append("\n@Repeatable(RTEs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
302 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTE {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
303 |
sb.append("\n@Repeatable(RTFs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
304 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTF {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
305 |
sb.append("\n@Repeatable(RTGs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
306 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTG {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
307 |
sb.append("\n@Repeatable(RTHs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
308 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTH {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
309 |
sb.append("\n@Repeatable(RTIs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
310 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTI {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
311 |
sb.append("\n@Repeatable(RTJs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
312 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTJ {}"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
313 |
sb.append("\n@Repeatable(RTKs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
314 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTK {}"); |
15385 | 315 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
316 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
317 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTAs { RTA[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
318 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
319 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTBs { RTB[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
320 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
321 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTCs { RTC[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
322 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
323 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTDs { RTD[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
324 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
325 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTEs { RTE[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
326 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
327 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTFs { RTF[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
328 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
329 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTGs { RTG[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
330 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
331 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTHs { RTH[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
332 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
333 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTIs { RTI[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
334 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
335 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTJs { RTJ[] value(); }"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
336 |
sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
337 |
"@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTKs { RTK[] value(); }"); |
15385 | 338 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
339 |
sb.append("\n@Target(value={ElementType.TYPE,ElementType.FIELD,ElementType.METHOD," + |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
340 |
"ElementType.PARAMETER,ElementType.CONSTRUCTOR,ElementType.LOCAL_VARIABLE})"); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
341 |
sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface Decl {}"); |
15385 | 342 |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
343 |
return replaceAll(sb.toString(), replacements); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
344 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
345 |
|
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
346 |
private String replaceAll(String src, Map<String, String> replacements) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
347 |
for (Map.Entry<String, String> entry : replacements.entrySet()) { |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
348 |
src = src.replace(entry.getKey(), entry.getValue()); |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
349 |
} |
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
350 |
return src; |
15385 | 351 |
} |
352 |
||
353 |
public static final int NOT_SET = -888; |
|
354 |
||
355 |
} |
|
356 |
||
357 |
@Retention(RetentionPolicy.RUNTIME) |
|
358 |
@Target(ElementType.METHOD) |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
359 |
@Repeatable(TADescriptions.class) |
15385 | 360 |
@interface TADescription { |
361 |
String annotation(); |
|
362 |
||
363 |
TargetType type(); |
|
364 |
int offset() default Driver.NOT_SET; |
|
365 |
int[] lvarOffset() default { }; |
|
366 |
int[] lvarLength() default { }; |
|
367 |
int[] lvarIndex() default { }; |
|
368 |
int boundIndex() default Driver.NOT_SET; |
|
369 |
int paramIndex() default Driver.NOT_SET; |
|
370 |
int typeIndex() default Driver.NOT_SET; |
|
371 |
int exceptionIndex() default Driver.NOT_SET; |
|
372 |
||
373 |
int[] genericLocation() default {}; |
|
374 |
} |
|
375 |
||
376 |
@Retention(RetentionPolicy.RUNTIME) |
|
377 |
@Target(ElementType.METHOD) |
|
378 |
@interface TADescriptions { |
|
379 |
TADescription[] value() default {}; |
|
380 |
} |
|
381 |
||
382 |
/** |
|
383 |
* The name of the class that should be analyzed. |
|
384 |
* Should only need to be provided when analyzing inner classes. |
|
385 |
*/ |
|
386 |
@Retention(RetentionPolicy.RUNTIME) |
|
387 |
@Target(ElementType.METHOD) |
|
388 |
@interface TestClass { |
|
24896
986d876a9121
8042451: Write tests for all possible kinds of type annotation
aeremeev
parents:
24396
diff
changeset
|
389 |
String value(); |
15385 | 390 |
} |