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

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

Issue 10537122: Fix analysis server caching edge case http://code.google.com/p/dart/issues/detail?id=3423 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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/Library.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/Library.java (revision 8521)
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/analysis/Library.java (working copy)
@@ -26,8 +26,6 @@
import java.io.File;
import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.PrintWriter;
import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
@@ -40,9 +38,7 @@
*/
class Library {
- private static final String PREFIXES_TAG = "prefixes: ";
- private static final String DIRECTIVES_TAG = "directives: ";
- private static final int DIRECTIVES_LEN = DIRECTIVES_TAG.length();
+ private static final String END_PREFIXES_TAG = "</end-prefixes>";
private static final String END_IMPORTS_TAG = "</end-imports>";
private static final String END_SOURCES_TAG = "</end-sources>";
@@ -104,61 +100,13 @@
* when the ASTs are re-parsed and re-resolved because they were already notified the first time
* it was parsed and resolved.
*/
- static Library readCache(AnalysisServer server, File libFile, LineNumberReader reader)
+ static Library readCache(AnalysisServer server, File libFile, CacheReader reader)
throws IOException {
LibrarySource libSource = toLibrarySource(server, libFile);
-
- HashSet<String> prefixes = new HashSet<String>();
- String line = reader.readLine();
- if (line == null || !line.startsWith(PREFIXES_TAG)) {
- throw new IOException("Expected " + PREFIXES_TAG + " but found " + line);
- }
- int start = PREFIXES_TAG.length();
- int last = line.length() - 1;
- while (start < last) {
- int end = line.indexOf(',', start);
- prefixes.add(line.substring(start, end));
- start = end + 1;
- }
-
- line = reader.readLine();
- if (line == null || !line.startsWith(DIRECTIVES_TAG)) {
- throw new IOException("Expected " + DIRECTIVES_TAG + " but found " + line);
- }
- boolean hasDirectives = line.length() > DIRECTIVES_LEN && line.charAt(DIRECTIVES_LEN) == 't';
-
- HashMap<String, File> imports = new HashMap<String, File>();
- while (true) {
- line = reader.readLine();
- if (line == null) {
- throw new IOException("Expected " + END_IMPORTS_TAG + " but found EOF");
- }
- if (line.equals(END_IMPORTS_TAG)) {
- break;
- }
- String path = reader.readLine();
- if (path == null) {
- throw new IOException("Expected import path but found EOF");
- }
- imports.put(line, new File(path));
- }
-
- HashMap<String, File> sources = new HashMap<String, File>();
- while (true) {
- line = reader.readLine();
- if (line == null) {
- throw new IOException("Expected " + END_SOURCES_TAG + " but found EOF");
- }
- if (line.equals(END_SOURCES_TAG)) {
- break;
- }
- String path = reader.readLine();
- if (path == null) {
- throw new IOException("Expected source path but found EOF");
- }
- sources.put(line, new File(path));
- }
-
+ boolean hasDirectives = reader.readBoolean();
+ HashSet<String> prefixes = reader.readStringSet(END_PREFIXES_TAG);
+ HashMap<String, File> imports = reader.readStringFileMap(END_IMPORTS_TAG);
+ HashMap<String, File> sources = reader.readStringFileMap(END_SOURCES_TAG);
return new Library(libFile, libSource, prefixes, hasDirectives, imports, sources, false);
}
@@ -168,6 +116,7 @@
private final boolean hasDirectives;
private final HashMap<String, File> imports;
private final HashMap<String, File> sources;
+
private final HashMap<File, DartUnit> resolvedUnits;
/**
@@ -249,24 +198,10 @@
/**
* Write information about the cached library, but do not write the AST structures themselves.
*/
- void writeCache(PrintWriter writer) {
- writer.print(PREFIXES_TAG);
- for (String eachPrefix : prefixes) {
- writer.print(eachPrefix);
- writer.print(',');
- }
- writer.println();
- writer.print(DIRECTIVES_TAG);
- writer.println(hasDirectives);
- for (Entry<String, File> entry : imports.entrySet()) {
- writer.println(entry.getKey());
- writer.println(entry.getValue().getPath());
- }
- writer.println(END_IMPORTS_TAG);
- for (Entry<String, File> entry : sources.entrySet()) {
- writer.println(entry.getKey());
- writer.println(entry.getValue().getPath());
- }
- writer.println(END_SOURCES_TAG);
+ void writeCache(CacheWriter writer) {
+ writer.writeBoolean(hasDirectives);
+ writer.writeStringSet(prefixes, END_PREFIXES_TAG);
+ writer.writeStringFileMap(imports, END_IMPORTS_TAG);
+ writer.writeStringFileMap(sources, END_SOURCES_TAG);
}
}

Powered by Google App Engine
This is Rietveld 408576698