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 #import('../../compiler/implementation/util/characters.dart'); |
8 | 9 |
9 //------------------------------------------------------------------------------ | 10 //------------------------------------------------------------------------------ |
10 // Utility functions for using the Mirror API | 11 // Utility functions for using the Mirror API |
11 //------------------------------------------------------------------------------ | 12 //------------------------------------------------------------------------------ |
12 | 13 |
13 /** | 14 /** |
14 * Returns an iterable over the type declarations directly inheriting from | 15 * Returns an iterable over the type declarations directly inheriting from |
15 * the declaration of this type. | 16 * the declaration of this type. |
16 */ | 17 */ |
17 Iterable<InterfaceMirror> computeSubdeclarations(MirrorSystem system, | 18 Iterable<InterfaceMirror> computeSubdeclarations(InterfaceMirror type) { |
18 InterfaceMirror type) { | |
19 type = type.declaration; | 19 type = type.declaration; |
20 var subtypes = <InterfaceMirror>[]; | 20 var subtypes = <InterfaceMirror>[]; |
21 system.libraries().forEach((_, library) { | 21 type.system.libraries().forEach((_, library) { |
22 for (InterfaceMirror otherType in library.types().getValues()) { | 22 for (InterfaceMirror otherType in library.types().getValues()) { |
23 var superClass = otherType.superclass(); | 23 var superClass = otherType.superclass(); |
24 if (superClass !== null) { | 24 if (superClass !== null) { |
25 superClass = superClass.declaration; | 25 superClass = superClass.declaration; |
26 if (type.library() === superClass.library()) { | 26 if (type.library() === superClass.library()) { |
27 if (superClass == type) { | 27 if (superClass == type) { |
28 subtypes.add(otherType); | 28 subtypes.add(otherType); |
29 } | 29 } |
30 } | 30 } |
31 } | 31 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 operatorName == mirror.operatorName) { | 63 operatorName == mirror.operatorName) { |
64 foundMirror = mirror; | 64 foundMirror = mirror; |
65 } | 65 } |
66 } else { | 66 } else { |
67 foundMirror = mirror; | 67 foundMirror = mirror; |
68 } | 68 } |
69 } | 69 } |
70 }); | 70 }); |
71 return foundMirror; | 71 return foundMirror; |
72 } | 72 } |
| 73 |
| 74 LibraryMirror findLibrary(MemberMirror member) { |
| 75 ObjectMirror owner = member.surroundingDeclaration(); |
| 76 if (owner is LibraryMirror) { |
| 77 return owner; |
| 78 } else if (owner is TypeMirror) { |
| 79 return owner.library(); |
| 80 } |
| 81 throw new Exception('Unexpected owner: ${owner}'); |
| 82 } |
| 83 |
| 84 |
| 85 /** |
| 86 * Returns the column of the start of a location. |
| 87 */ |
| 88 int getLocationColumn(Location location) { |
| 89 String text = location.source().text(); |
| 90 int index = location.start()-1; |
| 91 var column = 0; |
| 92 while (0 <= index && index < text.length) { |
| 93 var charCode = text.charCodeAt(index); |
| 94 if (charCode == $CR || charCode == $LF) { |
| 95 break; |
| 96 } |
| 97 index--; |
| 98 column++; |
| 99 } |
| 100 return column; |
| 101 } |
OLD | NEW |