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

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/index/contributor/IndexContributor.java

Issue 10918260: Issue 5044. Keep FieldElement as Element for field access (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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/internal/index/contributor/IndexContributor.java
diff --git a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/index/contributor/IndexContributor.java b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/index/contributor/IndexContributor.java
index 8712733ff809d263ef45874233f49e9722eb244d..15d42cec3ebf81d709bcfb3c2c82d6c06bda2358 100644
--- a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/index/contributor/IndexContributor.java
+++ b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/index/contributor/IndexContributor.java
@@ -14,11 +14,11 @@
package com.google.dart.tools.core.internal.index.contributor;
import com.google.common.base.Objects;
+import com.google.dart.compiler.ast.ASTNodes;
import com.google.dart.compiler.ast.ASTVisitor;
import com.google.dart.compiler.ast.DartArrayAccess;
import com.google.dart.compiler.ast.DartBinaryExpression;
import com.google.dart.compiler.ast.DartClass;
-import com.google.dart.compiler.ast.DartClassMember;
import com.google.dart.compiler.ast.DartDeclaration;
import com.google.dart.compiler.ast.DartExpression;
import com.google.dart.compiler.ast.DartField;
@@ -39,7 +39,6 @@ import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartPropertyAccess;
import com.google.dart.compiler.ast.DartRedirectConstructorInvocation;
import com.google.dart.compiler.ast.DartSourceDirective;
-import com.google.dart.compiler.ast.DartStatement;
import com.google.dart.compiler.ast.DartStringLiteral;
import com.google.dart.compiler.ast.DartSuperConstructorInvocation;
import com.google.dart.compiler.ast.DartTypeNode;
@@ -362,6 +361,7 @@ public class IndexContributor extends ASTVisitor<Void> {
return null;
}
com.google.dart.compiler.resolver.Element element = node.getElement();
+ // no resolved Element, potential match
if (element == null) {
DartNode parent = node.getParent();
if (parent instanceof DartMethodInvocation
@@ -373,33 +373,41 @@ public class IndexContributor extends ASTVisitor<Void> {
createLocation(node));
}
if (parent instanceof DartPropertyAccess && ((DartPropertyAccess) parent).getName() == node) {
- boolean isAssignedTo = isAssignedTo(node);
+ DartPropertyAccess propertyAccess = (DartPropertyAccess) parent;
+ boolean inGetterContext = ASTNodes.inGetterContext(propertyAccess);
Element indexElement = new Element(IndexConstants.DYNAMIC, node.getName());
Location location = createLocation(node);
- if (isAssignedTo) {
- recordRelationship(indexElement, IndexConstants.IS_MODIFIED_BY_QUALIFIED, location);
- } else {
+ if (inGetterContext) {
recordRelationship(indexElement, IndexConstants.IS_ACCESSED_BY_QUALIFIED, location);
+ } else {
+ recordRelationship(indexElement, IndexConstants.IS_MODIFIED_BY_QUALIFIED, location);
}
}
}
+ // analyze Element
if (element instanceof ClassElement) {
processTypeReference(node, ((ClassElement) element).getType());
} else if (element instanceof FieldElement) {
- boolean isAssignedTo = isAssignedTo(node);
- Element indexElement = getElement((FieldElement) element, !isAssignedTo, isAssignedTo);
+ FieldElement fieldElement = (FieldElement) element;
+ DartNode propertyAccess = ASTNodes.getPropertyAccessNode(node);
+ boolean inGetterContext = ASTNodes.inGetterContext(propertyAccess);
+ Element indexElement = getElement(fieldElement, inGetterContext, true);
Location location = createLocation(node);
- if (isAssignedTo) {
- if (isQualified(node)) {
- recordRelationship(indexElement, IndexConstants.IS_MODIFIED_BY_QUALIFIED, location);
+ if (inGetterContext) {
+ if (fieldElement.getGetter() != null) {
+ processMethodInvocation(node, fieldElement.getGetter());
+ } else if (isQualified(node)) {
+ recordRelationship(indexElement, IndexConstants.IS_ACCESSED_BY_QUALIFIED, location);
} else {
- recordRelationship(indexElement, IndexConstants.IS_MODIFIED_BY_UNQUALIFIED, location);
+ recordRelationship(indexElement, IndexConstants.IS_ACCESSED_BY_UNQUALIFIED, location);
}
} else {
- if (isQualified(node)) {
- recordRelationship(indexElement, IndexConstants.IS_ACCESSED_BY_QUALIFIED, location);
+ if (fieldElement.getSetter() != null) {
+ processMethodInvocation(node, fieldElement.getSetter());
+ } else if (isQualified(node)) {
+ recordRelationship(indexElement, IndexConstants.IS_MODIFIED_BY_QUALIFIED, location);
} else {
- recordRelationship(indexElement, IndexConstants.IS_ACCESSED_BY_UNQUALIFIED, location);
+ recordRelationship(indexElement, IndexConstants.IS_MODIFIED_BY_UNQUALIFIED, location);
}
}
} else if (element instanceof MethodElement) {
@@ -937,29 +945,6 @@ public class IndexContributor extends ASTVisitor<Void> {
return superType.getElement();
}
- private boolean isAssignedTo(DartIdentifier node) {
- DartNode child = node;
- DartNode parent = child.getParent();
- while (parent != null) {
- if (parent instanceof DartBinaryExpression) {
- DartBinaryExpression binary = (DartBinaryExpression) parent;
- if (binary.getOperator().isAssignmentOperator() && child == binary.getArg1()) {
- return true;
- }
- } else if (parent instanceof DartPropertyAccess) {
- if (child != ((DartPropertyAccess) parent).getName()) {
- return false;
- }
- } else if (parent instanceof DartStatement || parent instanceof DartClassMember<?>
- || parent instanceof DartClass) {
- return false;
- }
- child = parent;
- parent = child.getParent();
- }
- return false;
- }
-
private boolean isExplicitInvocation(DartIdentifier identifier) {
DartNode parent = identifier.getParent();
return (parent instanceof DartFunctionObjectInvocation && ((DartFunctionObjectInvocation) parent).getTarget() == identifier)

Powered by Google App Engine
This is Rietveld 408576698