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 // Ensure that classes handled specially by dart2js can be reflected on. | 5 // Ensure that classes handled specially by dart2js can be reflected on. |
6 | 6 |
7 library test.intercepted_class_test; | 7 library test.intercepted_class_test; |
8 | 8 |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
| 10 import 'package:expect/expect.dart'; |
10 | 11 |
11 import 'stringify.dart' show stringify, expect; | 12 import 'stringify.dart' show stringify, expect; |
12 | 13 |
13 checkClassMirror(ClassMirror cls, String name) { | 14 checkClassMirror(ClassMirror cls, String name) { |
14 expect('s($name)', cls.simpleName); | 15 bool foundInterface = false; |
| 16 for(ClassMirror cm = cls; cm != null; cm = cm.superclass) { |
| 17 if (MirrorSystem.getName(cm.simpleName) == name) foundInterface = true; |
| 18 cm.superinterfaces.forEach((intf) { |
| 19 if (MirrorSystem.getName(intf.simpleName) == name) foundInterface = true; |
| 20 }); |
| 21 } |
| 22 Expect.isTrue(foundInterface, '$cls should implement $name'); |
| 23 |
15 var variables = new Map(); | 24 var variables = new Map(); |
16 cls.variables.forEach((Symbol key, VariableMirror value) { | 25 for(ClassMirror cm = cls; cm != null; cm = cm.superclass) { |
17 if (!value.isStatic && !value.isPrivate) { | 26 cm.variables.forEach((Symbol key, VariableMirror value) { |
18 variables[key] = value; | 27 if (!value.isStatic && !value.isPrivate) { |
19 } | 28 variables[key] = value; |
20 }); | 29 } |
| 30 }); |
| 31 } |
21 expect('{}', variables); | 32 expect('{}', variables); |
22 } | 33 } |
23 | 34 |
24 main() { | 35 main() { |
25 checkClassMirror(reflectClass(String), 'String'); | 36 checkClassMirror(reflectClass(String), 'String'); |
26 checkClassMirror(reflectClass(int), 'int'); | 37 checkClassMirror(reflectClass(int), 'int'); |
27 checkClassMirror(reflectClass(double), 'double'); | 38 checkClassMirror(reflectClass(double), 'double'); |
28 checkClassMirror(reflectClass(num), 'num'); | 39 checkClassMirror(reflectClass(num), 'num'); |
29 checkClassMirror(reflectClass(bool), 'bool'); | 40 checkClassMirror(reflectClass(bool), 'bool'); |
30 checkClassMirror(reflectClass(List), 'List'); | 41 checkClassMirror(reflectClass(List), 'List'); |
31 } | 42 } |
OLD | NEW |