| 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'); | 9 #import('../../../lib/compiler/implementation/util/characters.dart'); |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 while (0 <= index && index < text.length) { | 65 while (0 <= index && index < text.length) { |
| 66 var charCode = text.charCodeAt(index); | 66 var charCode = text.charCodeAt(index); |
| 67 if (charCode == $CR || charCode == $LF) { | 67 if (charCode == $CR || charCode == $LF) { |
| 68 break; | 68 break; |
| 69 } | 69 } |
| 70 index--; | 70 index--; |
| 71 column++; | 71 column++; |
| 72 } | 72 } |
| 73 return column; | 73 return column; |
| 74 } | 74 } |
| 75 |
| 76 class HierarchyIterable implements Iterable<InterfaceMirror> { |
| 77 final bool includeType; |
| 78 final InterfaceMirror type; |
| 79 |
| 80 HierarchyIterable(this.type, {bool includeType}) |
| 81 : this.includeType = includeType; |
| 82 |
| 83 Iterator<InterfaceMirror> iterator() => |
| 84 new HierarchyIterator(type, includeType: includeType); |
| 85 } |
| 86 |
| 87 /** |
| 88 * [HierarchyIterator] iterates through the class hierarchy of the provided |
| 89 * type. |
| 90 * |
| 91 * First is the superclass relation is traversed, skipping [Object], next the |
| 92 * superinterface relation and finally is [Object] visited. The supertypes are |
| 93 * visited in breadth first order and a superinterface is visited more than once |
| 94 * if implemented through multiple supertypes. |
| 95 */ |
| 96 class HierarchyIterator implements Iterator<InterfaceMirror> { |
| 97 final Queue<InterfaceMirror> queue = new Queue<InterfaceMirror>(); |
| 98 InterfaceMirror object; |
| 99 |
| 100 HierarchyIterator(InterfaceMirror type, {bool includeType}) { |
| 101 if (includeType) { |
| 102 queue.add(type); |
| 103 } else { |
| 104 push(type); |
| 105 } |
| 106 } |
| 107 |
| 108 InterfaceMirror push(InterfaceMirror type) { |
| 109 if (type.superclass !== null) { |
| 110 if (type.superclass.isObject) { |
| 111 object = type.superclass; |
| 112 } else { |
| 113 queue.addFirst(type.superclass); |
| 114 } |
| 115 } |
| 116 queue.addAll(type.interfaces); |
| 117 return type; |
| 118 } |
| 119 |
| 120 InterfaceMirror next() { |
| 121 InterfaceMirror type; |
| 122 if (queue.isEmpty()) { |
| 123 if (object === null) { |
| 124 throw new NoMoreElementsException(); |
| 125 } |
| 126 type = object; |
| 127 object = null; |
| 128 return type; |
| 129 } else { |
| 130 return push(queue.removeFirst()); |
| 131 } |
| 132 } |
| 133 |
| 134 bool hasNext() => !queue.isEmpty() || object !== null; |
| 135 } |
| OLD | NEW |