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.declarations_test; | 5 library test.declarations_test; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 import 'stringify.dart'; | 10 import 'stringify.dart'; |
11 import 'declarations_model.dart' as declarations_model; | 11 import 'declarations_model.dart' as declarations_model; |
12 | 12 |
13 castMirror(Mirror m) { | |
14 if (m is DeclarationMirror) return m as DeclarationMirror; | |
15 if (m is VariableMirror) return m as VariableMirror; | |
16 if (m is TypeVariableMirror) return m as TypeVariableMirror; | |
17 return m; | |
18 } | |
Bob Nystrom
2017/08/23 22:10:06
The "as" expressions aren't accomplishing anything
| |
19 | |
13 Set<DeclarationMirror> inheritedDeclarations(ClassMirror cm) { | 20 Set<DeclarationMirror> inheritedDeclarations(ClassMirror cm) { |
14 var decls = new Set<DeclarationMirror>(); | 21 var decls = new Set<DeclarationMirror>(); |
15 while (cm != null) { | 22 while (cm != null) { |
16 decls.addAll(cm.declarations.values); | 23 decls.addAll(cm.declarations.values); |
17 cm = cm.superclass; | 24 cm = cm.superclass; |
18 } | 25 } |
19 return decls; | 26 return decls; |
20 } | 27 } |
21 | 28 |
22 main() { | 29 main() { |
(...skipping 25 matching lines...) Expand all Loading... | |
48 'Method(s(_staticSetter=) in s(Class), private, static, setter)', | 55 'Method(s(_staticSetter=) in s(Class), private, static, setter)', |
49 'Method(s(instanceSetter=) in s(Class), setter)', | 56 'Method(s(instanceSetter=) in s(Class), setter)', |
50 'Method(s(staticSetter=) in s(Class), static, setter)' | 57 'Method(s(staticSetter=) in s(Class), static, setter)' |
51 ], | 58 ], |
52 cm.declarations.values | 59 cm.declarations.values |
53 .where((dm) => dm is MethodMirror && dm.isSetter) | 60 .where((dm) => dm is MethodMirror && dm.isSetter) |
54 .map(stringify), | 61 .map(stringify), |
55 'setters'); | 62 'setters'); |
56 | 63 |
57 // dart2js stops testing here. | 64 // dart2js stops testing here. |
58 return; // //# 01: ok | 65 return; //# 01: ok |
59 | 66 |
60 Expect.setEquals( | 67 Expect.setEquals( |
61 [ | 68 [ |
62 'Method(s(+) in s(Class))', | 69 'Method(s(+) in s(Class))', |
63 'Method(s(_instanceMethod) in s(Class), private)', | 70 'Method(s(_instanceMethod) in s(Class), private)', |
64 'Method(s(_staticMethod) in s(Class), private, static)', | 71 'Method(s(_staticMethod) in s(Class), private, static)', |
65 'Method(s(abstractMethod) in s(Class), abstract)', | 72 'Method(s(abstractMethod) in s(Class), abstract)', |
66 'Method(s(instanceMethod) in s(Class))', | 73 'Method(s(instanceMethod) in s(Class))', |
67 'Method(s(staticMethod) in s(Class), static)' | 74 'Method(s(staticMethod) in s(Class), static)' |
68 ], | 75 ], |
(...skipping 13 matching lines...) Expand all Loading... | |
82 'Method(s(Class.generativeConstructor) in s(Class), constructor)', | 89 'Method(s(Class.generativeConstructor) in s(Class), constructor)', |
83 'Method(s(Class.normalFactory) in s(Class), static, constructor)', | 90 'Method(s(Class.normalFactory) in s(Class), static, constructor)', |
84 'Method(s(Class.redirectingConstructor) in s(Class), constructor)', | 91 'Method(s(Class.redirectingConstructor) in s(Class), constructor)', |
85 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)' | 92 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)' |
86 ], | 93 ], |
87 cm.declarations.values | 94 cm.declarations.values |
88 .where((dm) => dm is MethodMirror && dm.isConstructor) | 95 .where((dm) => dm is MethodMirror && dm.isConstructor) |
89 .map(stringify), | 96 .map(stringify), |
90 'constructors and factories'); | 97 'constructors and factories'); |
91 | 98 |
92 Expect.setEquals([ | 99 Expect.setEquals( |
93 'Method(s(Class._normalFactory) in s(Class), private, static, constructor)', | 100 [ |
94 'Method(s(Class._redirectingFactory)' | 101 'Method(s(Class._normalFactory) in s(Class), private, static, constructo r)', |
95 ' in s(Class), private, static, constructor)', | 102 'Method(s(Class._redirectingFactory)' |
96 'Method(s(Class.normalFactory) in s(Class), static, constructor)', | 103 ' in s(Class), private, static, constructor)', |
97 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)', | 104 'Method(s(Class.normalFactory) in s(Class), static, constructor)', |
98 'Method(s(_staticGetter) in s(Class), private, static, getter)', | 105 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)', |
99 'Method(s(_staticMethod) in s(Class), private, static)', | 106 'Method(s(_staticGetter) in s(Class), private, static, getter)', |
100 'Method(s(_staticSetter=) in s(Class), private, static, setter)', | 107 'Method(s(_staticMethod) in s(Class), private, static)', |
101 'Variable(s(_staticVariable) in s(Class), private, static)', | 108 'Method(s(_staticSetter=) in s(Class), private, static, setter)', |
102 'Method(s(staticGetter) in s(Class), static, getter)', | 109 'Variable(s(_staticVariable) in s(Class), private, static)', |
103 'Method(s(staticMethod) in s(Class), static)', | 110 'Method(s(staticGetter) in s(Class), static, getter)', |
104 'Method(s(staticSetter=) in s(Class), static, setter)', | 111 'Method(s(staticMethod) in s(Class), static)', |
105 'Variable(s(staticVariable) in s(Class), static)' | 112 'Method(s(staticSetter=) in s(Class), static, setter)', |
106 ], cm.declarations.values.where((dm) => dm.isStatic).map(stringify), | 113 'Variable(s(staticVariable) in s(Class), static)' |
114 ], | |
115 cm.declarations.values | |
116 .where((dm) => castMirror(dm).isStatic) | |
Bob Nystrom
2017/08/23 22:10:05
You can just do:
(dm) => (dm as dynamic).isStatic
| |
117 .map(stringify), | |
107 'statics'); | 118 'statics'); |
108 | 119 |
109 Expect.setEquals([ | 120 Expect.setEquals( |
110 'Method(s(+) in s(Class))', | 121 [ |
111 'TypeVariable(s(C) in s(Class),' | 122 'Method(s(+) in s(Class))', |
112 ' upperBound = Class(s(Object) in s(dart.core), top-level))', | 123 'TypeVariable(s(C) in s(Class),' |
113 'Method(s(Class._generativeConstructor) in s(Class), private, constructor)', | 124 ' upperBound = Class(s(Object) in s(dart.core), top-level))', |
114 'Method(s(Class._redirectingConstructor)' | 125 'Method(s(Class._generativeConstructor) in s(Class), private, constructo r)', |
115 ' in s(Class), private, constructor)', | 126 'Method(s(Class._redirectingConstructor)' |
116 'Method(s(Class.generativeConstructor) in s(Class), constructor)', | 127 ' in s(Class), private, constructor)', |
117 'Method(s(Class.redirectingConstructor) in s(Class), constructor)', | 128 'Method(s(Class.generativeConstructor) in s(Class), constructor)', |
118 'Method(s(_instanceGetter) in s(Class), private, getter)', | 129 'Method(s(Class.redirectingConstructor) in s(Class), constructor)', |
119 'Method(s(_instanceMethod) in s(Class), private)', | 130 'Method(s(_instanceGetter) in s(Class), private, getter)', |
120 'Method(s(_instanceSetter=) in s(Class), private, setter)', | 131 'Method(s(_instanceMethod) in s(Class), private)', |
121 'Variable(s(_instanceVariable) in s(Class), private)', | 132 'Method(s(_instanceSetter=) in s(Class), private, setter)', |
122 'Method(s(abstractMethod) in s(Class), abstract)', | 133 'Variable(s(_instanceVariable) in s(Class), private)', |
123 'Method(s(instanceGetter) in s(Class), getter)', | 134 'Method(s(abstractMethod) in s(Class), abstract)', |
124 'Method(s(instanceMethod) in s(Class))', | 135 'Method(s(instanceGetter) in s(Class), getter)', |
125 'Method(s(instanceSetter=) in s(Class), setter)', | 136 'Method(s(instanceMethod) in s(Class))', |
126 'Variable(s(instanceVariable) in s(Class))' | 137 'Method(s(instanceSetter=) in s(Class), setter)', |
127 ], cm.declarations.values.where((dm) => !dm.isStatic).map(stringify), | 138 'Variable(s(instanceVariable) in s(Class))' |
139 ], | |
140 cm.declarations.values | |
141 .where((dm) => !castMirror(dm).isStatic) | |
142 .map(stringify), | |
128 'non-statics'); | 143 'non-statics'); |
129 | 144 |
130 Expect.setEquals([ | 145 Expect.setEquals( |
131 'Method(s(+) in s(Class))', | 146 [ |
132 'TypeVariable(s(C) in s(Class),' | 147 'Method(s(+) in s(Class))', |
133 ' upperBound = Class(s(Object) in s(dart.core), top-level))', | 148 'TypeVariable(s(C) in s(Class),' |
134 'Method(s(Class.generativeConstructor) in s(Class), constructor)', | 149 ' upperBound = Class(s(Object) in s(dart.core), top-level))', |
135 'Method(s(Class.normalFactory) in s(Class), static, constructor)', | 150 'Method(s(Class.generativeConstructor) in s(Class), constructor)', |
136 'Method(s(Class.redirectingConstructor) in s(Class), constructor)', | 151 'Method(s(Class.normalFactory) in s(Class), static, constructor)', |
137 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)', | 152 'Method(s(Class.redirectingConstructor) in s(Class), constructor)', |
138 'Method(s(abstractMethod) in s(Class), abstract)', | 153 'Method(s(Class.redirectingFactory) in s(Class), static, constructor)', |
139 'Method(s(instanceGetter) in s(Class), getter)', | 154 'Method(s(abstractMethod) in s(Class), abstract)', |
140 'Method(s(instanceMethod) in s(Class))', | 155 'Method(s(instanceGetter) in s(Class), getter)', |
141 'Method(s(instanceSetter=) in s(Class), setter)', | 156 'Method(s(instanceMethod) in s(Class))', |
142 'Variable(s(instanceVariable) in s(Class))', | 157 'Method(s(instanceSetter=) in s(Class), setter)', |
143 'Method(s(staticGetter) in s(Class), static, getter)', | 158 'Variable(s(instanceVariable) in s(Class))', |
144 'Method(s(staticMethod) in s(Class), static)', | 159 'Method(s(staticGetter) in s(Class), static, getter)', |
145 'Method(s(staticSetter=) in s(Class), static, setter)', | 160 'Method(s(staticMethod) in s(Class), static)', |
146 'Variable(s(staticVariable) in s(Class), static)' | 161 'Method(s(staticSetter=) in s(Class), static, setter)', |
147 ], cm.declarations.values.where((dm) => !dm.isPrivate).map(stringify), | 162 'Variable(s(staticVariable) in s(Class), static)' |
163 ], | |
164 cm.declarations.values | |
165 .where((dm) => !castMirror(dm).isPrivate) | |
166 .map(stringify), | |
148 'public'); | 167 'public'); |
149 | 168 |
150 Expect.setEquals([ | 169 Expect.setEquals([ |
151 'Method(s(*) in s(Mixin))', | 170 'Method(s(*) in s(Mixin))', |
152 'Method(s(+) in s(Class))', | 171 'Method(s(+) in s(Class))', |
153 'Method(s(-) in s(Superclass))', | 172 'Method(s(-) in s(Superclass))', |
154 'Method(s(==) in s(Object))', | 173 'Method(s(==) in s(Object))', |
155 'TypeVariable(s(C) in s(Class),' | 174 'TypeVariable(s(C) in s(Class),' |
156 ' upperBound = Class(s(Object) in s(dart.core), top-level))', | 175 ' upperBound = Class(s(Object) in s(dart.core), top-level))', |
157 'Method(s(Class.generativeConstructor) in s(Class), constructor)', | 176 'Method(s(Class.generativeConstructor) in s(Class), constructor)', |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 'Method(s(_mixinStaticSetter=) in s(Mixin), private, static, setter)', | 366 'Method(s(_mixinStaticSetter=) in s(Mixin), private, static, setter)', |
348 'Method(s(_mixinStaticMethod) in s(Mixin), private, static)' | 367 'Method(s(_mixinStaticMethod) in s(Mixin), private, static)' |
349 ], | 368 ], |
350 inheritedDeclarations(cm) | 369 inheritedDeclarations(cm) |
351 .difference(reflectClass(Object).declarations.values.toSet()) | 370 .difference(reflectClass(Object).declarations.values.toSet()) |
352 .map(stringify), | 371 .map(stringify), |
353 'transitive less Object'); | 372 'transitive less Object'); |
354 // The private members of Object may vary across implementations, so we | 373 // The private members of Object may vary across implementations, so we |
355 // exclude the declarations of Object in this test case. | 374 // exclude the declarations of Object in this test case. |
356 } | 375 } |
OLD | NEW |