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