OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library test.type_arguments_test; | 5 library test.type_arguments_test; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'generics_helper.dart'; | 10 import 'generics_helper.dart'; |
11 | 11 |
12 class A<T> {} | 12 class A<T> {} |
13 | |
14 class Z<T> {} | 13 class Z<T> {} |
15 | |
16 class B extends A {} | 14 class B extends A {} |
17 | |
18 class C | 15 class C |
19 extends A<num, int> // //# 01: static type warning | 16 extends A<num, int> // //# 01: static type warning |
20 {} | 17 {} |
21 | |
22 class D extends A<int> {} | 18 class D extends A<int> {} |
23 | |
24 class E<S> extends A<S> {} | 19 class E<S> extends A<S> {} |
25 | |
26 class F<R> extends A<int> {} | 20 class F<R> extends A<int> {} |
27 | |
28 class G {} | 21 class G {} |
29 | 22 class H<A,B,C> {} |
30 class H<A, B, C> {} | |
31 | |
32 class I extends G {} | 23 class I extends G {} |
33 | 24 |
34 main() { | 25 main() { |
35 // Declarations. | 26 // Declarations. |
36 typeParameters(reflectClass(A), [#T]); | 27 typeParameters(reflectClass(A), [#T]); |
37 typeParameters(reflectClass(G), []); | 28 typeParameters(reflectClass(G), []); |
38 typeParameters(reflectClass(B), []); | 29 typeParameters(reflectClass(B), []); |
39 typeParameters(reflectClass(C), []); | 30 typeParameters(reflectClass(C), []); |
40 typeParameters(reflectClass(D), []); | 31 typeParameters(reflectClass(D), []); |
41 typeParameters(reflectClass(E), [#S]); | 32 typeParameters(reflectClass(E), [#S]); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 typeParameters(reflect(new E()).type, [#S]); | 73 typeParameters(reflect(new E()).type, [#S]); |
83 typeParameters(reflect(new F<num>()).type, [#R]); | 74 typeParameters(reflect(new F<num>()).type, [#R]); |
84 typeParameters(reflect(new G()).type, []); | 75 typeParameters(reflect(new G()).type, []); |
85 typeParameters(reflect(new H()).type, [#A, #B, #C]); | 76 typeParameters(reflect(new H()).type, [#A, #B, #C]); |
86 typeParameters(reflect(new I()).type, []); | 77 typeParameters(reflect(new I()).type, []); |
87 | 78 |
88 var numMirror = reflectClass(num); | 79 var numMirror = reflectClass(num); |
89 var dynamicMirror = currentMirrorSystem().dynamicType; | 80 var dynamicMirror = currentMirrorSystem().dynamicType; |
90 typeArguments(reflect(new A<num>()).type, [numMirror]); | 81 typeArguments(reflect(new A<num>()).type, [numMirror]); |
91 typeArguments(reflect(new A<dynamic>()).type, [dynamicMirror]); | 82 typeArguments(reflect(new A<dynamic>()).type, [dynamicMirror]); |
92 typeArguments(reflect(new A()).type, [dynamicMirror]); | 83 typeArguments(reflect(new A()).type, [dynamicMirror]); |
93 typeArguments(reflect(new B()).type, []); | 84 typeArguments(reflect(new B()).type, []); |
94 typeArguments(reflect(new C()).type, []); | 85 typeArguments(reflect(new C()).type, []); |
95 typeArguments(reflect(new D()).type, []); | 86 typeArguments(reflect(new D()).type, []); |
96 typeArguments(reflect(new E<num>()).type, [numMirror]); | 87 typeArguments(reflect(new E<num>()).type, [numMirror]); |
97 typeArguments(reflect(new E<dynamic>()).type, [dynamicMirror]); | 88 typeArguments(reflect(new E<dynamic>()).type, [dynamicMirror]); |
98 typeArguments(reflect(new E()).type, [dynamicMirror]); | 89 typeArguments(reflect(new E()).type, [dynamicMirror]); |
99 typeArguments(reflect(new F<num>()).type, [numMirror]); | 90 typeArguments(reflect(new F<num>()).type, [numMirror]); |
100 typeArguments(reflect(new F<dynamic>()).type, [dynamicMirror]); | 91 typeArguments(reflect(new F<dynamic>()).type, [dynamicMirror]); |
101 typeArguments(reflect(new F()).type, [dynamicMirror]); | 92 typeArguments(reflect(new F()).type, [dynamicMirror]); |
102 typeArguments(reflect(new G()).type, []); | 93 typeArguments(reflect(new G()).type, []); |
103 typeArguments(reflect(new H<dynamic, num, dynamic>()).type, | 94 typeArguments(reflect(new H<dynamic, num, dynamic>()).type, |
104 [dynamicMirror, numMirror, dynamicMirror]); | 95 [dynamicMirror, numMirror, dynamicMirror]); |
105 typeArguments(reflect(new I()).type, []); | 96 typeArguments(reflect(new I()).type, []); |
106 | 97 |
107 Expect.isFalse(reflect(new A<num>()).type.isOriginalDeclaration); | 98 Expect.isFalse(reflect(new A<num>()).type.isOriginalDeclaration); |
108 Expect.isTrue(reflect(new B()).type.isOriginalDeclaration); | 99 Expect.isTrue(reflect(new B()).type.isOriginalDeclaration); |
109 Expect.isTrue(reflect(new C()).type.isOriginalDeclaration); | 100 Expect.isTrue(reflect(new C()).type.isOriginalDeclaration); |
110 Expect.isTrue(reflect(new D()).type.isOriginalDeclaration); | 101 Expect.isTrue(reflect(new D()).type.isOriginalDeclaration); |
111 Expect.isFalse(reflect(new E<num>()).type.isOriginalDeclaration); | 102 Expect.isFalse(reflect(new E<num>()).type.isOriginalDeclaration); |
112 Expect.isFalse(reflect(new F<num>()).type.isOriginalDeclaration); | 103 Expect.isFalse(reflect(new F<num>()).type.isOriginalDeclaration); |
113 Expect.isTrue(reflect(new G()).type.isOriginalDeclaration); | 104 Expect.isTrue(reflect(new G()).type.isOriginalDeclaration); |
114 Expect.isFalse(reflect(new H()).type.isOriginalDeclaration); | 105 Expect.isFalse(reflect(new H()).type.isOriginalDeclaration); |
115 Expect.isTrue(reflect(new I()).type.isOriginalDeclaration); | 106 Expect.isTrue(reflect(new I()).type.isOriginalDeclaration); |
116 | 107 |
117 Expect.equals( | 108 Expect.equals(reflectClass(A), |
118 reflectClass(A), reflect(new A<num>()).type.originalDeclaration); | 109 reflect(new A<num>()).type.originalDeclaration); |
119 Expect.equals(reflectClass(B), reflect(new B()).type.originalDeclaration); | 110 Expect.equals(reflectClass(B), |
120 Expect.equals(reflectClass(C), reflect(new C()).type.originalDeclaration); | 111 reflect(new B()).type.originalDeclaration); |
121 Expect.equals(reflectClass(D), reflect(new D()).type.originalDeclaration); | 112 Expect.equals(reflectClass(C), |
122 Expect.equals( | 113 reflect(new C()).type.originalDeclaration); |
123 reflectClass(E), reflect(new E<num>()).type.originalDeclaration); | 114 Expect.equals(reflectClass(D), |
124 Expect.equals( | 115 reflect(new D()).type.originalDeclaration); |
125 reflectClass(F), reflect(new F<num>()).type.originalDeclaration); | 116 Expect.equals(reflectClass(E), |
126 Expect.equals(reflectClass(G), reflect(new G()).type.originalDeclaration); | 117 reflect(new E<num>()).type.originalDeclaration); |
127 Expect.equals(reflectClass(H), reflect(new H()).type.originalDeclaration); | 118 Expect.equals(reflectClass(F), |
128 Expect.equals(reflectClass(I), reflect(new I()).type.originalDeclaration); | 119 reflect(new F<num>()).type.originalDeclaration); |
| 120 Expect.equals(reflectClass(G), |
| 121 reflect(new G()).type.originalDeclaration); |
| 122 Expect.equals(reflectClass(H), |
| 123 reflect(new H()).type.originalDeclaration); |
| 124 Expect.equals(reflectClass(I), |
| 125 reflect(new I()).type.originalDeclaration); |
129 | 126 |
130 Expect.notEquals(reflect(new A<num>()).type, | 127 Expect.notEquals(reflect(new A<num>()).type, |
131 reflect(new A<num>()).type.originalDeclaration); | 128 reflect(new A<num>()).type.originalDeclaration); |
132 Expect.equals( | 129 Expect.equals(reflect(new B()).type, |
133 reflect(new B()).type, reflect(new B()).type.originalDeclaration); | 130 reflect(new B()).type.originalDeclaration); |
134 Expect.equals( | 131 Expect.equals(reflect(new C()).type, |
135 reflect(new C()).type, reflect(new C()).type.originalDeclaration); | 132 reflect(new C()).type.originalDeclaration); |
136 Expect.equals( | 133 Expect.equals(reflect(new D()).type, |
137 reflect(new D()).type, reflect(new D()).type.originalDeclaration); | 134 reflect(new D()).type.originalDeclaration); |
138 Expect.notEquals(reflect(new E<num>()).type, | 135 Expect.notEquals(reflect(new E<num>()).type, |
139 reflect(new E<num>()).type.originalDeclaration); | 136 reflect(new E<num>()).type.originalDeclaration); |
140 Expect.notEquals(reflect(new F<num>()).type, | 137 Expect.notEquals(reflect(new F<num>()).type, |
141 reflect(new F<num>()).type.originalDeclaration); | 138 reflect(new F<num>()).type.originalDeclaration); |
142 Expect.equals( | 139 Expect.equals(reflect(new G()).type, |
143 reflect(new G()).type, reflect(new G()).type.originalDeclaration); | 140 reflect(new G()).type.originalDeclaration); |
144 Expect.notEquals( | 141 Expect.notEquals(reflect(new H()).type, |
145 reflect(new H()).type, reflect(new H()).type.originalDeclaration); | 142 reflect(new H()).type.originalDeclaration); |
146 Expect.equals( | 143 Expect.equals(reflect(new I()).type, |
147 reflect(new I()).type, reflect(new I()).type.originalDeclaration); | 144 reflect(new I()).type.originalDeclaration); |
148 | 145 |
149 // Library members are all uninstantaited generics or non-generics. | 146 // Library members are all uninstantaited generics or non-generics. |
150 currentMirrorSystem().libraries.values.forEach((libraryMirror) { | 147 currentMirrorSystem().libraries.values.forEach((libraryMirror) { |
151 libraryMirror.declarations.values.forEach((declaration) { | 148 libraryMirror.declarations.values.forEach((declaration) { |
152 if (declaration is ClassMirror) { | 149 if (declaration is ClassMirror) { |
153 Expect.isTrue(declaration.isOriginalDeclaration); | 150 Expect.isTrue(declaration.isOriginalDeclaration); |
154 Expect.equals(declaration, declaration.originalDeclaration); | 151 Expect.equals(declaration, declaration.originalDeclaration); |
155 } | 152 } |
156 }); | 153 }); |
157 }); | 154 }); |
158 | 155 |
159 Expect.equals(reflectClass(A).typeVariables[0].owner, reflectClass(A)); | 156 Expect.equals(reflectClass(A).typeVariables[0].owner, reflectClass(A)); |
160 Expect.equals(reflectClass(Z).typeVariables[0].owner, reflectClass(Z)); | 157 Expect.equals(reflectClass(Z).typeVariables[0].owner, reflectClass(Z)); |
161 Expect.notEquals( | 158 Expect.notEquals(reflectClass(A).typeVariables[0], |
162 reflectClass(A).typeVariables[0], reflectClass(Z).typeVariables[0]); | 159 reflectClass(Z).typeVariables[0]); |
163 Expect.equals( | 160 Expect.equals(reflectClass(A).typeVariables[0], |
164 reflectClass(A).typeVariables[0], reflectClass(A).typeVariables[0]); | 161 reflectClass(A).typeVariables[0]); |
165 } | 162 } |
OLD | NEW |