Chromium Code Reviews| 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; |
| + } |
| } |