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

Unified Diff: pkg/serialization/lib/src/mirrors_helpers.dart

Issue 11644030: Rename specialTreatmentFor, improve handling of constants as constructor parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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: pkg/serialization/lib/src/mirrors_helpers.dart
diff --git a/pkg/serialization/lib/src/mirrors_helpers.dart b/pkg/serialization/lib/src/mirrors_helpers.dart
index 078aea0e8d1f653b8e0ded882c91ce1603cb30f7..b67eccac8bc30049df452547ecab3585b033b7fa 100644
--- a/pkg/serialization/lib/src/mirrors_helpers.dart
+++ b/pkg/serialization/lib/src/mirrors_helpers.dart
@@ -28,9 +28,19 @@ List<VariableMirror> publicFields(ClassMirror mirror) {
}
}
+/** Return true if the class has a field named [name]. Note that this
+ * includes private fields, but excludes statics. */
+bool hasField(String name, ClassMirror mirror) {
+ var field = mirror.variables[name];
+ if (field != null && !field.isStatic) return true;
+ var superclass = mirror.superclass;
+ if (superclass == mirror) return false;
+ return hasField(name, superclass);
+}
+
/**
- * Return a list of all the public getters of a class, including inherited
- * getters.
+ * Return a list of all the getters of a class, including inherited
+ * getters. Note that this allows private getters, but excludes statics.
*/
List<MethodMirror> publicGetters(ClassMirror mirror) {
var mine = mirror.getters.values.filter((x) => !(x.isPrivate || x.isStatic));
@@ -42,6 +52,15 @@ List<MethodMirror> publicGetters(ClassMirror mirror) {
}
}
+/** Return true if the class has a getter named [name] */
+bool hasGetter(String name, ClassMirror mirror) {
+ var getter = mirror.getters[name];
+ if (getter != null && !getter.isStatic) return true;
+ var superclass = mirror.superclass;
+ if (superclass == mirror) return false;
+ return hasField(name, superclass);
+}
+
/**
* Return a list of all the public getters of a class which have corresponding
* setters.

Powered by Google App Engine
This is Rietveld 408576698