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

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/DiscardTask.java

Issue 10883074: Update scan, changed and discard to handle "packages" and "pubspec.yaml" (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/DiscardTask.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/DiscardTask.java (revision 11962)
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/DiscardTask.java (working copy)
@@ -15,11 +15,7 @@
import com.google.dart.tools.core.DartCore;
-import static com.google.dart.tools.core.analysis.AnalysisUtility.equalsOrContains;
-
import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
/**
* Remove package contexts, cached libraries, and any tasks related to analyzing those libraries
@@ -27,15 +23,11 @@
class DiscardTask extends Task {
private final AnalysisServer server;
- private final SavedContext savedContext;
private final File rootFile;
- private final ArrayList<Library> discardedLibraries;
public DiscardTask(AnalysisServer server, File file) {
this.server = server;
- this.savedContext = server.getSavedContext();
this.rootFile = file;
- this.discardedLibraries = new ArrayList<Library>();
}
@Override
@@ -50,95 +42,23 @@
@Override
public void perform() {
+ File file = rootFile;
- // If this is a dart file, then discard the cached library
- if (rootFile.isFile()
- || (!rootFile.exists() && DartCore.isDartLikeFileName(rootFile.getName()))) {
- for (PackageContext packageContext : savedContext.getPackageContexts()) {
- discardLibrary(packageContext, rootFile);
- }
- discardLibrary(savedContext, rootFile);
+ // If a "packages" directory was discarded, then discard the application context
+ // The pubspec may have already been discarded, so only check the directory name
+ if (file.getName().equals(DartCore.PACKAGES_DIRECTORY_NAME)) {
+ file = file.getParentFile();
}
- // otherwise discard all cached libraries in the specified directory tree
- else {
- for (PackageContext packageContext : savedContext.getPackageContexts()) {
- discardLibrariesIn(packageContext, rootFile);
-
- // Discard any package contexts in the specified directory tree
- if (equalsOrContains(rootFile, packageContext.getApplicationDirectory())) {
- savedContext.discardPackageContext(packageContext);
- }
- }
- discardLibrariesIn(savedContext, rootFile);
+ // Discard libraries and package contexts
+ if (server.getSavedContext().discardLibraries(file).size() == 0) {
+ return;
}
- // Remove any referenced libraries
- int index = 0;
- while (index < discardedLibraries.size()) {
- Library library = discardedLibraries.get(index++);
- for (PackageContext packageContext : savedContext.getPackageContexts()) {
- discardReferencingLibraries(packageContext, library);
- }
- discardReferencingLibraries(savedContext, library);
- }
-
- // Remove all pending analysis tasks as they may have been related to the discarded library
+ // Remove all pending analysis tasks as they may have been related to the discarded libraries
server.removeAllBackgroundAnalysisTasks();
+
// Reanalyze any libraries not already cached
server.queueAnalyzeContext();
}
-
- /**
- * Discard all cached libraries in the specified directory tree
- */
- private void discardLibrariesIn(Context context, File directory) {
- Collection<Library> cachedLibraries = new ArrayList<Library>(context.getCachedLibraries());
- for (Library library : cachedLibraries) {
- if (equalsOrContains(directory, library.getFile())) {
- discardLibrary(context, library);
- }
- }
- }
-
- /**
- * If there is a cached library, then discard the library and notify others that the library is no
- * longer being analyzed
- */
- private void discardLibrary(Context context, File libraryFile) {
- Library library = context.getCachedLibrary(libraryFile);
- if (library != null) {
- discardLibrary(context, library);
- }
- }
-
- /**
- * Discard the library and notify others that the library is no longer being analyzed
- */
- private void discardLibrary(Context context, Library library) {
- AnalysisEvent event = new AnalysisEvent(
- library.getFile(),
- library.getSourceFiles(),
- AnalysisError.NONE);
-
- context.discardLibrary(library);
- discardedLibraries.add(library);
-
- for (AnalysisListener listener : savedContext.getAnalysisListeners()) {
- try {
- listener.discarded(event);
- } catch (Throwable e) {
- DartCore.logError("Exception during discard notification", e);
- }
- }
- }
-
- /**
- * Discard any libraries referencing the specified library
- */
- private void discardReferencingLibraries(Context context, Library library) {
- for (Library referencingLibrary : context.getLibrariesImporting(library.getFile())) {
- discardLibrary(context, referencingLibrary);
- }
- }
}

Powered by Google App Engine
This is Rietveld 408576698