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

Unified Diff: compiler/javatests/com/google/dart/compiler/end2end/inc/MemoryLibrarySource.java

Issue 11273064: Issue 5887. Parts must start with 'part of'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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: compiler/javatests/com/google/dart/compiler/end2end/inc/MemoryLibrarySource.java
diff --git a/compiler/javatests/com/google/dart/compiler/end2end/inc/MemoryLibrarySource.java b/compiler/javatests/com/google/dart/compiler/end2end/inc/MemoryLibrarySource.java
index a2fd2c447f8d47acb46b9b5857c1d61a6fe1f4d0..e31466f5ff96269d10f5217b6d38041cdcd36536 100644
--- a/compiler/javatests/com/google/dart/compiler/end2end/inc/MemoryLibrarySource.java
+++ b/compiler/javatests/com/google/dart/compiler/end2end/inc/MemoryLibrarySource.java
@@ -22,17 +22,20 @@ import java.util.Map;
public class MemoryLibrarySource implements LibrarySource {
public static final String IO_EXCEPTION_CONTENT = "simulate-IOException";
private final String libName;
+ private final Map<String, DartSource> sourceMap;
private final Map<String, String> sourceContentMap;
private final Map<String, Long> sourceLastModifiedMap;
public MemoryLibrarySource(String libName) {
this.libName = libName;
+ sourceMap = Maps.newHashMap();
sourceContentMap = Maps.newHashMap();
sourceLastModifiedMap = Maps.newHashMap();
}
private MemoryLibrarySource(String libName, MemoryLibrarySource parent) {
this.libName = libName;
+ sourceMap = parent.sourceMap;
sourceContentMap = parent.sourceContentMap;
sourceLastModifiedMap = parent.sourceLastModifiedMap;
}
@@ -75,17 +78,33 @@ public class MemoryLibrarySource implements LibrarySource {
}
@Override
- public LibrarySource getImportFor(final String relPath) throws IOException {
+ public LibrarySource getImportFor(String relPath) throws IOException {
+ if (!sourceContentMap.containsKey(relPath)) {
+ return null;
+ }
return new MemoryLibrarySource(relPath, this);
}
@Override
public DartSource getSourceFor(final String relPath) {
+ DartSource result;
+ // check cache
+ {
+ result = sourceMap.get(relPath);
+ if (result != null) {
+ return result;
+ }
+ }
+ // prepare content
final String content = sourceContentMap.get(relPath);
final Long sourceLastModified = sourceLastModifiedMap.get(relPath);
+ // may be does not exist
+ if (content == null) {
+ return null;
+ }
// Return fake UrlDateSource with in-memory content.
final URI uri = URI.create(relPath);
- return new UrlDartSource(uri, relPath, this) {
+ result = new UrlDartSource(uri, relPath, this) {
@Override
public String getName() {
return relPath;
@@ -111,12 +130,15 @@ public class MemoryLibrarySource implements LibrarySource {
return new StringReader(content);
}
};
+ sourceMap.put(relPath, result);
+ return result;
}
/**
* Sets the given content for the source.
*/
public void setContent(String relPath, String content) {
+ sourceMap.remove(relPath);
sourceContentMap.put(relPath, content);
sourceLastModifiedMap.put(relPath, System.currentTimeMillis());
}

Powered by Google App Engine
This is Rietveld 408576698