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