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

Unified Diff: pkg/analyzer/lib/file_system/memory_file_system.dart

Issue 2265593002: Add writeAsStringSync (issue 27109) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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: pkg/analyzer/lib/file_system/memory_file_system.dart
diff --git a/pkg/analyzer/lib/file_system/memory_file_system.dart b/pkg/analyzer/lib/file_system/memory_file_system.dart
index dbc41d14b75d257e351f63763872e6f8a569687e..51d635bed2900e42359453db08c8e1887cfda938 100644
--- a/pkg/analyzer/lib/file_system/memory_file_system.dart
+++ b/pkg/analyzer/lib/file_system/memory_file_system.dart
@@ -23,7 +23,6 @@ class MemoryResourceProvider implements ResourceProvider {
final Map<String, _MemoryResource> _pathToResource =
new HashMap<String, _MemoryResource>();
final Map<String, String> _pathToContent = new HashMap<String, String>();
- final Map<String, List<int>> _pathToBytes = new HashMap<String, List<int>>();
final Map<String, int> _pathToTimestamp = new HashMap<String, int>();
final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers =
new HashMap<String, List<StreamController<WatchEvent>>>();
@@ -135,7 +134,7 @@ class MemoryResourceProvider implements ResourceProvider {
File newFileWithBytes(String path, List<int> bytes, [int stamp]) {
path = pathContext.normalize(path);
_MemoryFile file = _newFile(path);
- _pathToBytes[path] = bytes;
+ _pathToContent[path] = new String.fromCharCodes(bytes);
_pathToTimestamp[path] = stamp ?? nextStamp++;
_notifyWatchers(path, ChangeType.ADD);
return file;
@@ -180,7 +179,6 @@ class MemoryResourceProvider implements ResourceProvider {
_MemoryFile newFile = _newFile(newPath);
_pathToResource.remove(path);
_pathToContent[newPath] = _pathToContent.remove(path);
- _pathToBytes[newPath] = _pathToBytes.remove(path);
_pathToTimestamp[newPath] = _pathToTimestamp.remove(path);
if (existingNewResource != null) {
_notifyWatchers(newPath, ChangeType.REMOVE);
@@ -245,10 +243,10 @@ class MemoryResourceProvider implements ResourceProvider {
});
}
- void _setFileBytes(_MemoryFile file, List<int> bytes) {
+ void _setFileContent(_MemoryFile file, String content) {
String path = file.path;
_pathToResource[path] = file;
- _pathToBytes[path] = bytes;
+ _pathToContent[path] = content;
_pathToTimestamp[path] = nextStamp++;
_notifyWatchers(path, ChangeType.MODIFY);
}
@@ -316,6 +314,11 @@ class _MemoryDummyLink extends _MemoryResource implements File {
void writeAsBytesSync(List<int> bytes) {
throw new FileSystemException(path, 'File could not be written');
}
+
+ @override
+ void writeAsStringSync(String content) {
+ throw new FileSystemException(path, 'File could not be written');
+ }
}
/**
@@ -355,11 +358,11 @@ class _MemoryFile extends _MemoryResource implements File {
@override
List<int> readAsBytesSync() {
- List<int> bytes = _provider._pathToBytes[path];
- if (bytes == null) {
- throw new FileSystemException(path, 'File "$path" is not binary.');
+ String content = _provider._pathToContent[path];
+ if (content == null) {
+ throw new FileSystemException(path, 'File "$path" does not exist.');
}
- return bytes;
+ return content.codeUnits;
}
@override
@@ -381,7 +384,12 @@ class _MemoryFile extends _MemoryResource implements File {
@override
void writeAsBytesSync(List<int> bytes) {
- _provider._setFileBytes(this, bytes);
+ _provider._setFileContent(this, new String.fromCharCodes(bytes));
+ }
+
+ @override
+ void writeAsStringSync(String content) {
+ _provider._setFileContent(this, content);
}
}

Powered by Google App Engine
This is Rietveld 408576698