Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library polymer.src.common.declarations; | 1 library polymer.src.common.declarations; |
| 2 | 2 |
| 3 import 'package:reflectable/reflectable.dart'; | 3 import 'package:reflectable/reflectable.dart'; |
| 4 import '../../polymer_micro.dart'; | |
| 4 | 5 |
| 5 typedef bool _WhereFn(String name, DeclarationMirror declaration); | 6 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
| |
| 7 typedef bool _ClassWhereFn(ClassMirror mirror); | |
| 8 | |
| 9 List<ClassMirror> mixinsFor( | |
| 10 Type type, Reflectable reflectionClass, {_ClassWhereFn where}) { | |
| 11 var typeMirror = _reflect(type, reflectionClass); | |
| 12 var mixins = []; | |
| 13 var superClass = _getSuper(typeMirror); | |
| 14 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.
| |
| 15 var mixin = superClass.mixin; | |
| 16 if (mixin != superClass && (where == null || where(mixin))) { | |
| 17 mixins.add(mixin); | |
| 18 } | |
| 19 superClass = _getSuper(superClass); | |
| 20 } | |
| 21 return mixins.reversed.toList(); | |
| 22 } | |
| 6 | 23 |
| 7 Map<String, DeclarationMirror> declarationsFor( | 24 Map<String, DeclarationMirror> declarationsFor( |
| 8 Type type, Reflectable reflectionClass, {_WhereFn where}) { | 25 Type type, Reflectable reflectionClass, {_DeclarationWhereFn where}) { |
| 9 var typeMirror; | 26 var typeMirror = _reflect(type, reflectionClass); |
| 10 try { | |
| 11 typeMirror = reflectionClass.reflectType(type); | |
| 12 } catch (e) { | |
| 13 throw 'type $type is missing the $reflectionClass annotation'; | |
| 14 } | |
| 15 var declarations = {}; | 27 var declarations = {}; |
| 16 var superClass = typeMirror; | 28 var superClass = typeMirror; |
| 17 while (superClass != null && superClass.reflectedType != Object) { | 29 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
| |
| 18 superClass.declarations.forEach((name, declaration) { | 30 superClass.declarations.forEach((name, declaration) { |
| 19 if (declarations.containsKey(name)) return; | 31 if (declarations.containsKey(name)) return; |
| 20 if (where != null && !where(name, declaration)) return; | 32 if (where != null && !where(name, declaration)) return; |
| 21 declarations[name] = declaration; | 33 declarations[name] = declaration; |
| 22 }); | 34 }); |
| 23 superClass = _getSuper(superClass); | 35 superClass = _getSuper(superClass); |
| 24 } | 36 } |
| 25 return declarations; | 37 return declarations; |
| 26 } | 38 } |
| 27 | 39 |
| 40 ClassMirror _reflect(Type type, Reflectable reflectionClass) { | |
| 41 try { | |
| 42 return reflectionClass.reflectType(type); | |
| 43 } catch (e) { | |
| 44 throw 'type $type is missing the $reflectionClass annotation'; | |
| 45 } | |
| 46 } | |
| 47 | |
| 28 ClassMirror _getSuper(ClassMirror clazz) { | 48 ClassMirror _getSuper(ClassMirror clazz) { |
| 29 // Currently throws post-transform if superclass isn't annotated with a | 49 // Currently throws post-transform if superclass isn't annotated with a |
| 30 // [Reflectable] class. | 50 // [Reflectable] class. |
| 31 try { | 51 try { |
| 32 return clazz.superclass; | 52 return clazz.superclass; |
| 33 } catch(e) { | 53 } catch(e) { |
| 34 return null; | 54 return null; |
| 35 } | 55 } |
| 36 } | 56 } |
| 37 | 57 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 55 bool isSetter(DeclarationMirror declaration) { | 75 bool isSetter(DeclarationMirror declaration) { |
| 56 return declaration is MethodMirror && declaration.isSetter; | 76 return declaration is MethodMirror && declaration.isSetter; |
| 57 } | 77 } |
| 58 | 78 |
| 59 bool hasSetter(MethodMirror getterDeclaration) { | 79 bool hasSetter(MethodMirror getterDeclaration) { |
| 60 assert(getterDeclaration.isGetter); | 80 assert(getterDeclaration.isGetter); |
| 61 var owner = getterDeclaration.owner; | 81 var owner = getterDeclaration.owner; |
| 62 assert(owner is LibraryMirror || owner is ClassMirror); | 82 assert(owner is LibraryMirror || owner is ClassMirror); |
| 63 return owner.declarations.containsKey('${getterDeclaration.simpleName}='); | 83 return owner.declarations.containsKey('${getterDeclaration.simpleName}='); |
| 64 } | 84 } |
| OLD | NEW |