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

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

Issue 11377039: Issue 6251. Resolve and rename type and constructor references in [new Type.name]. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 5cfd9f4ef1205f107effaf38ff783c4f847a4501..1e72ee40530db29d6d8b45f51984e2dc08b0cf0b 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
@@ -19,6 +19,8 @@ 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.DartCommentNewName;
+import com.google.dart.compiler.ast.DartCommentRefName;
import com.google.dart.compiler.ast.DartDeclaration;
import com.google.dart.compiler.ast.DartExpression;
import com.google.dart.compiler.ast.DartField;
@@ -52,6 +54,7 @@ import com.google.dart.compiler.resolver.ConstructorElement;
import com.google.dart.compiler.resolver.FieldElement;
import com.google.dart.compiler.resolver.LibraryElement;
import com.google.dart.compiler.resolver.MethodElement;
+import com.google.dart.compiler.resolver.NodeElement;
import com.google.dart.compiler.resolver.VariableElement;
import com.google.dart.compiler.type.InterfaceType;
import com.google.dart.compiler.util.apache.StringUtils;
@@ -81,8 +84,8 @@ import java.util.ArrayList;
import javax.lang.model.element.TypeElement;
/**
- * Instances of the class <code>IndexContributor</code> visit an AST structure to compute the data and relationships
- * to be contributed to an index.
+ * Instances of the class <code>IndexContributor</code> visit an AST structure to compute the data
+ * and relationships to be contributed to an index.
*/
public class IndexContributor extends ASTVisitor<Void> {
/*
@@ -289,6 +292,47 @@ public class IndexContributor extends ASTVisitor<Void> {
}
@Override
+ public Void visitCommentNewName(DartCommentNewName node) {
+ ClassElement classElement = node.getClassElement();
+ ConstructorElement constructorElement = node.getConstructorElement();
+ if (classElement != null) {
+ int classOffset = node.getClassOffset();
+ int classLength = classElement.getName().length();
+ try {
+ Element indexElement = ElementFactory.getElement(classElement);
+ Location location = createLocation(classOffset, classLength, null);
+ recordRelationship(indexElement, IndexConstants.IS_REFERENCED_BY, location);
+ } catch (Throwable e) {
+ }
+ try {
+ Element indexElement = ElementFactory.getElement(constructorElement);
+ int length = classLength + ".".length() + constructorElement.getName().length();
+ Location location = createLocation(classOffset, length, null);
+ recordRelationship(indexElement, IndexConstants.IS_INVOKED_BY_UNQUALIFIED, location);
+ } catch (Throwable e) {
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Void visitCommentRefName(DartCommentRefName node) {
+ NodeElement element = node.getElement();
+ if (element != null) {
+ try {
+ Element indexElement = ElementFactory.getElement(element);
+ Location location = createLocation(
+ node.getSourceInfo().getOffset() + "[".length(),
+ node.getSourceInfo().getLength() - "[]".length(),
+ null);
+ recordRelationship(indexElement, IndexConstants.IS_REFERENCED_BY, location);
+ } catch (Throwable e) {
+ }
+ }
+ return null;
+ }
+
+ @Override
public Void visitField(DartField node) {
enterScope(getElement(node));
try {
@@ -337,10 +381,8 @@ public class IndexContributor extends ASTVisitor<Void> {
if (element instanceof MethodElement) {
processMethodInvocation(getIdentifier(node.getTarget()), (MethodElement) element);
} else {
- notFound(
- "function invocation: [" + (element == null ? "null" : element.toString()) + "] "
- + node.toString(),
- node);
+ notFound("function invocation: [" + (element == null ? "null" : element.toString()) + "] "
+ + node.toString(), node);
}
return super.visitFunctionObjectInvocation(node);
}
@@ -366,8 +408,8 @@ public class IndexContributor extends ASTVisitor<Void> {
// no resolved Element, potential match
if (element == null) {
DartNode parent = node.getParent();
- if (parent instanceof DartMethodInvocation &&
- ((DartMethodInvocation) parent).getFunctionName() == node) {
+ if (parent instanceof DartMethodInvocation
+ && ((DartMethodInvocation) parent).getFunctionName() == node) {
Element indexElement = new Element(IndexConstants.DYNAMIC, node.getName());
recordRelationship(
indexElement,
@@ -422,8 +464,8 @@ public class IndexContributor extends ASTVisitor<Void> {
} else if (!isExplicitInvocation(node)) {
Element indexElement = getElement(methodElement);
Location location = createLocation(node);
- Relationship relationship = isQualified(node)
- ? IndexConstants.IS_ACCESSED_BY_QUALIFIED : IndexConstants.IS_ACCESSED_BY_UNQUALIFIED;
+ Relationship relationship = isQualified(node) ? IndexConstants.IS_ACCESSED_BY_QUALIFIED
+ : IndexConstants.IS_ACCESSED_BY_UNQUALIFIED;
recordRelationship(indexElement, relationship, location);
}
} else if (element instanceof LibraryElement) {
@@ -558,9 +600,8 @@ public class IndexContributor extends ASTVisitor<Void> {
} finally {
unnamedFunctionCount.pop();
if (!unnamedFunctionCount.isEmpty()) {
- DartCore.logError(
- unnamedFunctionCount.size() + " scopes entered but not exited while visiting "
- + compilationUnit.getElementName());
+ DartCore.logError(unnamedFunctionCount.size()
+ + " scopes entered but not exited while visiting " + compilationUnit.getElementName());
unnamedFunctionCount.clear();
}
}
@@ -712,8 +753,8 @@ public class IndexContributor extends ASTVisitor<Void> {
}
/**
- * Return the method that the given method overrides, or <code>null</code> if the given method does
- * not override another method.
+ * Return the method that the given method overrides, or <code>null</code> if the given method
+ * does not override another method.
*
* @param method the method that might override another method
* @return the method that the given method overrides
@@ -787,8 +828,9 @@ public class IndexContributor extends ASTVisitor<Void> {
* @return an element representing the given type
*/
private Element getElement(DartClass node) {
- return new Element(compilationUnitResource, ElementFactory.composeElementId(
- node.getClassName()));
+ return new Element(
+ compilationUnitResource,
+ ElementFactory.composeElementId(node.getClassName()));
}
/**
@@ -798,9 +840,9 @@ public class IndexContributor extends ASTVisitor<Void> {
* @return an element representing the given field
*/
private Element getElement(DartField node) {
- return new Element(
- compilationUnitResource,
- ElementFactory.composeElementId(peekElement(), node.getName().getName()));
+ return new Element(compilationUnitResource, ElementFactory.composeElementId(
+ peekElement(),
+ node.getName().getName()));
}
/**
@@ -819,9 +861,9 @@ public class IndexContributor extends ASTVisitor<Void> {
functionName = Integer.toString(unnamedFunctionCount.peek());
unnamedFunctionCount.increment(1);
}
- return new Element(
- compilationUnitResource,
- ElementFactory.composeElementId(peekElement(), functionName));
+ return new Element(compilationUnitResource, ElementFactory.composeElementId(
+ peekElement(),
+ functionName));
}
/**
@@ -843,9 +885,9 @@ public class IndexContributor extends ASTVisitor<Void> {
* @return an element representing the given method
*/
private Element getElement(DartMethodDefinition node) {
- return new Element(
- compilationUnitResource,
- ElementFactory.composeElementId(peekElement(), toString(node.getName())));
+ return new Element(compilationUnitResource, ElementFactory.composeElementId(
+ peekElement(),
+ toString(node.getName())));
}
/**
@@ -925,18 +967,16 @@ public class IndexContributor extends ASTVisitor<Void> {
try {
return ResourceFactory.getResource(compilationUnit);
} catch (DartModelException exception) {
- DartCore.logInformation(
- "Could not get underlying resource for compilation unit "
- + compilationUnit.getElementName(),
- exception);
+ DartCore.logInformation("Could not get underlying resource for compilation unit "
+ + compilationUnit.getElementName(), exception);
}
}
return libraryResource;
}
/**
- * Return the superclass of the given class, or <code>null</code> if the given class does not have a
- * superclass or if the superclass cannot be determined.
+ * Return the superclass of the given class, or <code>null</code> if the given class does not have
+ * a superclass or if the superclass cannot be determined.
*
* @param classElement the class being accessed
* @return the superclass of the given class
@@ -951,22 +991,17 @@ public class IndexContributor extends ASTVisitor<Void> {
private boolean isExplicitInvocation(DartIdentifier identifier) {
DartNode parent = identifier.getParent();
- return (parent instanceof DartFunctionObjectInvocation
- && ((DartFunctionObjectInvocation) parent).getTarget() == identifier) || (
- parent instanceof DartMethodInvocation
- && ((DartMethodInvocation) parent).getFunctionName() == identifier) || (
- parent instanceof DartNewExpression
- && ((DartNewExpression) parent).getConstructor() == identifier) || (
- parent instanceof DartRedirectConstructorInvocation
- && ((DartRedirectConstructorInvocation) parent).getName() == identifier) || (
- parent instanceof DartSuperConstructorInvocation
- && ((DartSuperConstructorInvocation) parent).getName() == identifier) || (
- parent instanceof DartUnqualifiedInvocation
- && ((DartUnqualifiedInvocation) parent).getTarget() == identifier);
+ return (parent instanceof DartFunctionObjectInvocation && ((DartFunctionObjectInvocation) parent).getTarget() == identifier)
+ || (parent instanceof DartMethodInvocation && ((DartMethodInvocation) parent).getFunctionName() == identifier)
+ || (parent instanceof DartNewExpression && ((DartNewExpression) parent).getConstructor() == identifier)
+ || (parent instanceof DartRedirectConstructorInvocation && ((DartRedirectConstructorInvocation) parent).getName() == identifier)
+ || (parent instanceof DartSuperConstructorInvocation && ((DartSuperConstructorInvocation) parent).getName() == identifier)
+ || (parent instanceof DartUnqualifiedInvocation && ((DartUnqualifiedInvocation) parent).getTarget() == identifier);
}
/**
- * Return <code>true</code> if the given identifier represents the name in a declaration of that name.
+ * Return <code>true</code> if the given identifier represents the name in a declaration of that
+ * name.
*
* @param node the identifier being tested
* @return <code>true</code> if the given identifier is the name in a declaration
@@ -1051,8 +1086,8 @@ public class IndexContributor extends ASTVisitor<Void> {
}
/**
- * Return the element representing the inner-most enclosing scope, or <code>null</code> if we are at
- * the top-level of the compilation unit.
+ * Return the element representing the inner-most enclosing scope, or <code>null</code> if we are
+ * at the top-level of the compilation unit.
*
* @return the element representing the inner-most enclosing scope
*/
@@ -1080,10 +1115,7 @@ public class IndexContributor extends ASTVisitor<Void> {
IndexConstants.UNIVERSE,
IndexConstants.DEFINES_INTERFACE,
createNameLocation(node));
- recordRelationship(
- libraryElement,
- IndexConstants.DEFINES_INTERFACE,
- createNameLocation(node));
+ recordRelationship(libraryElement, IndexConstants.DEFINES_INTERFACE, createNameLocation(node));
} else {
recordRelationship(
IndexConstants.UNIVERSE,
@@ -1193,8 +1225,8 @@ public class IndexContributor extends ASTVisitor<Void> {
notFound("method invocation", methodName);
return;
}
- Relationship relationship = isQualified(methodName)
- ? IndexConstants.IS_INVOKED_BY_QUALIFIED : IndexConstants.IS_INVOKED_BY_UNQUALIFIED;
+ Relationship relationship = isQualified(methodName) ? IndexConstants.IS_INVOKED_BY_QUALIFIED
+ : IndexConstants.IS_INVOKED_BY_UNQUALIFIED;
recordRelationship(getElement(binding), relationship, createLocation(methodName));
}
@@ -1205,8 +1237,7 @@ public class IndexContributor extends ASTVisitor<Void> {
* @param length the length of the name of the method being invoked
* @param binding the element representing the method being invoked
*/
- private void processMethodInvocation(
- int offset, int length, String prefix, MethodElement binding) {
+ private void processMethodInvocation(int offset, int length, String prefix, MethodElement binding) {
if (binding == null) {
notFound("method invocation", offset, length);
return;
@@ -1259,16 +1290,14 @@ public class IndexContributor extends ASTVisitor<Void> {
* @param prefix the prefix of the import, may be <code>null</code>
* @param offset the offset of the prefix
*/
- private void recordImportReference(
- LibraryElement importLibraryElement, String prefix, int offset) {
+ private void recordImportReference(LibraryElement importLibraryElement, String prefix, int offset) {
try {
DartLibrary importLibraryModel = BindingUtils.getDartElement(importLibraryElement);
for (DartImport imprt : libraryImports) {
- if (Objects.equal(imprt.getLibrary(), importLibraryModel) && Objects.equal(
- imprt.getPrefix(),
- prefix)) {
- String imprtId = ElementFactory.composeElementId(
- imprt.getPrefix() + ":" + imprt.getLibrary().getElementName());
+ if (Objects.equal(imprt.getLibrary(), importLibraryModel)
+ && Objects.equal(imprt.getPrefix(), prefix)) {
+ String imprtId = ElementFactory.composeElementId(imprt.getPrefix() + ":"
+ + imprt.getLibrary().getElementName());
Element imprtElement = new Element(libraryResource, imprtId);
int length = StringUtils.length(prefix);
Location location = createLocation(offset, length, null);
@@ -1277,9 +1306,8 @@ public class IndexContributor extends ASTVisitor<Void> {
}
}
} catch (Throwable e) {
- DartCore.logInformation(
- "Could not record reference to library import " + importLibraryElement,
- e);
+ DartCore.logInformation("Could not record reference to library import "
+ + importLibraryElement, e);
}
}
@@ -1289,9 +1317,9 @@ public class IndexContributor extends ASTVisitor<Void> {
*/
private void recordImportReference_noPrefix(DartIdentifier node) {
com.google.dart.compiler.resolver.Element element = node.getElement();
- if (element != null && element.getEnclosingElement() instanceof LibraryElement &&
- PropertyDescriptorHelper.getLocationInParent(node)
- != PropertyDescriptorHelper.DART_PROPERTY_ACCESS_NAME) {
+ if (element != null
+ && element.getEnclosingElement() instanceof LibraryElement
+ && PropertyDescriptorHelper.getLocationInParent(node) != PropertyDescriptorHelper.DART_PROPERTY_ACCESS_NAME) {
LibraryElement importLibraryElement = (LibraryElement) element.getEnclosingElement();
recordImportReference(importLibraryElement, null, node.getSourceInfo().getOffset());
}

Powered by Google App Engine
This is Rietveld 408576698