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

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/NameOccurrencesFinder.java

Issue 9703096: Remove Element.getNode() method (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changes for review 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
Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/NameOccurrencesFinder.java
diff --git a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/NameOccurrencesFinder.java b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/NameOccurrencesFinder.java
index 6edb73042367a222f9e37045869c6a899542b46a..30766e4984f56c49dabbcba7334c4440f6e898b8 100644
--- a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/NameOccurrencesFinder.java
+++ b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/NameOccurrencesFinder.java
@@ -3,21 +3,15 @@ package com.google.dart.tools.core.utilities.ast;
import com.google.dart.compiler.ast.ASTVisitor;
import com.google.dart.compiler.ast.DartDeclaration;
import com.google.dart.compiler.ast.DartExpression;
-import com.google.dart.compiler.ast.DartFunction;
-import com.google.dart.compiler.ast.DartFunctionTypeAlias;
import com.google.dart.compiler.ast.DartInvocation;
-import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartNode;
-import com.google.dart.compiler.ast.DartParameter;
import com.google.dart.compiler.resolver.Element;
-import com.google.dart.compiler.resolver.VariableElement;
import java.util.ArrayList;
import java.util.List;
public class NameOccurrencesFinder extends ASTVisitor<Void> {
- private DartNode ast;
private Element target;
private List<DartNode> matches;
@@ -31,9 +25,7 @@ public class NameOccurrencesFinder extends ASTVisitor<Void> {
}
public void searchWithin(DartNode ast) {
- this.ast = ast;
- DartNode container = findTargetContainer();
- container.accept(this);
+ ast.accept(this);
}
@Override
@@ -67,29 +59,4 @@ public class NameOccurrencesFinder extends ASTVisitor<Void> {
}
return super.visitNode(node);
}
-
- private DartNode findAncestor(DartNode node, Class<?>... classes) {
- if (node == null) {
- return null;
- }
- Class<? extends DartNode> nodeClass = node.getClass();
- for (Class<?> ancestorClass : classes) {
- if (ancestorClass.isAssignableFrom(nodeClass)) {
- return node;
- }
- }
- return findAncestor(node.getParent(), classes);
- }
-
- private DartNode findTargetContainer() {
- if (target instanceof VariableElement) {
- return findAncestor(target.getNode(), DartMethodDefinition.class);
- } else if (target instanceof DartParameter) {
- // TODO determine all decls that can have parameters and include here
- return findAncestor(target.getNode(), DartMethodDefinition.class, DartFunction.class,
- DartFunctionTypeAlias.class);
- } else {
- return ast;
- }
- }
}

Powered by Google App Engine
This is Rietveld 408576698