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.reflected_type_test; | 5 library test.reflected_type_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 | 10 |
11 class A<T> {} | 11 class A<T> {} |
| 12 |
12 class B extends A {} | 13 class B extends A {} |
| 14 |
13 class C extends A<num, int> {} // //# 01: static type warning | 15 class C extends A<num, int> {} // //# 01: static type warning |
14 class D extends A<int> {} | 16 class D extends A<int> {} |
| 17 |
15 class E<S> extends A<S> {} | 18 class E<S> extends A<S> {} |
| 19 |
16 class F<R> extends A<int> {} | 20 class F<R> extends A<int> {} |
| 21 |
17 class G {} | 22 class G {} |
18 class H<A,B,C> {} | 23 |
| 24 class H<A, B, C> {} |
19 | 25 |
20 expectReflectedType(classMirror, expectedType) { | 26 expectReflectedType(classMirror, expectedType) { |
21 if (expectedType == null) { | 27 if (expectedType == null) { |
22 Expect.isFalse(classMirror.hasReflectedType, | 28 Expect.isFalse(classMirror.hasReflectedType, |
23 "$classMirror should not have a reflected type"); | 29 "$classMirror should not have a reflected type"); |
24 Expect.throws(() => classMirror.reflectedType, | 30 Expect.throws( |
25 (e) => e is UnsupportedError); | 31 () => classMirror.reflectedType, (e) => e is UnsupportedError); |
26 } else { | 32 } else { |
27 Expect.isTrue(classMirror.hasReflectedType, | 33 Expect.isTrue(classMirror.hasReflectedType, |
28 "$classMirror should have a reflected type"); | 34 "$classMirror should have a reflected type"); |
29 Expect.equals(expectedType, classMirror.reflectedType); | 35 Expect.equals(expectedType, classMirror.reflectedType); |
30 } | 36 } |
31 } | 37 } |
32 | 38 |
33 main() { | 39 main() { |
34 // Basic non-generic types, including intercepted types. | 40 // Basic non-generic types, including intercepted types. |
35 expectReflectedType(reflectClass(Object), Object); | 41 expectReflectedType(reflectClass(Object), Object); |
36 expectReflectedType(reflectClass(String), String); | 42 expectReflectedType(reflectClass(String), String); |
37 expectReflectedType(reflectClass(int), int); | 43 expectReflectedType(reflectClass(int), int); |
38 expectReflectedType(reflectClass(num), num); | 44 expectReflectedType(reflectClass(num), num); |
39 expectReflectedType(reflectClass(double), double); | 45 expectReflectedType(reflectClass(double), double); |
40 expectReflectedType(reflectClass(bool), bool); | 46 expectReflectedType(reflectClass(bool), bool); |
41 expectReflectedType(reflectClass(Null), Null); | 47 expectReflectedType(reflectClass(Null), Null); |
42 | 48 |
43 // Declarations. | 49 // Declarations. |
44 expectReflectedType(reflectClass(A), null); | 50 expectReflectedType(reflectClass(A), null); |
45 expectReflectedType(reflectClass(B), B); | 51 expectReflectedType(reflectClass(B), B); |
46 expectReflectedType(reflectClass(C), C); // //# 01: continued | 52 expectReflectedType(reflectClass(C), C); // //# 01: continued |
47 expectReflectedType(reflectClass(D), D); | 53 expectReflectedType(reflectClass(D), D); |
48 expectReflectedType(reflectClass(E), null); | 54 expectReflectedType(reflectClass(E), null); |
49 expectReflectedType(reflectClass(F), null); | 55 expectReflectedType(reflectClass(F), null); |
50 expectReflectedType(reflectClass(G), G); | 56 expectReflectedType(reflectClass(G), G); |
51 expectReflectedType(reflectClass(H), null); | 57 expectReflectedType(reflectClass(H), null); |
52 | 58 |
53 // Instantiations. | 59 // Instantiations. |
54 expectReflectedType(reflect(new A()).type, new A().runtimeType); | 60 expectReflectedType(reflect(new A()).type, new A().runtimeType); |
55 expectReflectedType(reflect(new B()).type, new B().runtimeType); | 61 expectReflectedType(reflect(new B()).type, new B().runtimeType); |
56 expectReflectedType(reflect(new C()).type, new C().runtimeType); // //# 01: co
ntinued | 62 expectReflectedType(reflect(new C()).type, new C().runtimeType); // //# 01: co
ntinued |
57 expectReflectedType(reflect(new D()).type, new D().runtimeType); | 63 expectReflectedType(reflect(new D()).type, new D().runtimeType); |
58 expectReflectedType(reflect(new E()).type, new E().runtimeType); | 64 expectReflectedType(reflect(new E()).type, new E().runtimeType); |
59 expectReflectedType(reflect(new F()).type, new F().runtimeType); | 65 expectReflectedType(reflect(new F()).type, new F().runtimeType); |
60 expectReflectedType(reflect(new G()).type, new G().runtimeType); | 66 expectReflectedType(reflect(new G()).type, new G().runtimeType); |
61 expectReflectedType(reflect(new H()).type, new H().runtimeType); | 67 expectReflectedType(reflect(new H()).type, new H().runtimeType); |
62 | 68 |
63 expectReflectedType(reflect(new A<num>()).type, new A<num>().runtimeType); | 69 expectReflectedType(reflect(new A<num>()).type, new A<num>().runtimeType); |
64 expectReflectedType(reflect(new B<num>()).type.superclass, // //# 02: static t
ype warning | 70 expectReflectedType(reflect(new B<num>()).type.superclass, // //# 02: static t
ype warning |
65 new A<dynamic>().runtimeType); // //# 02: continue
d | 71 new A<dynamic>().runtimeType); // //# 02: continue
d |
66 expectReflectedType(reflect(new C<num>()).type.superclass, // //# 01: continue
d | 72 expectReflectedType(reflect(new C<num>()).type.superclass, // //# 01: continue
d |
67 new A<dynamic>().runtimeType); // //# 01: continue
d | 73 new A<dynamic>().runtimeType); // //# 01: continue
d |
68 expectReflectedType(reflect(new D<num>()).type.superclass, // //# 03: static t
ype warning | 74 expectReflectedType(reflect(new D<num>()).type.superclass, // //# 03: static t
ype warning |
69 new A<int>().runtimeType); // //# 03: continue
d | 75 new A<int>().runtimeType); // //# 03: continue
d |
70 expectReflectedType(reflect(new E<num>()).type, new E<num>().runtimeType); | 76 expectReflectedType(reflect(new E<num>()).type, new E<num>().runtimeType); |
71 expectReflectedType(reflect(new E<num>()).type.superclass, | 77 expectReflectedType( |
72 new A<num>().runtimeType); | 78 reflect(new E<num>()).type.superclass, new A<num>().runtimeType); |
73 expectReflectedType(reflect(new F<num>()).type.superclass, | 79 expectReflectedType( |
74 new A<int>().runtimeType); | 80 reflect(new F<num>()).type.superclass, new A<int>().runtimeType); |
75 expectReflectedType(reflect(new F<num>()).type, new F<num>().runtimeType); | 81 expectReflectedType(reflect(new F<num>()).type, new F<num>().runtimeType); |
76 expectReflectedType(reflect(new H<num, num, num>()).type, | 82 expectReflectedType( |
77 new H<num, num, num>().runtimeType); | 83 reflect(new H<num, num, num>()).type, new H<num, num, num>().runtimeType); |
78 } | 84 } |
OLD | NEW |