Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1309)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 9
10 //------------------------------------------------------------------------------ 10 //------------------------------------------------------------------------------
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 LibraryMirror findLibrary(MemberMirror member) { 46 LibraryMirror findLibrary(MemberMirror member) {
47 DeclarationMirror owner = member.owner; 47 DeclarationMirror owner = member.owner;
48 if (owner is LibraryMirror) { 48 if (owner is LibraryMirror) {
49 return owner; 49 return owner;
50 } else if (owner is TypeMirror) { 50 } else if (owner is TypeMirror) {
51 return owner.library; 51 return owner.library;
52 } 52 }
53 throw new Exception('Unexpected owner: ${owner}'); 53 throw new Exception('Unexpected owner: ${owner}');
54 } 54 }
55 55
56 class HierarchyIterable implements Iterable<ClassMirror> { 56 class HierarchyIterable extends Iterable<ClassMirror> {
57 final bool includeType; 57 final bool includeType;
58 final ClassMirror type; 58 final ClassMirror type;
59 59
60 HierarchyIterable(this.type, {bool includeType}) 60 HierarchyIterable(this.type, {bool includeType})
61 : this.includeType = includeType; 61 : this.includeType = includeType;
62 62
63 Iterator<ClassMirror> iterator() => 63 Iterator<ClassMirror> get iterator =>
64 new HierarchyIterator(type, includeType: includeType); 64 new HierarchyIterator(type, includeType: includeType);
65 } 65 }
66 66
67 /** 67 /**
68 * [HierarchyIterator] iterates through the class hierarchy of the provided 68 * [HierarchyIterator] iterates through the class hierarchy of the provided
69 * type. 69 * type.
70 * 70 *
71 * First is the superclass relation is traversed, skipping [Object], next the 71 * First the superclass relation is traversed, skipping [Object], next the
72 * superinterface relation and finally is [Object] visited. The supertypes are 72 * superinterface relation and finally is [Object] visited. The supertypes are
73 * visited in breadth first order and a superinterface is visited more than once 73 * visited in breadth first order and a superinterface is visited more than once
74 * if implemented through multiple supertypes. 74 * if implemented through multiple supertypes.
75 */ 75 */
76 class HierarchyIterator implements Iterator<ClassMirror> { 76 class HierarchyIterator implements Iterator<ClassMirror> {
77 final Queue<ClassMirror> queue = new Queue<ClassMirror>(); 77 final Queue<ClassMirror> queue = new Queue<ClassMirror>();
78 ClassMirror object; 78 ClassMirror object;
79 ClassMirror _current;
79 80
80 HierarchyIterator(ClassMirror type, {bool includeType}) { 81 HierarchyIterator(ClassMirror type, {bool includeType}) {
81 if (includeType) { 82 if (includeType) {
82 queue.add(type); 83 queue.add(type);
83 } else { 84 } else {
84 push(type); 85 push(type);
85 } 86 }
86 } 87 }
87 88
88 ClassMirror push(ClassMirror type) { 89 ClassMirror push(ClassMirror type) {
89 if (type.superclass != null) { 90 if (type.superclass != null) {
90 if (type.superclass.isObject) { 91 if (type.superclass.isObject) {
91 object = type.superclass; 92 object = type.superclass;
92 } else { 93 } else {
93 queue.addFirst(type.superclass); 94 queue.addFirst(type.superclass);
94 } 95 }
95 } 96 }
96 queue.addAll(type.superinterfaces); 97 queue.addAll(type.superinterfaces);
97 return type; 98 return type;
98 } 99 }
99 100
100 ClassMirror next() { 101 ClassMirror get current => _current;
101 ClassMirror type; 102
103 bool moveNext() {
104 _current = null;
102 if (queue.isEmpty) { 105 if (queue.isEmpty) {
103 if (object == null) { 106 if (object == null) return false;
104 throw new StateError("No more elements"); 107 _current = object;
105 }
106 type = object;
107 object = null; 108 object = null;
108 return type; 109 return true;
109 } else { 110 } else {
110 return push(queue.removeFirst()); 111 _current = push(queue.removeFirst());
112 return true;
111 } 113 }
112 } 114 }
113
114 bool get hasNext => !queue.isEmpty || object != null;
115 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698