Chromium Code Reviews| Index: lib/src/common/declarations.dart |
| diff --git a/lib/src/common/declarations.dart b/lib/src/common/declarations.dart |
| index 121bd8ab38e6961374ffa903acda94964f28c7a1..9a22249e1f535b3a67f795316992c7122f3481ef 100644 |
| --- a/lib/src/common/declarations.dart |
| +++ b/lib/src/common/declarations.dart |
| @@ -1,20 +1,32 @@ |
| library polymer.src.common.declarations; |
| import 'package:reflectable/reflectable.dart'; |
| +import '../../polymer_micro.dart'; |
| -typedef bool _WhereFn(String name, DeclarationMirror declaration); |
| +typedef bool _DeclarationWhereFn(String name, DeclarationMirror declaration); |
|
Siggi Cherem (dart-lang)
2015/08/12 22:43:15
naming nit: maybe use Function or Callback instead
jakemac
2015/08/13 17:50:45
Opted for the inline type annotation, I forgot you
|
| +typedef bool _ClassWhereFn(ClassMirror mirror); |
| -Map<String, DeclarationMirror> declarationsFor( |
| - Type type, Reflectable reflectionClass, {_WhereFn where}) { |
| - var typeMirror; |
| - try { |
| - typeMirror = reflectionClass.reflectType(type); |
| - } catch (e) { |
| - throw 'type $type is missing the $reflectionClass annotation'; |
| +List<ClassMirror> mixinsFor( |
| + Type type, Reflectable reflectionClass, {_ClassWhereFn where}) { |
| + var typeMirror = _reflect(type, reflectionClass); |
| + var mixins = []; |
| + var superClass = _getSuper(typeMirror); |
| + while(superClass != null && superClass.reflectedType != PolymerElement) { |
|
Siggi Cherem (dart-lang)
2015/08/12 22:43:15
run formatter
jakemac
2015/08/13 17:50:45
Done.
|
| + var mixin = superClass.mixin; |
| + if (mixin != superClass && (where == null || where(mixin))) { |
| + mixins.add(mixin); |
| + } |
| + superClass = _getSuper(superClass); |
| } |
| + return mixins.reversed.toList(); |
| +} |
| + |
| +Map<String, DeclarationMirror> declarationsFor( |
| + Type type, Reflectable reflectionClass, {_DeclarationWhereFn where}) { |
| + var typeMirror = _reflect(type, reflectionClass); |
| var declarations = {}; |
| var superClass = typeMirror; |
| - while (superClass != null && superClass.reflectedType != Object) { |
| + while (superClass != null && superClass.reflectedType != PolymerElement) { |
|
Siggi Cherem (dart-lang)
2015/08/12 22:43:15
just to double check - do we ever need to fetch so
jakemac
2015/08/13 17:50:45
Its fine to stop at PolymerElement, although I act
|
| superClass.declarations.forEach((name, declaration) { |
| if (declarations.containsKey(name)) return; |
| if (where != null && !where(name, declaration)) return; |
| @@ -25,6 +37,14 @@ Map<String, DeclarationMirror> declarationsFor( |
| return declarations; |
| } |
| +ClassMirror _reflect(Type type, Reflectable reflectionClass) { |
| + try { |
| + return reflectionClass.reflectType(type); |
| + } catch (e) { |
| + throw 'type $type is missing the $reflectionClass annotation'; |
| + } |
| +} |
| + |
| ClassMirror _getSuper(ClassMirror clazz) { |
| // Currently throws post-transform if superclass isn't annotated with a |
| // [Reflectable] class. |