Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart b/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart |
| index fca92c4266dc3bed09e5cb87a326c363d2ac26f9..f7c857305434d2adb4a281db6d5c39e2d752c883 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart |
| @@ -180,44 +180,68 @@ Iterable<DeclarationMirror> membersOf( |
| Iterable<TypeMirror> classesOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where((mirror) => mirror is ClassMirror); |
| + return new _TypeOfIterable<ClassMirror>(declarations.values); |
| } |
| Iterable<TypeMirror> typesOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where((mirror) => mirror is TypeMirror); |
| + return new _TypeOfIterable<TypeMirror>(declarations.values); |
| } |
| Iterable<MethodMirror> methodsOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where( |
| - (mirror) => mirror is MethodMirror && mirror.isRegularMethod); |
| + return _anyMethodOf(declarations).where((mirror) => mirror.isRegularMethod); |
| } |
| Iterable<MethodMirror> constructorsOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where( |
| - (mirror) => mirror is MethodMirror && mirror.isConstructor); |
| + return _anyMethodOf(declarations).where((mirror) => mirror.isConstructor); |
| } |
| Iterable<MethodMirror> settersOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where( |
| - (mirror) => mirror is MethodMirror && mirror.isSetter); |
| + return _anyMethodOf(declarations).where((mirror) => mirror.isSetter); |
| } |
| Iterable<MethodMirror> gettersOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where( |
| - (mirror) => mirror is MethodMirror && mirror.isGetter); |
| + return _anyMethodOf(declarations).where((mirror) => mirror.isGetter); |
| } |
| +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.
|
| + 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.
|
| + new _TypeOfIterable<MethodMirror>(declarations.values); |
| + |
| Iterable<VariableMirror> variablesOf( |
| Map<Symbol, DeclarationMirror> declarations) { |
| - return declarations.values.where((mirror) => mirror is VariableMirror); |
| + return new _TypeOfIterable<VariableMirror>(declarations.values); |
| +} |
| + |
| +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.
|
| + final Iterable _source; |
| + |
| + _TypeOfIterable(this._source); |
| + |
| + 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.
|
| + new _TypeOfIterator<TTarget>(_source.iterator); |
| } |
| +class _TypeOfIterator<TTarget> implements Iterator<TTarget> { |
| + final Iterator _source; |
| + |
| + 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.
|
| + _TypeOfIterator(this._source); |
| + |
| + bool moveNext() { |
| + while(_source.moveNext()) { |
| + if (_source.current is TTarget) { |
| + return true; |
| + } |
| + } |
| + return false; |
| + } |
| +} |
| bool isObject(TypeMirror mirror) => |
| mirror is ClassMirror && mirror.superclass == null; |