| 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 | 10 |
| 11 class A<T> {} | 11 class A<T> {} |
| 12 class B extends A {} // Same as class B extends A<dynamic>. | 12 class B extends A {} // Same as class B extends A<dynamic>. |
| 13 class C extends A<num, int> {} // Same as class C extends A<dynamic>. | 13 class C extends A<num, int> {} // Same as class C extends A<dynamic>. |
| 14 class D extends A<int> {} | 14 class D extends A<int> {} |
| 15 class E<S> extends A<S> {} | 15 class E<S> extends A<S> {} |
| 16 class F<R> extends A<int> {} | 16 class F<R> extends A<int> {} |
| 17 class G {} | 17 class G {} |
| 18 class H<A,B,C> {} |
| 18 | 19 |
| 19 typeParameters(mirror, parameterNames) { | 20 typeParameters(mirror, parameterNames) { |
| 20 Expect.listEquals(parameterNames.map((n) => new Symbol(n)).toList(), | 21 Expect.listEquals(parameterNames.map((n) => new Symbol(n)).toList(), |
| 21 mirror.typeVariables.keys.toList()); | 22 mirror.typeVariables.keys.toList()); |
| 22 } | 23 } |
| 23 | 24 |
| 24 typeArguments(mirror, argumentMirrors) { | 25 typeArguments(mirror, argumentMirrors) { |
| 25 Expect.listEquals(argumentMirrors, | 26 Expect.listEquals(argumentMirrors, |
| 26 mirror.typeArguments.values.toList()); | 27 mirror.typeArguments.values.toList()); |
| 27 if (!mirror.isOriginalDeclaration) { | 28 if (!mirror.isOriginalDeclaration) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 Expect.equals(reflectClass(G), reflectClass(G).originalDeclaration); | 66 Expect.equals(reflectClass(G), reflectClass(G).originalDeclaration); |
| 66 | 67 |
| 67 // Instantiations. | 68 // Instantiations. |
| 68 typeParameters(reflect(new A<num>()).type, ['T']); | 69 typeParameters(reflect(new A<num>()).type, ['T']); |
| 69 typeParameters(reflect(new B<num>()).type, []); | 70 typeParameters(reflect(new B<num>()).type, []); |
| 70 typeParameters(reflect(new C()).type, []); | 71 typeParameters(reflect(new C()).type, []); |
| 71 typeParameters(reflect(new D()).type, []); | 72 typeParameters(reflect(new D()).type, []); |
| 72 typeParameters(reflect(new E()).type, ['S']); | 73 typeParameters(reflect(new E()).type, ['S']); |
| 73 typeParameters(reflect(new F<num>()).type, ['R']); | 74 typeParameters(reflect(new F<num>()).type, ['R']); |
| 74 typeParameters(reflect(new G()).type, []); | 75 typeParameters(reflect(new G()).type, []); |
| 76 typeParameters(reflect(new H()).type, ['A', 'B', 'C']); |
| 75 | 77 |
| 76 var numMirror = reflectClass(num); | 78 var numMirror = reflectClass(num); |
| 79 var dynamicMirror = currentMirrorSystem().dynamicType; |
| 77 typeArguments(reflect(new A<num>()).type, [numMirror]); | 80 typeArguments(reflect(new A<num>()).type, [numMirror]); |
| 81 typeArguments(reflect(new A<dynamic>()).type, [dynamicMirror]); |
| 82 typeArguments(reflect(new A()).type, [dynamicMirror]); |
| 78 typeArguments(reflect(new B()).type, []); | 83 typeArguments(reflect(new B()).type, []); |
| 79 typeArguments(reflect(new C()).type, []); | 84 typeArguments(reflect(new C()).type, []); |
| 80 typeArguments(reflect(new D()).type, []); | 85 typeArguments(reflect(new D()).type, []); |
| 81 typeArguments(reflect(new E<num>()).type, [numMirror]); | 86 typeArguments(reflect(new E<num>()).type, [numMirror]); |
| 87 typeArguments(reflect(new E<dynamic>()).type, [dynamicMirror]); |
| 88 typeArguments(reflect(new E()).type, [dynamicMirror]); |
| 82 typeArguments(reflect(new F<num>()).type, [numMirror]); | 89 typeArguments(reflect(new F<num>()).type, [numMirror]); |
| 90 typeArguments(reflect(new F<dynamic>()).type, [dynamicMirror]); |
| 91 typeArguments(reflect(new F()).type, [dynamicMirror]); |
| 83 typeArguments(reflect(new G()).type, []); | 92 typeArguments(reflect(new G()).type, []); |
| 93 typeArguments(reflect(new H<dynamic, num, dynamic>()).type, |
| 94 [dynamicMirror, numMirror, dynamicMirror]); |
| 84 | 95 |
| 85 Expect.isFalse(reflect(new A<num>()).type.isOriginalDeclaration); | 96 Expect.isFalse(reflect(new A<num>()).type.isOriginalDeclaration); |
| 86 Expect.isTrue(reflect(new B()).type.isOriginalDeclaration); | 97 Expect.isTrue(reflect(new B()).type.isOriginalDeclaration); |
| 87 Expect.isTrue(reflect(new C()).type.isOriginalDeclaration); | 98 Expect.isTrue(reflect(new C()).type.isOriginalDeclaration); |
| 88 Expect.isTrue(reflect(new D()).type.isOriginalDeclaration); | 99 Expect.isTrue(reflect(new D()).type.isOriginalDeclaration); |
| 89 Expect.isFalse(reflect(new E<num>()).type.isOriginalDeclaration); | 100 Expect.isFalse(reflect(new E<num>()).type.isOriginalDeclaration); |
| 90 Expect.isFalse(reflect(new F<num>()).type.isOriginalDeclaration); | 101 Expect.isFalse(reflect(new F<num>()).type.isOriginalDeclaration); |
| 91 Expect.isTrue(reflect(new G()).type.isOriginalDeclaration); | 102 Expect.isTrue(reflect(new G()).type.isOriginalDeclaration); |
| 103 Expect.isFalse(reflect(new H()).type.isOriginalDeclaration); |
| 92 | 104 |
| 93 Expect.equals(reflectClass(A), | 105 Expect.equals(reflectClass(A), |
| 94 reflect(new A<num>()).type.originalDeclaration); | 106 reflect(new A<num>()).type.originalDeclaration); |
| 95 Expect.equals(reflectClass(B), | 107 Expect.equals(reflectClass(B), |
| 96 reflect(new B()).type.originalDeclaration); | 108 reflect(new B()).type.originalDeclaration); |
| 97 Expect.equals(reflectClass(C), | 109 Expect.equals(reflectClass(C), |
| 98 reflect(new C()).type.originalDeclaration); | 110 reflect(new C()).type.originalDeclaration); |
| 99 Expect.equals(reflectClass(D), | 111 Expect.equals(reflectClass(D), |
| 100 reflect(new D()).type.originalDeclaration); | 112 reflect(new D()).type.originalDeclaration); |
| 101 Expect.equals(reflectClass(E), | 113 Expect.equals(reflectClass(E), |
| 102 reflect(new E<num>()).type.originalDeclaration); | 114 reflect(new E<num>()).type.originalDeclaration); |
| 103 Expect.equals(reflectClass(F), | 115 Expect.equals(reflectClass(F), |
| 104 reflect(new F<num>()).type.originalDeclaration); | 116 reflect(new F<num>()).type.originalDeclaration); |
| 105 Expect.equals(reflectClass(G), | 117 Expect.equals(reflectClass(G), |
| 106 reflect(new G()).type.originalDeclaration); | 118 reflect(new G()).type.originalDeclaration); |
| 119 Expect.equals(reflectClass(H), |
| 120 reflect(new H()).type.originalDeclaration); |
| 107 | 121 |
| 108 Expect.notEquals(reflect(new A<num>()).type, | 122 Expect.notEquals(reflect(new A<num>()).type, |
| 109 reflect(new A<num>()).type.originalDeclaration); | 123 reflect(new A<num>()).type.originalDeclaration); |
| 110 Expect.equals(reflect(new B()).type, | 124 Expect.equals(reflect(new B()).type, |
| 111 reflect(new B()).type.originalDeclaration); | 125 reflect(new B()).type.originalDeclaration); |
| 112 Expect.equals(reflect(new C()).type, | 126 Expect.equals(reflect(new C()).type, |
| 113 reflect(new C()).type.originalDeclaration); | 127 reflect(new C()).type.originalDeclaration); |
| 114 Expect.equals(reflect(new D()).type, | 128 Expect.equals(reflect(new D()).type, |
| 115 reflect(new D()).type.originalDeclaration); | 129 reflect(new D()).type.originalDeclaration); |
| 116 Expect.notEquals(reflect(new E<num>()).type, | 130 Expect.notEquals(reflect(new E<num>()).type, |
| 117 reflect(new E<num>()).type.originalDeclaration); | 131 reflect(new E<num>()).type.originalDeclaration); |
| 118 Expect.notEquals(reflect(new F<num>()).type, | 132 Expect.notEquals(reflect(new F<num>()).type, |
| 119 reflect(new F<num>()).type.originalDeclaration); | 133 reflect(new F<num>()).type.originalDeclaration); |
| 120 Expect.equals(reflect(new G()).type, | 134 Expect.equals(reflect(new G()).type, |
| 121 reflect(new G()).type.originalDeclaration); | 135 reflect(new G()).type.originalDeclaration); |
| 136 Expect.notEquals(reflect(new H()).type, |
| 137 reflect(new H()).type.originalDeclaration); |
| 122 | 138 |
| 123 // Library members are all uninstantaited generics or non-generics. | 139 // Library members are all uninstantaited generics or non-generics. |
| 124 currentMirrorSystem().libraries.values.forEach((libraryMirror) { | 140 currentMirrorSystem().libraries.values.forEach((libraryMirror) { |
| 125 libraryMirror.classes.values.forEach((classMirror) { | 141 libraryMirror.classes.values.forEach((classMirror) { |
| 126 // TODO(12282): Deal with generic typedefs. | 142 // TODO(12282): Deal with generic typedefs. |
| 127 if (classMirror is! TypedefMirror) { | 143 if (classMirror is! TypedefMirror) { |
| 128 Expect.isTrue(classMirror.isOriginalDeclaration); | 144 Expect.isTrue(classMirror.isOriginalDeclaration); |
| 129 Expect.equals(classMirror, classMirror.originalDeclaration); | 145 Expect.equals(classMirror, classMirror.originalDeclaration); |
| 130 } | 146 } |
| 131 }); | 147 }); |
| 132 }); | 148 }); |
| 133 } | 149 } |
| OLD | NEW |