OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library lib; | |
6 | |
7 import 'package:expect/expect.dart'; | |
8 | |
9 @MirrorsUsed(targets: "lib") | |
10 import 'dart:mirrors'; | |
11 | |
12 class A<T> {} | |
13 | |
14 class B extends A<U> {} | |
15 | |
16 class C extends A<C> {} | |
17 | |
18 class D<T> extends A<T> {} | |
19 | |
20 class E<X, Y> extends G<H<Y>> {} | |
21 | |
22 class F<X> implements A<X> {} | |
23 | |
24 class FF<X, Y> implements G<H<Y>> {} | |
25 | |
26 class G<T> {} | |
27 | |
28 class H<T> {} | |
29 | |
30 class U {} | |
31 | |
32 class R {} | |
33 | |
34 void testOriginals() { | |
35 ClassMirror a = reflectClass(A); | |
36 ClassMirror b = reflectClass(B); | |
37 ClassMirror c = reflectClass(C); | |
38 ClassMirror d = reflectClass(D); | |
39 ClassMirror e = reflectClass(E); | |
40 ClassMirror f = reflectClass(F); | |
41 ClassMirror ff = reflectClass(FF); | |
42 ClassMirror superA = a.superclass; | |
43 ClassMirror superB = b.superclass; | |
44 ClassMirror superC = c.superclass; | |
45 ClassMirror superD = d.superclass; | |
46 ClassMirror superE = e.superclass; | |
47 ClassMirror superInterfaceF = f.superinterfaces[0]; | |
48 ClassMirror superInterfaceFF = ff.superinterfaces[0]; | |
49 | |
50 TypeVariableMirror aT = a.typeVariables[0]; | |
51 TypeVariableMirror dT = d.typeVariables[0]; | |
52 TypeVariableMirror eX = e.typeVariables[0]; | |
53 TypeVariableMirror eY = e.typeVariables[1]; | |
54 TypeVariableMirror fX = f.typeVariables[0]; | |
55 TypeVariableMirror feX = ff.typeVariables[0]; | |
56 TypeVariableMirror feY = ff.typeVariables[1]; | |
57 | |
58 Expect.isTrue(superA.isOriginalDeclaration); | |
59 Expect.isFalse(superB.isOriginalDeclaration); | |
60 Expect.isFalse(superC.isOriginalDeclaration); | |
61 Expect.isFalse(superD.isOriginalDeclaration); | |
62 Expect.isFalse(superE.isOriginalDeclaration); | |
63 Expect.isFalse(superInterfaceF.isOriginalDeclaration); | |
64 Expect.isFalse(superInterfaceFF.isOriginalDeclaration); | |
65 | |
66 Expect.equals(reflectClass(Object), superA); | |
67 Expect.equals(reflect(new A<U>()).type, superB); | |
68 Expect.equals(reflect(new A<C>()).type, superC); //# 01: ok | |
69 Expect.equals(reflect(new U()).type, superB.typeArguments[0]); | |
70 Expect.equals(reflect(new C()).type, superC.typeArguments[0]); //# 01: ok | |
71 Expect.equals(dT, superD.typeArguments[0]); | |
72 Expect.equals(eY, superE.typeArguments[0].typeArguments[0]); | |
73 Expect.equals(feY, superInterfaceFF.typeArguments[0].typeArguments[0]); | |
74 Expect.equals(fX, superInterfaceF.typeArguments[0]); | |
75 } | |
76 | |
77 void testInstances() { | |
78 ClassMirror a = reflect(new A<U>()).type; | |
79 ClassMirror b = reflect(new B()).type; | |
80 ClassMirror c = reflect(new C()).type; | |
81 ClassMirror d = reflect(new D<U>()).type; | |
82 ClassMirror e = reflect(new E<U, R>()).type; | |
83 ClassMirror e0 = reflect(new E<U, H<R>>()).type; | |
84 ClassMirror ff = reflect(new FF<U, R>()).type; | |
85 ClassMirror f = reflect(new F<U>()).type; | |
86 ClassMirror u = reflect(new U()).type; | |
87 ClassMirror r = reflect(new R()).type; | |
88 ClassMirror hr = reflect(new H<R>()).type; | |
89 | |
90 ClassMirror superA = a.superclass; | |
91 ClassMirror superB = b.superclass; | |
92 ClassMirror superC = c.superclass; | |
93 ClassMirror superD = d.superclass; | |
94 ClassMirror superE = e.superclass; | |
95 ClassMirror superE0 = e0.superclass; | |
96 ClassMirror superInterfaceF = f.superinterfaces[0]; | |
97 ClassMirror superInterfaceFF = ff.superinterfaces[0]; | |
98 | |
99 Expect.isTrue(superA.isOriginalDeclaration); | |
100 Expect.isFalse(superB.isOriginalDeclaration); | |
101 Expect.isFalse(superC.isOriginalDeclaration); | |
102 Expect.isFalse(superD.isOriginalDeclaration); | |
103 Expect.isFalse(superE.isOriginalDeclaration); | |
104 Expect.isFalse(superE0.isOriginalDeclaration); | |
105 Expect.isFalse(superInterfaceF.isOriginalDeclaration); | |
106 Expect.isFalse(superInterfaceFF.isOriginalDeclaration); | |
107 | |
108 Expect.equals(reflectClass(Object), superA); | |
109 Expect.equals(reflect(new A<U>()).type, superB); | |
110 Expect.equals(reflect(new A<C>()).type, superC); //# 01: ok | |
111 Expect.equals(reflect(new A<U>()).type, superD); | |
112 Expect.equals(reflect(new G<H<R>>()).type, superE); | |
113 Expect.equals(reflect(new G<H<H<R>>>()).type, superE0); | |
114 Expect.equals(reflect(new G<H<R>>()).type, superInterfaceFF); | |
115 Expect.equals(u, superB.typeArguments[0]); | |
116 Expect.equals(reflect(new C()).type, superC.typeArguments[0]); //# 01: ok | |
117 Expect.equals(u, superD.typeArguments[0]); | |
118 Expect.equals(r, superE.typeArguments[0].typeArguments[0]); | |
119 Expect.equals(hr, superE0.typeArguments[0].typeArguments[0]); | |
120 Expect.equals(r, superInterfaceFF.typeArguments[0].typeArguments[0]); | |
121 Expect.equals(u, superInterfaceF.typeArguments[0]); | |
122 } | |
123 | |
124 void testObject() { | |
125 ClassMirror object = reflectClass(Object); | |
126 Expect.equals(null, object.superclass); | |
127 } | |
128 | |
129 main() { | |
130 testOriginals(); | |
131 testInstances(); | |
132 testObject(); | |
133 } | |
OLD | NEW |