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

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/SavedContext.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/SavedContext.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/SavedContext.java (revision 11962)
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/SavedContext.java (working copy)
@@ -15,9 +15,13 @@
import com.google.dart.compiler.PackageLibraryManager;
+import static com.google.dart.tools.core.analysis.AnalysisUtility.equalsOrContains;
+
import java.io.File;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
/**
* Analysis of Dart source saved on disk
@@ -25,8 +29,8 @@
public class SavedContext extends Context {
/**
- * A mapping of directories containing a "packages" to current package contexts. This should only
- * be accessed on the background thread.
+ * A mapping of application directories (directories containing a "packages" directory) to current
+ * package contexts. This should only be accessed on the background thread.
*/
private HashMap<File, PackageContext> packageContexts = new HashMap<File, PackageContext>();
@@ -34,16 +38,66 @@
super(server, libraryManager);
}
+ /**
+ * TESTING: Answer an array of directories for which a {@link PackageContext} has been defined
+ */
+ public File[] getApplicationDirectories() {
+ return packageContexts.keySet().toArray(new File[packageContexts.keySet().size()]);
+ }
+
@Override
public String toString() {
return getClass().getSimpleName();
}
- void discardPackageContext(PackageContext context) {
- packageContexts.remove(context.getApplicationDirectory());
+ /**
+ * Discard all package contexts in addition to all libraries without notifying any listeners about
+ * discarded libraries
+ */
+ @Override
+ void discardAllLibraries() {
+ packageContexts.clear();
+ super.discardAllLibraries();
}
/**
+ * If the specified file is a directory, then discard all libraries in that directory tree
+ * otherwise discard the specified library. In both cases, discard all libraries that directly or
+ * indirectly reference the discarded libraries.
+ *
+ * @param rootFile the original file or directory to discard
+ * @return the collection of discarded libraries (not <code>null</code>, contains no
+ * <code>null</code>s)
+ */
+ Collection<Library> discardLibraries(File rootFile) {
+ ArrayList<Library> discarded = new ArrayList<Library>(40);
+ discardLibraries(rootFile, discarded);
+ return discarded;
+ };
+
+ /**
+ * If the specified file is a directory, then discard all libraries and package contexts in that
+ * directory tree otherwise discard the specified library. In both cases, discard all libraries
+ * that directly or indirectly reference the discarded libraries.
+ *
+ * @param rootFile the original file or directory to discard
+ * @param discarded the collection of discarded libraries and to which newly discarded libraries
+ * should be added (not <code>null</code>, contains no <code>null</code>s)
+ */
+ @Override
+ void discardLibraries(File rootFile, ArrayList<Library> discarded) {
+ super.discardLibraries(rootFile, discarded);
+ Iterator<PackageContext> iter = packageContexts.values().iterator();
+ while (iter.hasNext()) {
+ PackageContext context = iter.next();
+ context.discardLibraries(rootFile, discarded);
+ if (equalsOrContains(rootFile, context.getApplicationDirectory())) {
+ iter.remove();
+ }
+ }
+ };
+
+ /**
* Answer the package context for the specified application directory, creating and caching a new
* one if one does not already exist.
*
@@ -58,8 +112,4 @@
}
return context;
}
-
- Collection<PackageContext> getPackageContexts() {
- return packageContexts.values();
- }
}

Powered by Google App Engine
This is Rietveld 408576698