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

Side by Side Diff: pkg/analyzer/lib/file_system/memory_file_system.dart

Issue 1007233002: Add readAsStringSync() to File. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library memory_file_system; 5 library memory_file_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 @override 200 @override
201 Source createSource([Uri uri]) { 201 Source createSource([Uri uri]) {
202 throw new FileSystemException(path, 'File could not be read'); 202 throw new FileSystemException(path, 'File could not be read');
203 } 203 }
204 204
205 @override 205 @override
206 bool isOrContains(String path) { 206 bool isOrContains(String path) {
207 return path == this.path; 207 return path == this.path;
208 } 208 }
209
210 @override
211 String readAsStringSync() {
212 throw new FileSystemException(path, 'File could not be read');
213 }
209 } 214 }
210 215
211 /** 216 /**
212 * An in-memory implementation of [File]. 217 * An in-memory implementation of [File].
213 */ 218 */
214 class _MemoryFile extends _MemoryResource implements File { 219 class _MemoryFile extends _MemoryResource implements File {
215 _MemoryFile(MemoryResourceProvider provider, String path) 220 _MemoryFile(MemoryResourceProvider provider, String path)
216 : super(provider, path); 221 : super(provider, path);
217 222
218 @override 223 @override
219 bool get exists => _provider._pathToResource[path] is _MemoryFile; 224 bool get exists => _provider._pathToResource[path] is _MemoryFile;
220 225
221 int get modificationStamp { 226 int get modificationStamp {
222 int stamp = _provider._pathToTimestamp[path]; 227 int stamp = _provider._pathToTimestamp[path];
223 if (stamp == null) { 228 if (stamp == null) {
224 throw new FileSystemException(path, 'File does not exist.'); 229 throw new FileSystemException(path, 'File "$path" does not exist.');
225 } 230 }
226 return stamp; 231 return stamp;
227 } 232 }
228 233
229 String get _content { 234 String get _content {
230 String content = _provider._pathToContent[path]; 235 String content = _provider._pathToContent[path];
231 if (content == null) { 236 if (content == null) {
232 throw new FileSystemException(path, "File does not exist"); 237 throw new FileSystemException(path, 'File "$path" does not exist.');
233 } 238 }
234 return content; 239 return content;
235 } 240 }
236 241
237 @override 242 @override
238 Source createSource([Uri uri]) { 243 Source createSource([Uri uri]) {
239 if (uri == null) { 244 if (uri == null) {
240 uri = posix.toUri(path); 245 uri = posix.toUri(path);
241 } 246 }
242 return new _MemoryFileSource(this, uri); 247 return new _MemoryFileSource(this, uri);
243 } 248 }
244 249
245 @override 250 @override
246 bool isOrContains(String path) { 251 bool isOrContains(String path) {
247 return path == this.path; 252 return path == this.path;
248 } 253 }
254
255 @override
256 String readAsStringSync() {
257 String content = _provider._pathToContent[path];
258 if (content == null) {
259 throw new FileSystemException(path, 'File "$path" does not exist.');
260 }
261 return content;
262 }
249 } 263 }
250 264
251 /** 265 /**
252 * An in-memory implementation of [Source]. 266 * An in-memory implementation of [Source].
253 */ 267 */
254 class _MemoryFileSource extends Source { 268 class _MemoryFileSource extends Source {
255 /** 269 /**
256 * Map from encoded URI/filepath pair to a unique integer identifier. This 270 * Map from encoded URI/filepath pair to a unique integer identifier. This
257 * identifier is used for equality tests and hash codes. 271 * identifier is used for equality tests and hash codes.
258 * 272 *
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 bool operator ==(other) { 461 bool operator ==(other) {
448 if (runtimeType != other.runtimeType) { 462 if (runtimeType != other.runtimeType) {
449 return false; 463 return false;
450 } 464 }
451 return path == other.path; 465 return path == other.path;
452 } 466 }
453 467
454 @override 468 @override
455 String toString() => path; 469 String toString() => path;
456 } 470 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/file_system/file_system.dart ('k') | pkg/analyzer/lib/file_system/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698