Index: tests/lib/mirrors/generic_interface_test.dart |
diff --git a/tests/lib/mirrors/generic_interface_test.dart b/tests/lib/mirrors/generic_interface_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8a2b9a0c16815927e89d062c3bb66600162d12c1 |
--- /dev/null |
+++ b/tests/lib/mirrors/generic_interface_test.dart |
@@ -0,0 +1,110 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library test.generic_bounded; |
+ |
+import 'dart:mirrors'; |
+ |
+import 'package:expect/expect.dart'; |
+ |
+import 'generics_test.dart'; |
+ |
+class Interface<T> {} |
+class Bounded<S extends num> {} |
+ |
+class Fixed implements Interface<int> {} |
+class Generic<R> implements Interface<R> {} |
+ |
+class Bienbounded implements Bounded<int> {} |
+class Malbounded implements Bounded<String> {} |
+class FBounded implements Interface<FBounded> {} |
+ |
+class Mixin {} |
+class FixedMixinApplication = Object with Mixin implements Interface<int>; |
+class GenericMixinApplication<X> = Object with Mixin implements Interface<X>; |
+class FixedClass extends Object with Mixin implements Interface<int> {} |
+class GenericClass<Y> extends Object with Mixin implements Interface<Y> {} |
+ |
+main() { |
+ TypeMirror dynamicMirror = currentMirrorSystem().dynamicType; |
+ |
+ ClassMirror interfaceDecl = reflectClass(Interface); |
+ ClassMirror boundedDecl = reflectClass(Bounded); |
+ |
+ ClassMirror interfaceOfInt = reflectClass(Fixed).superinterfaces.single; |
+ ClassMirror interfaceOfR = reflectClass(Generic).superinterfaces.single; |
+ ClassMirror interfaceOfBool = reflect(new Generic<bool>()).type.superinterfaces.single; |
+ |
+ ClassMirror boundedOfInt = reflectClass(Bienbounded).superinterfaces.single; |
+ ClassMirror boundedOfString = reflectClass(Malbounded).superinterfaces.single; |
+ ClassMirror interfaceOfFBounded = reflectClass(FBounded).superinterfaces.single; |
+ |
+ ClassMirror interfaceOfInt2 = reflectClass(FixedMixinApplication).superinterfaces.single; |
+ ClassMirror interfaceOfX = reflectClass(GenericMixinApplication).superinterfaces.single; |
+ ClassMirror interfaceOfDouble = reflect(new GenericMixinApplication<double>()).type.superinterfaces.single; |
+ ClassMirror interfaceOfInt3 = reflectClass(FixedClass).superinterfaces.single; |
+ ClassMirror interfaceOfY = reflectClass(GenericClass).superinterfaces.single; |
+ ClassMirror interfaceOfDouble2 = reflect(new GenericClass<double>()).type.superinterfaces.single; |
+ |
+ |
+ Expect.isTrue(interfaceDecl.isOriginalDeclaration); |
+ Expect.isTrue(boundedDecl.isOriginalDeclaration); |
+ |
+ Expect.isFalse(interfaceOfInt.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfR.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfBool.isOriginalDeclaration); |
+ Expect.isFalse(boundedOfInt.isOriginalDeclaration); |
+ Expect.isFalse(boundedOfString.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfFBounded.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfInt2.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfX.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfDouble.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfInt3.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfY.isOriginalDeclaration); |
+ Expect.isFalse(interfaceOfDouble2.isOriginalDeclaration); |
+ |
+ |
+ TypeVariableMirror tFromInterface = interfaceDecl.typeVariables.single; |
+ TypeVariableMirror sFromBounded = boundedDecl.typeVariables.single; |
+ TypeVariableMirror rFromGeneric = reflectClass(Generic).typeVariables.single; |
+ TypeVariableMirror xFromGenericMixinApplication = reflectClass(GenericMixinApplication).typeVariables.single; |
+ TypeVariableMirror yFromGenericClass = reflectClass(GenericClass).typeVariables.single; |
+ |
+ Expect.equals(reflectClass(Object), tFromInterface.upperBound); |
+ Expect.equals(reflectClass(num), sFromBounded.upperBound); |
+ Expect.equals(reflectClass(Object), rFromGeneric.upperBound); |
+ Expect.equals(reflectClass(Object), xFromGenericMixinApplication.upperBound); |
+ Expect.equals(reflectClass(Object), yFromGenericClass.upperBound); |
+ |
+ |
+ typeParameters(interfaceDecl, [#T]); |
+ typeParameters(boundedDecl, [#S]); |
+ typeParameters(interfaceOfInt, [#T]); |
+ typeParameters(interfaceOfR, [#T]); |
+ typeParameters(interfaceOfBool, [#T]); |
+ typeParameters(boundedOfInt, [#S]); |
+ typeParameters(boundedOfString, [#S]); |
+ typeParameters(interfaceOfFBounded, [#T]); |
+ typeParameters(interfaceOfInt2, [#T]); |
+ typeParameters(interfaceOfX, [#T]); |
+ typeParameters(interfaceOfDouble, [#T]); |
+ typeParameters(interfaceOfInt3, [#T]); |
+ typeParameters(interfaceOfY, [#T]); |
+ typeParameters(interfaceOfDouble2, [#T]); |
+ |
+ typeArguments(interfaceDecl, []); |
+ typeArguments(boundedDecl, []); |
+ typeArguments(interfaceOfInt, [reflectClass(int)]); |
+ typeArguments(interfaceOfR, [rFromGeneric]); |
+ typeArguments(interfaceOfBool, [reflectClass(bool)]); /// 01: ok |
+ typeArguments(boundedOfInt, [reflectClass(int)]); |
+ typeArguments(boundedOfString, [reflectClass(String)]); |
+ typeArguments(interfaceOfFBounded, [reflectClass(FBounded)]); |
+ typeArguments(interfaceOfInt2, [reflectClass(int)]); |
+ typeArguments(interfaceOfX, [xFromGenericMixinApplication]); |
+ typeArguments(interfaceOfDouble, [reflectClass(double)]); /// 01: ok |
+ typeArguments(interfaceOfInt3, [reflectClass(int)]); |
+ typeArguments(interfaceOfY, [yFromGenericClass]); |
+ typeArguments(interfaceOfDouble2, [reflectClass(double)]); /// 01: ok |
+} |