author | kshefov |
Wed, 20 Mar 2013 14:02:25 +0400 | |
changeset 16468 | 8675645c0757 |
parent 15332 | aa02ac4b20b7 |
child 21274 | 238365b3e98a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
16468
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
2 |
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary Tests com.sun.beans.TypeResolver |
|
27 |
* @author Eamonn McManus |
|
28 |
*/ |
|
29 |
||
30 |
import com.sun.beans.TypeResolver; |
|
31 |
||
11092
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
32 |
import java.lang.annotation.Annotation; |
16468
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
33 |
import java.lang.reflect.AnnotatedType; |
2 | 34 |
import java.lang.reflect.Field; |
35 |
import java.lang.reflect.GenericDeclaration; |
|
36 |
import java.lang.reflect.Method; |
|
37 |
import java.lang.reflect.Type; |
|
38 |
import java.lang.reflect.TypeVariable; |
|
39 |
import java.lang.reflect.WildcardType; |
|
40 |
import java.util.ArrayList; |
|
41 |
import java.util.Arrays; |
|
42 |
import java.util.Comparator; |
|
43 |
import java.util.List; |
|
44 |
import java.util.Map; |
|
45 |
||
46 |
import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl; |
|
47 |
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; |
|
48 |
||
49 |
public class TestTypeResolver { |
|
50 |
static final List<Class<?>> failedCases = new ArrayList<Class<?>>(); |
|
51 |
||
52 |
public static void main(String[] args) throws Exception { |
|
53 |
test(TestTypeResolver.class); |
|
54 |
if (failedCases.isEmpty()) |
|
55 |
System.out.println("TEST PASSED"); |
|
56 |
else { |
|
57 |
System.out.println("TEST FAILED: failed cases: " + failedCases); |
|
58 |
throw new Error("TEST FAILED"); |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
private static void test(Class<?> c) throws Exception { |
|
63 |
/* Every public nested class represents a test. In each case, either |
|
64 |
* the class contains further nested classes, in which case we |
|
65 |
* call this method recursively; or it declares or inherits a |
|
66 |
* method called getThing() and it declares a static field |
|
67 |
* called "expect" which |
|
68 |
* is the Type of that method's return value. The test consists |
|
69 |
* of checking that the value returned by |
|
70 |
* TypeResolver.resolveInClass is indeed this Type. |
|
71 |
*/ |
|
72 |
System.out.println("Test " + c); |
|
73 |
Class<?>[] nested = c.getClasses(); |
|
74 |
Arrays.sort(nested, classNameComparator); |
|
75 |
for (Class<?> n : nested) |
|
76 |
test(n); |
|
77 |
final Method m; |
|
78 |
try { |
|
79 |
m = c.getMethod("getThing"); |
|
80 |
} catch (NoSuchMethodException e) { |
|
81 |
if (nested.length == 0) { |
|
82 |
System.out.println( |
|
83 |
"TEST ERROR: class " + c.getName() + " has neither " + |
|
84 |
"nested classes nor getThing() method"); |
|
85 |
failedCases.add(c); |
|
86 |
} |
|
87 |
return; |
|
88 |
} |
|
89 |
Object expect = null; |
|
90 |
try { |
|
91 |
Field f = c.getDeclaredField("expect"); |
|
92 |
expect = f.get(null); |
|
93 |
} catch (NoSuchFieldException e) { |
|
94 |
Class<?> outer = c.getDeclaringClass(); |
|
95 |
if (outer != null) { |
|
96 |
try { |
|
97 |
Field f = outer.getDeclaredField("expect" + c.getSimpleName()); |
|
98 |
expect = f.get(null); |
|
99 |
} catch (NoSuchFieldException e1) { |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
if (expect == null) { |
|
104 |
System.out.println( |
|
105 |
"TEST ERROR: class " + c.getName() + " has getThing() method " + |
|
106 |
"but not expect field"); |
|
107 |
failedCases.add(c); |
|
108 |
return; |
|
109 |
} |
|
110 |
Type t = m.getGenericReturnType(); |
|
111 |
// t = FixType.fixType(t, c); |
|
112 |
t = TypeResolver.resolveInClass(c, t); |
|
113 |
System.out.print("..." + t); |
|
114 |
// check expected value, and incidentally equals method defined |
|
115 |
// by private implementations of the various Type interfaces |
|
116 |
if (expect.equals(t) && t.equals(expect)) |
|
117 |
System.out.println(", as expected"); |
|
118 |
else { |
|
119 |
System.out.println(" BUT SHOULD BE " + expect); |
|
120 |
failedCases.add(c); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
private static class ClassNameComparator implements Comparator<Class<?>> { |
|
125 |
public int compare(Class<?> a, Class<?> b) { |
|
126 |
return a.getName().compareTo(b.getName()); |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
private static final Comparator<Class<?>> classNameComparator = |
|
131 |
new ClassNameComparator(); |
|
132 |
||
133 |
private static abstract class TypeVariableImpl<D extends GenericDeclaration> |
|
134 |
implements TypeVariable<D> { |
|
135 |
private final String name; |
|
136 |
private final D gd; |
|
137 |
private final Type[] bounds; |
|
138 |
||
139 |
TypeVariableImpl(String name, D gd, Type... bounds) { |
|
140 |
this.name = name; |
|
141 |
this.gd = gd; |
|
142 |
if (bounds.length == 0) |
|
143 |
bounds = new Type[] {Object.class}; |
|
144 |
this.bounds = bounds.clone(); |
|
145 |
} |
|
146 |
||
147 |
public Type[] getBounds() { |
|
148 |
return bounds.clone(); |
|
149 |
} |
|
150 |
||
151 |
public D getGenericDeclaration() { |
|
152 |
return gd; |
|
153 |
} |
|
154 |
||
155 |
public String getName() { |
|
156 |
return name; |
|
157 |
} |
|
158 |
||
159 |
public String toString() { |
|
160 |
return name; |
|
161 |
} |
|
162 |
||
163 |
public boolean equals(Object o) { |
|
164 |
if (!(o instanceof TypeVariable)) |
|
165 |
return false; |
|
166 |
TypeVariable tv = (TypeVariable) o; |
|
167 |
return equal(name, tv.getName()) && |
|
168 |
equal(gd, tv.getGenericDeclaration()) && |
|
169 |
Arrays.equals(bounds, tv.getBounds()); |
|
170 |
} |
|
171 |
||
172 |
public int hashCode() { |
|
173 |
return hash(name) ^ hash(gd) ^ Arrays.hashCode(bounds); |
|
174 |
} |
|
11092
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
175 |
|
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
176 |
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
177 |
return false; // not used |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
178 |
} |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
179 |
|
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
180 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
181 |
return null; // not used |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
182 |
} |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
183 |
|
15332
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
184 |
public <T extends Annotation> T[] getAnnotations(Class<T> annotationClass) { |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
185 |
return null; // not used |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
186 |
} |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
187 |
|
11092
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
188 |
public Annotation[] getAnnotations() { |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
189 |
return null; // not used |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
190 |
} |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
191 |
|
15332
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
192 |
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) { |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
193 |
return null; // not used |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
194 |
} |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
195 |
|
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
196 |
public <T extends Annotation> T[] getDeclaredAnnotations(Class<T> annotationClass) { |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
197 |
return null; // not used |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
198 |
} |
aa02ac4b20b7
8005138: test/java/beans/Introspector/TestTypeResolver.java fails
malenkov
parents:
11092
diff
changeset
|
199 |
|
11092
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
200 |
public Annotation[] getDeclaredAnnotations() { |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
201 |
return null; // not used |
6c49e728d427
7110521: Regression test failed: Introspector/TestTypeResolver.java
malenkov
parents:
5506
diff
changeset
|
202 |
} |
16468
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
203 |
|
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
204 |
public AnnotatedType[] getAnnotatedBounds() { |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
205 |
return null; // not used |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
206 |
} |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
207 |
|
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
208 |
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
209 |
return null; // not used |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
210 |
} |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
211 |
|
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
212 |
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) { |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
213 |
return null; // not used |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
214 |
} |
8675645c0757
8009880: TEST_BUG: Test java/beans/Introspector/TestTypeResolver.java should be modified again
kshefov
parents:
15332
diff
changeset
|
215 |
|
2 | 216 |
} |
217 |
||
218 |
private static class ClassTypeVariable extends TypeVariableImpl<Class<?>> { |
|
219 |
ClassTypeVariable(String name, Class<?> gd, Type... bounds) { |
|
220 |
super(name, gd, bounds); |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
private static class MethodTypeVariable extends TypeVariableImpl<Method> { |
|
225 |
MethodTypeVariable(String name, Method gd, Type... bounds) { |
|
226 |
super(name, gd, bounds); |
|
227 |
} |
|
228 |
} |
|
229 |
||
230 |
private static class WildcardTypeImpl implements WildcardType { |
|
231 |
private final Type[] upperBounds; |
|
232 |
private final Type[] lowerBounds; |
|
233 |
||
234 |
WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { |
|
235 |
if (upperBounds == null || upperBounds.length == 0) |
|
236 |
upperBounds = new Type[] {Object.class}; |
|
237 |
if (lowerBounds == null) |
|
238 |
lowerBounds = new Type[0]; |
|
239 |
this.upperBounds = upperBounds.clone(); |
|
240 |
this.lowerBounds = lowerBounds.clone(); |
|
241 |
} |
|
242 |
||
243 |
public Type[] getUpperBounds() { |
|
244 |
return upperBounds.clone(); |
|
245 |
} |
|
246 |
||
247 |
public Type[] getLowerBounds() { |
|
248 |
return lowerBounds.clone(); |
|
249 |
} |
|
250 |
||
251 |
public boolean equals(Object o) { |
|
252 |
if (o instanceof WildcardType) { |
|
253 |
WildcardType wt = (WildcardType) o; |
|
254 |
return Arrays.equals(upperBounds, wt.getUpperBounds()) && |
|
255 |
Arrays.equals(lowerBounds, wt.getLowerBounds()); |
|
256 |
} else |
|
257 |
return false; |
|
258 |
} |
|
259 |
||
260 |
public int hashCode() { |
|
261 |
return Arrays.hashCode(upperBounds) ^ Arrays.hashCode(lowerBounds); |
|
262 |
} |
|
263 |
||
264 |
public String toString() { |
|
265 |
StringBuilder sb = new StringBuilder("?"); |
|
266 |
if (upperBounds.length > 1 || upperBounds[0] != Object.class) { |
|
267 |
sb.append(" extends"); |
|
268 |
appendBounds(sb, upperBounds); |
|
269 |
} |
|
270 |
if (lowerBounds.length > 0) { |
|
271 |
sb.append(" super"); |
|
272 |
appendBounds(sb, lowerBounds); |
|
273 |
} |
|
274 |
return sb.toString(); |
|
275 |
} |
|
276 |
||
277 |
private static void appendBounds(StringBuilder sb, Type[] bounds) { |
|
278 |
boolean and = false; |
|
279 |
for (Type bound : bounds) { |
|
280 |
if (and) |
|
281 |
sb.append(" &"); |
|
282 |
sb.append(" "); |
|
283 |
if (bound instanceof Class) |
|
284 |
sb.append(((Class<?>) bound).getName()); |
|
285 |
else |
|
286 |
sb.append(bound); |
|
287 |
and = true; |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
||
292 |
static boolean equal(Object x, Object y) { |
|
293 |
if (x == y) |
|
294 |
return true; |
|
295 |
if (x == null || y == null) |
|
296 |
return false; |
|
297 |
return x.equals(y); |
|
298 |
} |
|
299 |
||
300 |
static int hash(Object x) { |
|
301 |
return (x == null) ? null : x.hashCode(); |
|
302 |
} |
|
303 |
||
304 |
||
305 |
public static class Outer<T> { |
|
306 |
public class Inner { |
|
307 |
public T getThing() { |
|
308 |
return null; |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
static final Type expectInner = new ClassTypeVariable("T", Outer.class); |
|
313 |
} |
|
314 |
||
315 |
public static class Super<T> { |
|
316 |
static final Type expect = new ClassTypeVariable("T", Super.class); |
|
317 |
||
318 |
public T getThing() { |
|
319 |
return null; |
|
320 |
} |
|
321 |
} |
|
322 |
||
323 |
public static class Int extends Super<Integer> { |
|
324 |
static final Type expect = Integer.class; |
|
325 |
} |
|
326 |
||
327 |
public static class IntOverride extends Int { |
|
328 |
static final Type expect = Integer.class; |
|
329 |
||
330 |
public Integer getThing() { |
|
331 |
return null; |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
public static class Mid<X> extends Super<X> { |
|
336 |
static final Type expect = new ClassTypeVariable("X", Mid.class); |
|
337 |
} |
|
338 |
||
339 |
public static class Str extends Mid<String> { |
|
340 |
static final Type expect = String.class; |
|
341 |
} |
|
342 |
||
343 |
public static class ListInt extends Super<List<Integer>> { |
|
344 |
static final Type expect = ParameterizedTypeImpl.make( |
|
345 |
List.class, new Type[] {Integer.class}, null); |
|
346 |
} |
|
347 |
||
348 |
public static class ListIntSub extends ListInt { |
|
349 |
static final Type expect = ParameterizedTypeImpl.make( |
|
350 |
List.class, new Type[] {Integer.class}, null); |
|
351 |
||
352 |
public List<Integer> getThing() { |
|
353 |
return null; |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
public static class ListU<U> extends Super<List<U>> { |
|
358 |
static final Type expect = ParameterizedTypeImpl.make( |
|
359 |
List.class, new Type[] {new ClassTypeVariable("U", ListU.class)}, null); |
|
360 |
} |
|
361 |
||
362 |
public static class ListUInt extends ListU<Integer> { |
|
363 |
static final Type expect = ParameterizedTypeImpl.make( |
|
364 |
List.class, new Type[] {Integer.class}, null); |
|
365 |
} |
|
366 |
||
367 |
public static class ListUSub<V> extends ListU<V> { |
|
368 |
static final Type expect = ParameterizedTypeImpl.make( |
|
369 |
List.class, new Type[] {new ClassTypeVariable("V", ListUSub.class)}, null); |
|
370 |
||
371 |
public List<V> getThing() { |
|
372 |
return null; |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
public static class ListUSubInt extends ListUSub<Integer> { |
|
377 |
static final Type expect = ParameterizedTypeImpl.make( |
|
378 |
List.class, new Type[] {Integer.class}, null); |
|
379 |
} |
|
380 |
||
381 |
public static class TwoParams<S, T> extends Super<S> { |
|
382 |
static final Type expect = new ClassTypeVariable("S", TwoParams.class); |
|
383 |
} |
|
384 |
||
385 |
public static class TwoParamsSub<T> extends TwoParams<T, Integer> { |
|
386 |
static final Type expect = new ClassTypeVariable("T", TwoParamsSub.class); |
|
387 |
} |
|
388 |
||
389 |
public static class TwoParamsSubSub extends TwoParamsSub<String> { |
|
390 |
static final Type expect = String.class; |
|
391 |
} |
|
392 |
||
393 |
public static interface Intf<T> { |
|
394 |
static final Type expect = new ClassTypeVariable("T", Intf.class); |
|
395 |
||
396 |
public T getThing(); |
|
397 |
} |
|
398 |
||
399 |
public static abstract class Impl implements Intf<String> { |
|
400 |
static final Type expect = String.class; |
|
401 |
} |
|
402 |
||
403 |
public static class Impl2 extends Super<String> implements Intf<String> { |
|
404 |
static final Type expect = String.class; |
|
405 |
} |
|
406 |
||
407 |
public static class Bound<T extends Number> extends Super<T> { |
|
408 |
static final Type expect = new ClassTypeVariable("T", Bound.class, Number.class); |
|
409 |
} |
|
410 |
||
411 |
public static class BoundInt extends Bound<Integer> { |
|
412 |
static final Type expect = Integer.class; |
|
413 |
} |
|
414 |
||
415 |
public static class RawBound extends Bound { |
|
416 |
static final Type expect = Number.class; |
|
417 |
} |
|
418 |
||
419 |
public static class RawBoundInt extends BoundInt { |
|
420 |
static final Type expect = Integer.class; |
|
421 |
} |
|
422 |
||
423 |
public static class MethodParam<T> { |
|
424 |
private static final Method m; |
|
425 |
||
426 |
static { |
|
427 |
try { |
|
428 |
m = MethodParam.class.getMethod("getThing"); |
|
429 |
} catch (Exception e) { |
|
430 |
throw new AssertionError(e); |
|
431 |
} |
|
432 |
} |
|
433 |
||
434 |
static final Type expect = new MethodTypeVariable("T", m); |
|
435 |
||
436 |
public <T> T getThing() { |
|
437 |
return null; |
|
438 |
} |
|
439 |
} |
|
440 |
||
441 |
public static class Raw extends Super { |
|
442 |
static final Type expect = Object.class; |
|
443 |
} |
|
444 |
||
445 |
public static class RawSub extends Raw { |
|
446 |
static final Type expect = Object.class; |
|
447 |
} |
|
448 |
||
449 |
public static class SimpleArray extends Super<String[]> { |
|
450 |
static final Type expect = String[].class; |
|
451 |
} |
|
452 |
||
453 |
public static class GenericArray extends Super<List<String>[]> { |
|
454 |
static final Type expect = GenericArrayTypeImpl.make( |
|
455 |
ParameterizedTypeImpl.make(List.class, new Type[] {String.class}, null)); |
|
456 |
} |
|
457 |
||
458 |
public static class GenericArrayT<T> extends Super<T[]> { |
|
459 |
static final Type expect = GenericArrayTypeImpl.make( |
|
460 |
new ClassTypeVariable("T", GenericArrayT.class)); |
|
461 |
} |
|
462 |
||
463 |
public static class GenericArrayTSub extends GenericArrayT<String[]> { |
|
464 |
static final Type expect = String[][].class; |
|
465 |
} |
|
466 |
||
467 |
public static class Wildcard extends Super<List<?>> { |
|
468 |
static final Type expect = ParameterizedTypeImpl.make( |
|
469 |
List.class, new Type[] {new WildcardTypeImpl(null, null)}, null); |
|
470 |
} |
|
471 |
||
472 |
public static class WildcardT<T> extends Super<List<? extends T>> { |
|
473 |
static final Type expect = ParameterizedTypeImpl.make( |
|
474 |
List.class, |
|
475 |
new Type[] { |
|
476 |
new WildcardTypeImpl( |
|
477 |
new Type[] {new ClassTypeVariable("T", WildcardT.class)}, |
|
478 |
null)}, |
|
479 |
null); |
|
480 |
} |
|
481 |
||
482 |
public static class WildcardTSub extends WildcardT<Integer> { |
|
483 |
static final Type expect = ParameterizedTypeImpl.make( |
|
484 |
List.class, |
|
485 |
new Type[] { |
|
486 |
new WildcardTypeImpl( |
|
487 |
new Type[] {Integer.class}, |
|
488 |
null)}, |
|
489 |
null); |
|
490 |
} |
|
491 |
||
492 |
public static class WildcardTSubSub<X> extends WildcardTSub { |
|
493 |
// X is just so we can have a raw subclass |
|
494 |
static final Type expect = WildcardTSub.expect; |
|
495 |
} |
|
496 |
||
497 |
public static class RawWildcardTSubSub extends WildcardTSubSub { |
|
498 |
static final Type expect = List.class; |
|
499 |
} |
|
500 |
||
501 |
public static class WildcardTSuper<T> extends Super<List<? super T>> { |
|
502 |
static final Type expect = ParameterizedTypeImpl.make( |
|
503 |
List.class, |
|
504 |
new Type[] { |
|
505 |
new WildcardTypeImpl( |
|
506 |
null, |
|
507 |
new Type[] {new ClassTypeVariable("T", WildcardTSuper.class)})}, |
|
508 |
null); |
|
509 |
} |
|
510 |
||
511 |
public static class WildcardTSuperSub extends WildcardTSuper<Integer> { |
|
512 |
static final Type expect = ParameterizedTypeImpl.make( |
|
513 |
List.class, |
|
514 |
new Type[] { |
|
515 |
new WildcardTypeImpl( |
|
516 |
null, |
|
517 |
new Type[] {Integer.class})}, |
|
518 |
null); |
|
519 |
} |
|
520 |
||
521 |
public static class SuperMap<K, V> { |
|
522 |
static final Type expect = ParameterizedTypeImpl.make( |
|
523 |
Map.class, |
|
524 |
new Type[] { |
|
525 |
new ClassTypeVariable("K", SuperMap.class), |
|
526 |
new ClassTypeVariable("V", SuperMap.class)}, |
|
527 |
null); |
|
528 |
||
529 |
public Map<K, V> getThing() { |
|
530 |
return null; |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
public static class SubMap extends SuperMap<String, Integer> { |
|
535 |
static final Type expect = ParameterizedTypeImpl.make( |
|
536 |
Map.class, |
|
537 |
new Type[] {String.class, Integer.class}, |
|
538 |
null); |
|
539 |
} |
|
540 |
||
541 |
public static class ListListT<T> extends Super<List<List<T>>> { |
|
542 |
static final Type expect = ParameterizedTypeImpl.make( |
|
543 |
List.class, |
|
544 |
new Type[] { |
|
545 |
ParameterizedTypeImpl.make( |
|
546 |
List.class, |
|
547 |
new Type[] {new ClassTypeVariable("T", ListListT.class)}, |
|
548 |
null)}, |
|
549 |
null); |
|
550 |
} |
|
551 |
||
552 |
public static class ListListString extends ListListT<String> { |
|
553 |
static final Type expect = ParameterizedTypeImpl.make( |
|
554 |
List.class, |
|
555 |
new Type[] { |
|
556 |
ParameterizedTypeImpl.make( |
|
557 |
List.class, |
|
558 |
new Type[] {String.class}, |
|
559 |
null)}, |
|
560 |
null); |
|
561 |
} |
|
562 |
||
563 |
public static class UExtendsT<T, U extends T> extends Super<U> { |
|
564 |
static final Type expect = new ClassTypeVariable( |
|
565 |
"U", UExtendsT.class, new ClassTypeVariable("T", UExtendsT.class)); |
|
566 |
} |
|
567 |
||
568 |
public static class UExtendsTSub extends UExtendsT<Number, Integer> { |
|
569 |
static final Type expect = Integer.class; |
|
570 |
} |
|
571 |
||
572 |
public static class SelfRef<T extends SelfRef<T>> extends Super<T> { |
|
573 |
static final Type expect = |
|
574 |
SelfRef.class.getTypeParameters()[0]; |
|
575 |
} |
|
576 |
||
577 |
public static class SelfRefSub extends SelfRef<SelfRefSub> { |
|
578 |
static final Type expect = SelfRefSub.class; |
|
579 |
} |
|
580 |
} |