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