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

Unified Diff: lib/compiler/implementation/elements/elements.dart

Issue 9873012: Move member-iterating code into ClassElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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
« no previous file with comments | « lib/compiler/implementation/compile_time_constants.dart ('k') | lib/compiler/implementation/emitter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/elements/elements.dart
diff --git a/lib/compiler/implementation/elements/elements.dart b/lib/compiler/implementation/elements/elements.dart
index 2db8b5c485eac375f3e0cb55e1bbefc1ea37af46..c1da9dc56336a3824608c1280028f9d14e37012b 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -779,6 +779,52 @@ class ClassElement extends ContainerElement {
return supertype === null ? null : supertype.element;
}
+ /**
+ * Runs through all members of this class.
+ *
+ * The enclosing class is passed to the callback. This is useful when
+ * [includeSuperMembers] is [:true:].
+ */
+ void forEachMember([void f(ClassElement enclosingClass, Element member),
ahe 2012/04/19 10:02:31 Why is f optional?
floitsch 2012/04/19 10:41:32 So that you can give it a name and put it last. It
ahe 2012/04/19 10:43:58 I see.
+ includeBackendMembers = false,
+ includeSuperMembers = false]) {
+ ClassElement classElement = this;
+ do {
+ for (Element element in classElement.members) {
+ f(classElement, element);
+ }
+ if (includeBackendMembers) {
+ for (Element element in classElement.backendMembers) {
+ f(classElement, element);
+ }
+ }
+ classElement = includeSuperMembers ? classElement.superclass : null;
+ } while(classElement !== null);
+ }
+
+ /**
+ * Runs through all instance-field members of this class.
+ *
+ * The enclosing class is passed to the callback. This is useful when
+ * [includeSuperMembers] is [:true:].
+ *
+ * When [includeBackendMembers] and [includeSuperMembers] are both [:true:]
+ * then the fields are visited in the same order as they need to be given
+ * to the JavaScript constructor.
+ */
+ void forEachInstanceField([void f(ClassElement enclosingClass, Element field),
ahe 2012/04/19 10:02:31 Ditto.
+ includeBackendMembers = false,
+ includeSuperMembers = false]) {
+ // Filters so that [f] is only invoked with instance fields.
+ void fieldFilter(ClassElement enclosingClass, Element member) {
+ if (member.isInstanceMember() && member.kind == ElementKind.FIELD) {
+ f(enclosingClass, member);
+ }
+ }
+
+ forEachMember(fieldFilter, includeBackendMembers, includeSuperMembers);
+ }
+
bool isInterface() => false;
bool isNative() => nativeName != null;
SourceString nativeName;
« no previous file with comments | « lib/compiler/implementation/compile_time_constants.dart ('k') | lib/compiler/implementation/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698