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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/common/declarations.dart
diff --git a/lib/src/common/declarations.dart b/lib/src/common/declarations.dart
index 121bd8ab38e6961374ffa903acda94964f28c7a1..ec5227e322d07fe57699768deacb267c6cb3422e 100644
--- a/lib/src/common/declarations.dart
+++ b/lib/src/common/declarations.dart
@@ -1,20 +1,33 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
library polymer.src.common.declarations;
import 'package:reflectable/reflectable.dart';
+import '../../polymer_micro.dart';
-typedef bool _WhereFn(String name, DeclarationMirror declaration);
+List<ClassMirror> mixinsFor(Type type, Reflectable reflectionClass,
+ {bool where(ClassMirror mirror)}) {
+ var typeMirror = _reflect(type, reflectionClass);
+ var mixins = [];
+ var superClass = _getSuper(typeMirror);
+ while (superClass != null && superClass.mixin.reflectedType != PolymerMixin) {
+ 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, {_WhereFn where}) {
- var typeMirror;
- try {
- typeMirror = reflectionClass.reflectType(type);
- } catch (e) {
- throw 'type $type is missing the $reflectionClass annotation';
- }
+ Type type, Reflectable reflectionClass,
+ {bool where(String name, DeclarationMirror declaration)}) {
+ var typeMirror = _reflect(type, reflectionClass);
var declarations = {};
var superClass = typeMirror;
- while (superClass != null && superClass.reflectedType != Object) {
+ while (superClass != null && superClass.mixin.reflectedType != PolymerMixin) {
superClass.declarations.forEach((name, declaration) {
if (declarations.containsKey(name)) return;
if (where != null && !where(name, declaration)) return;
@@ -25,12 +38,20 @@ 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.
try {
return clazz.superclass;
- } catch(e) {
+ } catch (e) {
return null;
}
}
@@ -48,6 +69,7 @@ bool isProperty(DeclarationMirror declaration) {
if (declaration is MethodMirror) return !isRegularMethod(declaration);
return false;
}
+
bool isRegularMethod(DeclarationMirror declaration) {
return declaration is MethodMirror && declaration.isRegularMethod;
}

Powered by Google App Engine
This is Rietveld 408576698