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

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

Issue 8492014: Fix for http://code.google.com/p/dart/issues/detail?id=361 (Open Declaration does not work for so... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1263)
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/utilities/ast/DartElementLocator.java (working copy)
@@ -51,6 +51,7 @@
import com.google.dart.tools.core.model.SourceReference;
import com.google.dart.tools.core.utilities.bindings.BindingUtils;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
@@ -358,7 +359,8 @@
} else if (parent instanceof DartSourceDirective
&& ((DartSourceDirective) parent).getSourceUri() == node) {
DartLibrary library = compilationUnit.getLibrary();
- CompilationUnit sourcedUnit = library.getCompilationUnit(node.getValue());
+ String fileName = getFileName(library, node.getValue());
+ CompilationUnit sourcedUnit = library.getCompilationUnit(fileName);
if (sourcedUnit != null && sourcedUnit.exists()) {
foundElement = sourcedUnit;
}
@@ -503,4 +505,26 @@
}
}
}
+
+ /**
+ * Extract the file name from the given URI. Return the file name that was extracted, or the
+ * original URI if the format of the URI could not be recognized.
+ *
+ * @param library the library that the URI might be relative to
+ * @param uri the string representation of the URI
+ * @return the file name that was extracted
+ */
+ private String getFileName(DartLibrary library, String uri) {
+ try {
+ LibrarySource source = (LibrarySource) library.getDefiningCompilationUnit().getSourceRef();
+ return new Path(source.getSourceFor(uri).getUri().getPath()).lastSegment();
+ } catch (Exception exception) {
+ // Fall through to try a different approach
+ }
danrubel 2011/11/07 19:30:21 Do we need the code above? Will the code below alw
Brian Wilkerson 2011/11/07 19:40:33 I don't think so. I removed it.
+ int index = uri.lastIndexOf('/');
+ if (index >= 0) {
+ return uri.substring(index + 1);
+ }
+ return uri;
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698