OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('mirrors.util'); | 5 #library('mirrors.util'); |
6 | 6 |
7 #import('mirrors.dart'); | 7 #import('mirrors.dart'); |
8 | 8 |
9 //------------------------------------------------------------------------------ | 9 //------------------------------------------------------------------------------ |
10 // Utility functions for using the Mirror API | 10 // Utility functions for using the Mirror API |
11 //------------------------------------------------------------------------------ | 11 //------------------------------------------------------------------------------ |
12 | 12 |
13 /** | 13 /** |
14 * Returns an iterable over the type declarations directly inheriting from | 14 * Returns an iterable over the type declarations directly inheriting from |
15 * the declaration of this type. | 15 * the declaration of this type. |
16 */ | 16 */ |
17 Iterable<InterfaceMirror> computeSubdeclarations(MirrorSystem system, | 17 Iterable<InterfaceMirror> computeSubdeclarations(InterfaceMirror type) { |
18 InterfaceMirror type) { | |
19 type = type.declaration; | 18 type = type.declaration; |
20 var subtypes = <InterfaceMirror>[]; | 19 var subtypes = <InterfaceMirror>[]; |
21 system.libraries().forEach((_, library) { | 20 type.system.libraries().forEach((_, library) { |
22 for (InterfaceMirror otherType in library.types().getValues()) { | 21 for (InterfaceMirror otherType in library.types().getValues()) { |
23 var superClass = otherType.superclass(); | 22 var superClass = otherType.superclass(); |
24 if (superClass !== null) { | 23 if (superClass !== null) { |
25 superClass = superClass.declaration; | 24 superClass = superClass.declaration; |
26 if (type.library() === superClass.library()) { | 25 if (type.library() === superClass.library()) { |
27 if (superClass == type) { | 26 if (superClass == type) { |
28 subtypes.add(otherType); | 27 subtypes.add(otherType); |
29 } | 28 } |
30 } | 29 } |
31 } | 30 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 operatorName == mirror.operatorName) { | 62 operatorName == mirror.operatorName) { |
64 foundMirror = mirror; | 63 foundMirror = mirror; |
65 } | 64 } |
66 } else { | 65 } else { |
67 foundMirror = mirror; | 66 foundMirror = mirror; |
68 } | 67 } |
69 } | 68 } |
70 }); | 69 }); |
71 return foundMirror; | 70 return foundMirror; |
72 } | 71 } |
| 72 |
| 73 LibraryMirror findLibrary(MemberMirror member) { |
| 74 ObjectMirror owner = member.surroundingDeclaration(); |
| 75 if (owner is LibraryMirror) { |
| 76 return owner; |
| 77 } else if (owner is TypeMirror) { |
| 78 return owner.library(); |
| 79 } |
| 80 throw new Exception('Unexpected owner: ${owner}'); |
| 81 } |
OLD | NEW |