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

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

Issue 258753004: Use UnmodifiableMapView in compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 import 'dart:collection' show Queue, IterableBase; 7 import 'dart:collection' show Queue, IterableBase;
8 8
9 import 'source_mirrors.dart'; 9 import 'source_mirrors.dart';
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 Iterable<DeclarationMirror> membersOf( 175 Iterable<DeclarationMirror> membersOf(
176 Map<Symbol, DeclarationMirror> declarations) { 176 Map<Symbol, DeclarationMirror> declarations) {
177 return declarations.values.where( 177 return declarations.values.where(
178 (mirror) => mirror is MethodMirror || mirror is VariableMirror); 178 (mirror) => mirror is MethodMirror || mirror is VariableMirror);
179 } 179 }
180 180
181 Iterable<TypeMirror> classesOf( 181 Iterable<TypeMirror> classesOf(
182 Map<Symbol, DeclarationMirror> declarations) { 182 Map<Symbol, DeclarationMirror> declarations) {
183 return declarations.values.where((mirror) => mirror is ClassMirror); 183 return new _TypeOfIterable<ClassMirror>(declarations.values);
184 } 184 }
185 185
186 Iterable<TypeMirror> typesOf( 186 Iterable<TypeMirror> typesOf(
187 Map<Symbol, DeclarationMirror> declarations) { 187 Map<Symbol, DeclarationMirror> declarations) {
188 return declarations.values.where((mirror) => mirror is TypeMirror); 188 return new _TypeOfIterable<TypeMirror>(declarations.values);
189 } 189 }
190 190
191 Iterable<MethodMirror> methodsOf( 191 Iterable<MethodMirror> methodsOf(
192 Map<Symbol, DeclarationMirror> declarations) { 192 Map<Symbol, DeclarationMirror> declarations) {
193 return declarations.values.where( 193 return _anyMethodOf(declarations).where((mirror) => mirror.isRegularMethod);
194 (mirror) => mirror is MethodMirror && mirror.isRegularMethod);
195 } 194 }
196 195
197 Iterable<MethodMirror> constructorsOf( 196 Iterable<MethodMirror> constructorsOf(
198 Map<Symbol, DeclarationMirror> declarations) { 197 Map<Symbol, DeclarationMirror> declarations) {
199 return declarations.values.where( 198 return _anyMethodOf(declarations).where((mirror) => mirror.isConstructor);
200 (mirror) => mirror is MethodMirror && mirror.isConstructor);
201 } 199 }
202 200
203 Iterable<MethodMirror> settersOf( 201 Iterable<MethodMirror> settersOf(
204 Map<Symbol, DeclarationMirror> declarations) { 202 Map<Symbol, DeclarationMirror> declarations) {
205 return declarations.values.where( 203 return _anyMethodOf(declarations).where((mirror) => mirror.isSetter);
206 (mirror) => mirror is MethodMirror && mirror.isSetter);
207 } 204 }
208 205
209 Iterable<MethodMirror> gettersOf( 206 Iterable<MethodMirror> gettersOf(
210 Map<Symbol, DeclarationMirror> declarations) { 207 Map<Symbol, DeclarationMirror> declarations) {
211 return declarations.values.where( 208 return _anyMethodOf(declarations).where((mirror) => mirror.isGetter);
212 (mirror) => mirror is MethodMirror && mirror.isGetter);
213 } 209 }
214 210
211 Iterable<MethodMirror> _anyMethodOf(
herhut 2014/04/28 08:24:41 Maybe expose this (docgen seems to be a good use c
kevmoo 2014/04/28 09:23:01 Done.
212 Map<Symbol, DeclarationMirror> declarations) =>
herhut 2014/04/28 08:24:41 Nit: Do not use => across line breaks, use {} inst
kevmoo 2014/04/28 09:23:01 Done.
213 new _TypeOfIterable<MethodMirror>(declarations.values);
214
215 Iterable<VariableMirror> variablesOf( 215 Iterable<VariableMirror> variablesOf(
216 Map<Symbol, DeclarationMirror> declarations) { 216 Map<Symbol, DeclarationMirror> declarations) {
217 return declarations.values.where((mirror) => mirror is VariableMirror); 217 return new _TypeOfIterable<VariableMirror>(declarations.values);
218 } 218 }
219 219
220 class _TypeOfIterable<TTarget> extends IterableBase<TTarget> {
herhut 2014/04/28 08:24:41 I prefer T for type variables.
kevmoo 2014/04/28 09:23:01 Done.
221 final Iterable _source;
220 222
223 _TypeOfIterable(this._source);
224
225 Iterator<TTarget> get iterator =>
herhut 2014/04/28 08:24:41 Nit: Do not use => across line breaks.
kevmoo 2014/04/28 09:23:01 Done.
226 new _TypeOfIterator<TTarget>(_source.iterator);
227 }
228
229 class _TypeOfIterator<TTarget> implements Iterator<TTarget> {
230 final Iterator _source;
231
232 TTarget get current => _source.current as TTarget;
herhut 2014/04/28 08:24:41 Do you really need an as check here?
kevmoo 2014/04/28 09:23:01 Done.
233
234 _TypeOfIterator(this._source);
235
236 bool moveNext() {
237 while(_source.moveNext()) {
238 if (_source.current is TTarget) {
239 return true;
240 }
241 }
242 return false;
243 }
244 }
221 245
222 bool isObject(TypeMirror mirror) => 246 bool isObject(TypeMirror mirror) =>
223 mirror is ClassMirror && mirror.superclass == null; 247 mirror is ClassMirror && mirror.superclass == null;
224 248
225 /// Returns `true` if [cls] is declared in a private dart library. 249 /// Returns `true` if [cls] is declared in a private dart library.
226 bool isFromPrivateDartLibrary(ClassMirror cls) { 250 bool isFromPrivateDartLibrary(ClassMirror cls) {
227 if (isMixinApplication(cls)) cls = cls.mixin; 251 if (isMixinApplication(cls)) cls = cls.mixin;
228 var uri = getLibrary(cls).uri; 252 var uri = getLibrary(cls).uri;
229 return uri.scheme == 'dart' && uri.path.startsWith('_'); 253 return uri.scheme == 'dart' && uri.path.startsWith('_');
230 } 254 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Try type variables. 420 // Try type variables.
397 result = mirror.typeVariables.firstWhere( 421 result = mirror.typeVariables.firstWhere(
398 (TypeVariableMirror v) => v.simpleName == id, orElse: () => null); 422 (TypeVariableMirror v) => v.simpleName == id, orElse: () => null);
399 } else if (mirror is MethodMirror) { 423 } else if (mirror is MethodMirror) {
400 result = mirror.parameters.firstWhere( 424 result = mirror.parameters.firstWhere(
401 (ParameterMirror p) => p.simpleName == id, orElse: () => null); 425 (ParameterMirror p) => p.simpleName == id, orElse: () => null);
402 } 426 }
403 return result; 427 return result;
404 428
405 } 429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698