| 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 // TODO(rnystrom): Use "package:" URL (#4968). | 7 // TODO(rnystrom): Use "package:" URL (#4968). |
| 8 import 'mirrors.dart'; | 8 import 'mirrors.dart'; |
| 9 import '../../../lib/compiler/implementation/util/characters.dart'; | |
| 10 | 9 |
| 11 //------------------------------------------------------------------------------ | 10 //------------------------------------------------------------------------------ |
| 12 // Utility functions for using the Mirror API | 11 // Utility functions for using the Mirror API |
| 13 //------------------------------------------------------------------------------ | 12 //------------------------------------------------------------------------------ |
| 14 | 13 |
| 15 /** | 14 /** |
| 16 * Returns an iterable over the type declarations directly inheriting from | 15 * Returns an iterable over the type declarations directly inheriting from |
| 17 * the declaration of this type. | 16 * the declaration of this type. |
| 18 */ | 17 */ |
| 19 Iterable<ClassMirror> computeSubdeclarations(ClassMirror type) { | 18 Iterable<ClassMirror> computeSubdeclarations(ClassMirror type) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 subtypes.add(otherType); | 37 subtypes.add(otherType); |
| 39 } | 38 } |
| 40 } | 39 } |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 }); | 42 }); |
| 44 return subtypes; | 43 return subtypes; |
| 45 } | 44 } |
| 46 | 45 |
| 47 LibraryMirror findLibrary(MemberMirror member) { | 46 LibraryMirror findLibrary(MemberMirror member) { |
| 48 ContainerMirror owner = member.owner; | 47 DeclarationMirror owner = member.owner; |
| 49 if (owner is LibraryMirror) { | 48 if (owner is LibraryMirror) { |
| 50 return owner; | 49 return owner; |
| 51 } else if (owner is TypeMirror) { | 50 } else if (owner is TypeMirror) { |
| 52 return owner.library; | 51 return owner.library; |
| 53 } | 52 } |
| 54 throw new Exception('Unexpected owner: ${owner}'); | 53 throw new Exception('Unexpected owner: ${owner}'); |
| 55 } | 54 } |
| 56 | 55 |
| 57 | |
| 58 /** | |
| 59 * Returns the column of the start of a location. | |
| 60 */ | |
| 61 int getLocationColumn(SourceLocation location) { | |
| 62 String text = location.source.text; | |
| 63 int index = location.start-1; | |
| 64 var column = 0; | |
| 65 while (0 <= index && index < text.length) { | |
| 66 var charCode = text.charCodeAt(index); | |
| 67 if (charCode == $CR || charCode == $LF) { | |
| 68 break; | |
| 69 } | |
| 70 index--; | |
| 71 column++; | |
| 72 } | |
| 73 return column; | |
| 74 } | |
| 75 | |
| 76 class HierarchyIterable implements Iterable<ClassMirror> { | 56 class HierarchyIterable implements Iterable<ClassMirror> { |
| 77 final bool includeType; | 57 final bool includeType; |
| 78 final ClassMirror type; | 58 final ClassMirror type; |
| 79 | 59 |
| 80 HierarchyIterable(this.type, {bool includeType}) | 60 HierarchyIterable(this.type, {bool includeType}) |
| 81 : this.includeType = includeType; | 61 : this.includeType = includeType; |
| 82 | 62 |
| 83 Iterator<ClassMirror> iterator() => | 63 Iterator<ClassMirror> iterator() => |
| 84 new HierarchyIterator(type, includeType: includeType); | 64 new HierarchyIterator(type, includeType: includeType); |
| 85 } | 65 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 type = object; | 106 type = object; |
| 127 object = null; | 107 object = null; |
| 128 return type; | 108 return type; |
| 129 } else { | 109 } else { |
| 130 return push(queue.removeFirst()); | 110 return push(queue.removeFirst()); |
| 131 } | 111 } |
| 132 } | 112 } |
| 133 | 113 |
| 134 bool get hasNext => !queue.isEmpty || object != null; | 114 bool get hasNext => !queue.isEmpty || object != null; |
| 135 } | 115 } |
| OLD | NEW |