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

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/StandardDartElementContentProvider.java

Issue 9008070: fix for issue 391: File not highlighted in Libraries view sometimes (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 12 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
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/libraryview/LibraryExplorerPart.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/StandardDartElementContentProvider.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/StandardDartElementContentProvider.java (revision 2950)
+++ editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/StandardDartElementContentProvider.java (working copy)
@@ -17,6 +17,7 @@
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.dart.tools.core.DartCore;
+import com.google.dart.tools.core.internal.model.CompilationUnitImpl;
import com.google.dart.tools.core.internal.model.ExternalCompilationUnitImpl;
import com.google.dart.tools.core.model.CompilationUnit;
import com.google.dart.tools.core.model.DartElement;
@@ -441,45 +442,23 @@
return parent;
} else if (element instanceof ExternalCompilationUnitImpl) {
DartLibrary targetLibrary = ((ExternalCompilationUnitImpl) element).getLibrary();
- URI targetUri = ImportedDartLibraryContainer.getUri(targetLibrary);
- for (ImportedDartLibraryContainer container : libraryContainers.keySet()) {
- for (ImportedDartLibrary importedLibrary : container.getDartLibraries()) {
- URI importedUri = ImportedDartLibraryContainer.getUri(importedLibrary.getDartLibrary());
- if (targetUri.equals(importedUri)) {
- return importedLibrary;
- }
- }
+ return getParentLibrary(targetLibrary);
+
+ } else if (element instanceof CompilationUnit) {
+ DartLibrary targetLibrary = ((CompilationUnitImpl) element).getLibrary();
+ if (targetLibrary.isTopLevel()) {
+ return targetLibrary;
+ } else {
+ return getParentLibrary(targetLibrary);
}
- DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot());
- try {
- DartProject[] projects = model.getDartProjects();
- for (DartProject project : projects) {
- for (DartLibrary library : project.getDartLibraries()) {
- for (DartLibrary importedLibrary : library.getImportedLibraries()) {
- URI importedUri = ImportedDartLibraryContainer.getUri(importedLibrary);
- if (targetUri.equals(importedUri)) {
- return new ImportedDartLibrary(importedLibrary, new ImportedDartLibraryContainer(
- importedLibrary, importedLibrary));
- }
- }
- }
- }
- if (projects.length > 0) {
- DartLibrary[] libraries = projects[0].getDartLibraries();
- if (libraries.length > 0) {
- DartLibrary[] bundledLibraries = model.getBundledLibraries();
- for (DartLibrary bundledLibrary : bundledLibraries) {
- URI bundledUri = ImportedDartLibraryContainer.getUri(bundledLibrary);
- if (targetUri.equals(bundledUri)) {
- return new ImportedDartLibrary(bundledLibrary, new ImportedDartLibraryContainer(
- libraries[0], libraries[0]));
- }
- }
- }
- }
- } catch (DartModelException exception) {
- // Ignored. Simply fall through to return null.
+
+ } else if (element instanceof DartLibrary) {
+ if (((DartLibrary) element).isTopLevel()) {
+ return ((DartLibrary) element).getParent();
+ } else {
+ return getParentLibrary((DartLibrary) element);
}
+
} else if (element instanceof DartElement) {
return ((DartElement) element).getParent();
} else if (element instanceof ImportedDartLibraryContainer) {
@@ -554,4 +533,47 @@
return children.toArray(new Object[children.size()]);
}
+ private ImportedDartLibrary getParentLibrary(DartLibrary targetLibrary) {
+ URI targetUri = ImportedDartLibraryContainer.getUri(targetLibrary);
+ for (ImportedDartLibraryContainer container : libraryContainers.keySet()) {
+ for (ImportedDartLibrary importedLibrary : container.getDartLibraries()) {
+ URI importedUri = ImportedDartLibraryContainer.getUri(importedLibrary.getDartLibrary());
+ if (targetUri.equals(importedUri)) {
+ return importedLibrary;
+ }
+ }
+ }
+ DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ try {
+ DartProject[] projects = model.getDartProjects();
+ for (DartProject project : projects) {
+ for (DartLibrary library : project.getDartLibraries()) {
+ for (DartLibrary importedLibrary : library.getImportedLibraries()) {
+ URI importedUri = ImportedDartLibraryContainer.getUri(importedLibrary);
+ if (targetUri.equals(importedUri)) {
+ return new ImportedDartLibrary(importedLibrary, new ImportedDartLibraryContainer(
+ library, library));
+ }
+ }
+ }
+ }
+ if (projects.length > 0) {
+ DartLibrary[] libraries = projects[0].getDartLibraries();
+ if (libraries.length > 0) {
+ DartLibrary[] bundledLibraries = model.getBundledLibraries();
+ for (DartLibrary bundledLibrary : bundledLibraries) {
+ URI bundledUri = ImportedDartLibraryContainer.getUri(bundledLibrary);
+ if (targetUri.equals(bundledUri)) {
+ return new ImportedDartLibrary(bundledLibrary, new ImportedDartLibraryContainer(
+ libraries[0], libraries[0]));
+ }
+ }
+ }
+ }
+ } catch (DartModelException exception) {
+ // Ignored. Simply fall through to return null.
+ }
+ return null;
+ }
+
}
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/libraryview/LibraryExplorerPart.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698