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

Side by Side Diff: lib/src/common/declarations.dart

Issue 1290643006: First cut at behaviors. This just implements the lifecycle methodsportion. We may get the rest for … (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698