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 library test.generic_bounded; |
| 6 |
| 7 import 'dart:mirrors'; |
| 8 |
| 9 import 'package:expect/expect.dart'; |
| 10 |
| 11 import 'generics_test.dart'; |
| 12 |
| 13 class Interface<T> {} |
| 14 class Bounded<S extends num> {} |
| 15 |
| 16 class Fixed implements Interface<int> {} |
| 17 class Generic<R> implements Interface<R> {} |
| 18 |
| 19 class Bienbounded implements Bounded<int> {} |
| 20 class Malbounded implements Bounded<String> {} |
| 21 class FBounded implements Interface<FBounded> {} |
| 22 |
| 23 class Mixin {} |
| 24 class FixedMixinApplication = Object with Mixin implements Interface<int>; |
| 25 class GenericMixinApplication<X> = Object with Mixin implements Interface<X>; |
| 26 class FixedClass extends Object with Mixin implements Interface<int> {} |
| 27 class GenericClass<Y> extends Object with Mixin implements Interface<Y> {} |
| 28 |
| 29 main() { |
| 30 TypeMirror dynamicMirror = currentMirrorSystem().dynamicType; |
| 31 |
| 32 ClassMirror interfaceDecl = reflectClass(Interface); |
| 33 ClassMirror boundedDecl = reflectClass(Bounded); |
| 34 |
| 35 ClassMirror interfaceOfInt = reflectClass(Fixed).superinterfaces.single; |
| 36 ClassMirror interfaceOfR = reflectClass(Generic).superinterfaces.single; |
| 37 ClassMirror interfaceOfBool = reflect(new Generic<bool>()).type.superinterface
s.single; |
| 38 |
| 39 ClassMirror boundedOfInt = reflectClass(Bienbounded).superinterfaces.single; |
| 40 ClassMirror boundedOfString = reflectClass(Malbounded).superinterfaces.single; |
| 41 ClassMirror interfaceOfFBounded = reflectClass(FBounded).superinterfaces.singl
e; |
| 42 |
| 43 ClassMirror interfaceOfInt2 = reflectClass(FixedMixinApplication).superinterfa
ces.single; |
| 44 ClassMirror interfaceOfX = reflectClass(GenericMixinApplication).superinterfac
es.single; |
| 45 ClassMirror interfaceOfDouble = reflect(new GenericMixinApplication<double>())
.type.superinterfaces.single; |
| 46 ClassMirror interfaceOfInt3 = reflectClass(FixedClass).superinterfaces.single; |
| 47 ClassMirror interfaceOfY = reflectClass(GenericClass).superinterfaces.single; |
| 48 ClassMirror interfaceOfDouble2 = reflect(new GenericClass<double>()).type.supe
rinterfaces.single; |
| 49 |
| 50 |
| 51 Expect.isTrue(interfaceDecl.isOriginalDeclaration); |
| 52 Expect.isTrue(boundedDecl.isOriginalDeclaration); |
| 53 |
| 54 Expect.isFalse(interfaceOfInt.isOriginalDeclaration); |
| 55 Expect.isFalse(interfaceOfR.isOriginalDeclaration); |
| 56 Expect.isFalse(interfaceOfBool.isOriginalDeclaration); |
| 57 Expect.isFalse(boundedOfInt.isOriginalDeclaration); |
| 58 Expect.isFalse(boundedOfString.isOriginalDeclaration); |
| 59 Expect.isFalse(interfaceOfFBounded.isOriginalDeclaration); |
| 60 Expect.isFalse(interfaceOfInt2.isOriginalDeclaration); |
| 61 Expect.isFalse(interfaceOfX.isOriginalDeclaration); |
| 62 Expect.isFalse(interfaceOfDouble.isOriginalDeclaration); |
| 63 Expect.isFalse(interfaceOfInt3.isOriginalDeclaration); |
| 64 Expect.isFalse(interfaceOfY.isOriginalDeclaration); |
| 65 Expect.isFalse(interfaceOfDouble2.isOriginalDeclaration); |
| 66 |
| 67 |
| 68 TypeVariableMirror tFromInterface = interfaceDecl.typeVariables.single; |
| 69 TypeVariableMirror sFromBounded = boundedDecl.typeVariables.single; |
| 70 TypeVariableMirror rFromGeneric = reflectClass(Generic).typeVariables.single; |
| 71 TypeVariableMirror xFromGenericMixinApplication = reflectClass(GenericMixinApp
lication).typeVariables.single; |
| 72 TypeVariableMirror yFromGenericClass = reflectClass(GenericClass).typeVariable
s.single; |
| 73 |
| 74 Expect.equals(reflectClass(Object), tFromInterface.upperBound); |
| 75 Expect.equals(reflectClass(num), sFromBounded.upperBound); |
| 76 Expect.equals(reflectClass(Object), rFromGeneric.upperBound); |
| 77 Expect.equals(reflectClass(Object), xFromGenericMixinApplication.upperBound); |
| 78 Expect.equals(reflectClass(Object), yFromGenericClass.upperBound); |
| 79 |
| 80 |
| 81 typeParameters(interfaceDecl, [#T]); |
| 82 typeParameters(boundedDecl, [#S]); |
| 83 typeParameters(interfaceOfInt, [#T]); |
| 84 typeParameters(interfaceOfR, [#T]); |
| 85 typeParameters(interfaceOfBool, [#T]); |
| 86 typeParameters(boundedOfInt, [#S]); |
| 87 typeParameters(boundedOfString, [#S]); |
| 88 typeParameters(interfaceOfFBounded, [#T]); |
| 89 typeParameters(interfaceOfInt2, [#T]); |
| 90 typeParameters(interfaceOfX, [#T]); |
| 91 typeParameters(interfaceOfDouble, [#T]); |
| 92 typeParameters(interfaceOfInt3, [#T]); |
| 93 typeParameters(interfaceOfY, [#T]); |
| 94 typeParameters(interfaceOfDouble2, [#T]); |
| 95 |
| 96 typeArguments(interfaceDecl, []); |
| 97 typeArguments(boundedDecl, []); |
| 98 typeArguments(interfaceOfInt, [reflectClass(int)]); |
| 99 typeArguments(interfaceOfR, [rFromGeneric]); |
| 100 typeArguments(interfaceOfBool, [reflectClass(bool)]); /// 01: ok |
| 101 typeArguments(boundedOfInt, [reflectClass(int)]); |
| 102 typeArguments(boundedOfString, [reflectClass(String)]); |
| 103 typeArguments(interfaceOfFBounded, [reflectClass(FBounded)]); |
| 104 typeArguments(interfaceOfInt2, [reflectClass(int)]); |
| 105 typeArguments(interfaceOfX, [xFromGenericMixinApplication]); |
| 106 typeArguments(interfaceOfDouble, [reflectClass(double)]); /// 01: ok |
| 107 typeArguments(interfaceOfInt3, [reflectClass(int)]); |
| 108 typeArguments(interfaceOfY, [yFromGenericClass]); |
| 109 typeArguments(interfaceOfDouble2, [reflectClass(double)]); /// 01: ok |
| 110 } |
OLD | NEW |