| Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/DartElementLocator.java
|
| ===================================================================
|
| --- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/DartElementLocator.java (revision 10526)
|
| +++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/DartElementLocator.java (working copy)
|
| @@ -14,8 +14,6 @@
|
| package com.google.dart.tools.core.utilities.ast;
|
|
|
| import com.google.common.base.Objects;
|
| -import com.google.dart.compiler.DartSource;
|
| -import com.google.dart.compiler.LibrarySource;
|
| import com.google.dart.compiler.ast.ASTVisitor;
|
| import com.google.dart.compiler.ast.DartArrayAccess;
|
| import com.google.dart.compiler.ast.DartBinaryExpression;
|
| @@ -23,7 +21,6 @@
|
| import com.google.dart.compiler.ast.DartIdentifier;
|
| import com.google.dart.compiler.ast.DartImportDirective;
|
| import com.google.dart.compiler.ast.DartNode;
|
| -import com.google.dart.compiler.ast.DartResourceDirective;
|
| import com.google.dart.compiler.ast.DartSourceDirective;
|
| import com.google.dart.compiler.ast.DartStringLiteral;
|
| import com.google.dart.compiler.ast.DartUnaryExpression;
|
| @@ -40,7 +37,6 @@
|
| import com.google.dart.tools.core.model.DartImport;
|
| import com.google.dart.tools.core.model.DartLibrary;
|
| import com.google.dart.tools.core.model.DartModelException;
|
| -import com.google.dart.tools.core.model.DartResource;
|
| import com.google.dart.tools.core.model.SourceRange;
|
| import com.google.dart.tools.core.model.SourceReference;
|
| import com.google.dart.tools.core.utilities.bindings.BindingUtils;
|
| @@ -48,16 +44,14 @@
|
| import org.eclipse.jface.text.IRegion;
|
| import org.eclipse.jface.text.Region;
|
|
|
| -import java.net.URI;
|
| -
|
| /**
|
| - * Instances of the class <code>DartElementLocator</code> locate the {@link DartElement Dart
|
| - * element(s)} associated with a source range, given the AST structure built from the source.
|
| + * Instances of the class <code>DartElementLocator</code> locate the {@link DartElement Dart element(s)} associated
|
| + * with a source range, given the AST structure built from the source.
|
| */
|
| public class DartElementLocator extends ASTVisitor<Void> {
|
| /**
|
| - * Instances of the class <code>DartElementFoundException</code> are used to cancel visiting after
|
| - * an element has been found.
|
| + * Instances of the class <code>DartElementFoundException</code> are used to cancel visiting after an element has been
|
| + * found.
|
| */
|
| private class DartElementFoundException extends RuntimeException {
|
| private static final long serialVersionUID = 1L;
|
| @@ -97,14 +91,14 @@
|
| private IRegion wordRegion;
|
|
|
| /**
|
| - * The region within the element's compilation unit that needs to be highlighted, or
|
| - * <code>null</code> if there is no element.
|
| + * The region within the element's compilation unit that needs to be highlighted, or <code>null</code>
|
| + * if there is no element.
|
| */
|
| private IRegion candidateRegion;
|
|
|
| /**
|
| - * The resolved element that was found that corresponds to the given source range, or
|
| - * <code>null</code> if there is no such element.
|
| + * The resolved element that was found that corresponds to the given source range, or <code>null
|
| + * </code> if there is no such element.
|
| */
|
| private Element resolvedElement;
|
|
|
| @@ -136,8 +130,8 @@
|
| *
|
| * @param input the compilation unit containing the element to be found
|
| * @param offset the offset used to identify the element
|
| - * @param includeDeclarations <code>true</code> if elements should be returned for declaration
|
| - * sites as well as for reference sites
|
| + * @param includeDeclarations <code>true</code> if elements should be returned for declaration sites
|
| + * as well as for reference sites
|
| */
|
| public DartElementLocator(CompilationUnit input, int offset, boolean includeDeclarations) {
|
| this(input, offset, offset, includeDeclarations);
|
| @@ -164,10 +158,11 @@
|
| * @param input the compilation unit containing the element to be found
|
| * @param start the start offset of the range used to identify the element
|
| * @param end the end offset of the range used to identify the element
|
| - * @param includeDeclarations <code>true</code> if elements should be returned for declaration
|
| - * sites as well as for reference sites
|
| + * @param includeDeclarations <code>true</code> if elements should be returned for declaration sites
|
| + * as well as for reference sites
|
| */
|
| - public DartElementLocator(CompilationUnit input, int start, int end, boolean includeDeclarations) {
|
| + public DartElementLocator(
|
| + CompilationUnit input, int start, int end, boolean includeDeclarations) {
|
| this.compilationUnit = input;
|
| this.startOffset = start;
|
| this.endOffset = end;
|
| @@ -175,9 +170,8 @@
|
| }
|
|
|
| /**
|
| - * Return the region within the element's compilation unit that needs to be highlighted, or
|
| - * <code>null</code> if either there is no element or if the element can be used to determine the
|
| - * region.
|
| + * Return the region within the element's compilation unit that needs to be highlighted, or <code>null
|
| + * </code> if either there is no element or if the element can be used to determine the region.
|
| *
|
| * @return the region within the element's compilation unit that needs to be highlighted
|
| */
|
| @@ -186,8 +180,8 @@
|
| }
|
|
|
| /**
|
| - * Return the element that was found that corresponds to the given source range, or
|
| - * <code>null</code> if there is no such element.
|
| + * Return the element that was found that corresponds to the given source range, or <code>null</code>
|
| + * if there is no such element.
|
| *
|
| * @return the element that was found
|
| */
|
| @@ -196,7 +190,7 @@
|
| }
|
|
|
| /**
|
| - * Return the resolved element that was found that corresponds to the given source range, or
|
| + * Return the resolved element that was found that corresponds to the given source range, or
|
| * <code>null</code> if there is no such element.
|
| *
|
| * @return the element that was found
|
| @@ -218,8 +212,8 @@
|
|
|
| /**
|
| * Search within the given AST node for an identifier representing a {@link DartElement Dart
|
| - * element} in the specified source range. Return the element that was found, or <code>null</code>
|
| - * if no element was found.
|
| + * element} in the specified source range. Return the element that was found, or <code>null</code> if
|
| + * no element was found.
|
| *
|
| * @param node the AST node within which to search
|
| * @return the element that was found
|
| @@ -230,8 +224,10 @@
|
| } catch (DartElementFoundException exception) {
|
| // A node with the right source position was found.
|
| } catch (Exception exception) {
|
| - DartCore.logInformation("Unable to locate element at offset (" + startOffset + " - "
|
| - + endOffset + ") in " + compilationUnit.getElementName(), exception);
|
| + DartCore.logInformation(
|
| + "Unable to locate element at offset (" + startOffset + " - " + endOffset + ") in "
|
| + + compilationUnit.getElementName(),
|
| + exception);
|
| return null;
|
| }
|
| return foundElement;
|
| @@ -245,8 +241,9 @@
|
| int end = start + node.getSourceInfo().getLength();
|
| if (start <= startOffset && endOffset <= end) {
|
| DartExpression target = node.getTarget();
|
| - wordRegion = new Region(target.getSourceInfo().getOffset()
|
| - + target.getSourceInfo().getLength(), end);
|
| + wordRegion = new Region(
|
| + target.getSourceInfo().getOffset() + target.getSourceInfo().getLength(),
|
| + end);
|
| Element targetElement = node.getElement();
|
| findElementFor(targetElement);
|
| throw new DartElementFoundException();
|
| @@ -264,8 +261,9 @@
|
| if (start <= startOffset && endOffset <= end) {
|
| DartExpression leftOperand = node.getArg1();
|
| DartExpression rightOperand = node.getArg2();
|
| - wordRegion = computeOperatorRegion(leftOperand.getSourceInfo().getOffset()
|
| - + leftOperand.getSourceInfo().getLength(), rightOperand.getSourceInfo().getOffset() - 1);
|
| + wordRegion = computeOperatorRegion(
|
| + leftOperand.getSourceInfo().getOffset() + leftOperand.getSourceInfo().getLength(),
|
| + rightOperand.getSourceInfo().getOffset() - 1);
|
| Element targetElement = node.getElement();
|
| findElementFor(targetElement);
|
| throw new DartElementFoundException();
|
| @@ -309,8 +307,9 @@
|
| try {
|
| DartImport[] imports = compilationUnit.getLibrary().getImports();
|
| for (DartImport imprt : imports) {
|
| - if (Objects.equal(imprt.getLibrary(), foundElement)
|
| - && Objects.equal(imprt.getPrefix(), node.getName())) {
|
| + if (Objects.equal(imprt.getLibrary(), foundElement) && Objects.equal(
|
| + imprt.getPrefix(),
|
| + node.getName())) {
|
| foundElement = imprt;
|
| SourceRange range = imprt.getNameRange();
|
| candidateRegion = new Region(range.getOffset(), range.getLength());
|
| @@ -397,28 +396,6 @@
|
| if (sourcedUnit != null && sourcedUnit.exists()) {
|
| foundElement = sourcedUnit;
|
| }
|
| - } else if (parent instanceof DartResourceDirective
|
| - && ((DartResourceDirective) parent).getResourceUri() == node) {
|
| - //resolvedElement = ((DartResourceDirective) parent).getElement();
|
| - DartLibrary library = compilationUnit.getLibrary();
|
| - try {
|
| - DartSource unitSource = compilationUnit.getSourceRef();
|
| - if (unitSource != null) {
|
| - LibrarySource librarySource = unitSource.getLibrary();
|
| - if (librarySource != null) {
|
| - DartSource resourceSource = librarySource.getSourceFor(node.getValue());
|
| - if (resourceSource != null) {
|
| - URI resourceUri = resourceSource.getUri();
|
| - DartResource resource = library.getResource(resourceUri);
|
| - if (resource != null && resource.exists()) {
|
| - foundElement = resource;
|
| - }
|
| - }
|
| - }
|
| - }
|
| - } catch (DartModelException exception) {
|
| - foundElement = null;
|
| - }
|
| }
|
| throw new DartElementFoundException();
|
| }
|
|
|