OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.world.class_set; | 5 library dart2js.world.class_set; |
6 | 6 |
7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
8 import '../elements/elements.dart' show ClassElement; | 8 import '../elements/elements.dart' show ClassElement; |
9 import '../util/util.dart' show Link; | 9 import '../util/util.dart' show Link; |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 bool strict: false}) { | 95 bool strict: false}) { |
96 return new ClassHierarchyNodeIterable( | 96 return new ClassHierarchyNodeIterable( |
97 this, | 97 this, |
98 includeRoot: !strict, | 98 includeRoot: !strict, |
99 includeDirectlyInstantiated: includeDirectlyInstantiated, | 99 includeDirectlyInstantiated: includeDirectlyInstantiated, |
100 includeIndirectlyInstantiated: includeIndirectlyInstantiated, | 100 includeIndirectlyInstantiated: includeIndirectlyInstantiated, |
101 includeUninstantiated: includeUninstantiated); | 101 includeUninstantiated: includeUninstantiated); |
102 } | 102 } |
103 | 103 |
104 void printOn(StringBuffer sb, String indentation, | 104 void printOn(StringBuffer sb, String indentation, |
105 {bool instantiatedOnly: false}) { | 105 {bool instantiatedOnly: false, |
106 ClassElement withRespectTo}) { | |
107 | |
108 bool isRelatedTo(ClassElement subclass) { | |
109 return subclass.implementsInterface(withRespectTo); | |
110 } | |
111 | |
106 sb.write('$indentation$cls'); | 112 sb.write('$indentation$cls'); |
107 if (isDirectlyInstantiated) { | 113 if (isDirectlyInstantiated) { |
108 sb.write(' directly'); | 114 sb.write(' directly'); |
109 } | 115 } |
110 if (isIndirectlyInstantiated) { | 116 if (isIndirectlyInstantiated) { |
111 sb.write(' indirectly'); | 117 sb.write(' indirectly'); |
112 } | 118 } |
113 sb.write(' ['); | 119 sb.write(' ['); |
114 if (_directSubclasses.isEmpty) { | 120 if (_directSubclasses.isEmpty) { |
115 sb.write(']'); | 121 sb.write(']'); |
116 } else { | 122 } else { |
117 bool needsComma = false; | 123 bool needsComma = false; |
118 for (Link<ClassHierarchyNode> link = _directSubclasses; | 124 for (Link<ClassHierarchyNode> link = _directSubclasses; |
119 !link.isEmpty; | 125 !link.isEmpty; |
120 link = link.tail) { | 126 link = link.tail) { |
121 if (instantiatedOnly && !link.head.isInstantiated) { | 127 ClassHierarchyNode child = link.head; |
128 if (instantiatedOnly && !child.isInstantiated) { | |
122 continue; | 129 continue; |
123 } | 130 } |
131 if (withRespectTo != null) { | |
floitsch
2015/10/13 12:15:42
if (withRespectTo != null && !child.subclasses().a
Johnni Winther
2015/10/13 13:06:37
Done.
| |
132 if (!child.subclasses().any(isRelatedTo)) { | |
133 continue; | |
134 } | |
135 } | |
124 if (needsComma) { | 136 if (needsComma) { |
125 sb.write(',\n'); | 137 sb.write(',\n'); |
126 } else { | 138 } else { |
127 sb.write('\n'); | 139 sb.write('\n'); |
128 } | 140 } |
129 link.head.printOn( | 141 child.printOn( |
130 sb, '$indentation ', instantiatedOnly: instantiatedOnly); | 142 sb, |
143 '$indentation ', | |
144 instantiatedOnly: instantiatedOnly, | |
145 withRespectTo: withRespectTo); | |
131 needsComma = true; | 146 needsComma = true; |
132 } | 147 } |
133 if (needsComma) { | 148 if (needsComma) { |
134 sb.write('\n'); | 149 sb.write('\n'); |
135 sb.write('$indentation]'); | 150 sb.write('$indentation]'); |
136 } else { | 151 } else { |
137 sb.write(']'); | 152 sb.write(']'); |
138 } | 153 } |
139 } | 154 } |
140 } | 155 } |
141 | 156 |
142 String dump({String indentation: '', bool instantiatedOnly: false}) { | 157 String dump({String indentation: '', |
158 bool instantiatedOnly: false, | |
159 ClassElement withRespectTo}) { | |
143 StringBuffer sb = new StringBuffer(); | 160 StringBuffer sb = new StringBuffer(); |
144 printOn(sb, indentation, instantiatedOnly: instantiatedOnly); | 161 printOn(sb, indentation, |
162 instantiatedOnly: instantiatedOnly, | |
163 withRespectTo: withRespectTo); | |
145 return sb.toString(); | 164 return sb.toString(); |
146 } | 165 } |
147 | 166 |
148 String toString() => cls.toString(); | 167 String toString() => cls.toString(); |
149 } | 168 } |
150 | 169 |
151 /// Object holding the subclass and subtype relation for a single | 170 /// Object holding the subclass and subtype relation for a single |
152 /// [ClassElement]. | 171 /// [ClassElement]. |
153 /// | 172 /// |
154 /// The subclass relation for a class `C` is modelled through a reference to | 173 /// The subclass relation for a class `C` is modelled through a reference to |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 includeDirectlyInstantiated: includeDirectlyInstantiated, | 511 includeDirectlyInstantiated: includeDirectlyInstantiated, |
493 includeIndirectlyInstantiated: includeIndirectlyInstantiated, | 512 includeIndirectlyInstantiated: includeIndirectlyInstantiated, |
494 includeUninstantiated: includeUninstantiated).iterator; | 513 includeUninstantiated: includeUninstantiated).iterator; |
495 if (elements.moveNext()) { | 514 if (elements.moveNext()) { |
496 return true; | 515 return true; |
497 } | 516 } |
498 } | 517 } |
499 return false; | 518 return false; |
500 } | 519 } |
501 } | 520 } |
OLD | NEW |