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

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

Issue 989393002: Wrap dart:io exception in getChildren(), implement for the memory FS. (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
« no previous file with comments | « no previous file | pkg/analyzer/lib/file_system/physical_file_system.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 path = posix.normalize(path); 103 path = posix.normalize(path);
104 newFolder(posix.dirname(path)); 104 newFolder(posix.dirname(path));
105 _MemoryFile file = new _MemoryFile(this, path); 105 _MemoryFile file = new _MemoryFile(this, path);
106 _pathToResource[path] = file; 106 _pathToResource[path] = file;
107 _pathToContent[path] = content; 107 _pathToContent[path] = content;
108 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++; 108 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++;
109 _notifyWatchers(path, ChangeType.ADD); 109 _notifyWatchers(path, ChangeType.ADD);
110 return file; 110 return file;
111 } 111 }
112 112
113 File updateFile(String path, String content, [int stamp]) {
114 path = posix.normalize(path);
115 newFolder(posix.dirname(path));
116 _MemoryFile file = new _MemoryFile(this, path);
117 _pathToResource[path] = file;
118 _pathToContent[path] = content;
119 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++;
120 _notifyWatchers(path, ChangeType.MODIFY);
121 return file;
122 }
123
124 Folder newFolder(String path) { 113 Folder newFolder(String path) {
125 path = posix.normalize(path); 114 path = posix.normalize(path);
126 if (!path.startsWith('/')) { 115 if (!path.startsWith('/')) {
127 throw new ArgumentError("Path must start with '/'"); 116 throw new ArgumentError("Path must start with '/'");
128 } 117 }
129 _MemoryResource resource = _pathToResource[path]; 118 _MemoryResource resource = _pathToResource[path];
130 if (resource == null) { 119 if (resource == null) {
131 String parentPath = posix.dirname(path); 120 String parentPath = posix.dirname(path);
132 if (parentPath != path) { 121 if (parentPath != path) {
133 newFolder(parentPath); 122 newFolder(parentPath);
134 } 123 }
135 _MemoryFolder folder = new _MemoryFolder(this, path); 124 _MemoryFolder folder = new _MemoryFolder(this, path);
136 _pathToResource[path] = folder; 125 _pathToResource[path] = folder;
137 _pathToTimestamp[path] = nextStamp++; 126 _pathToTimestamp[path] = nextStamp++;
138 return folder; 127 return folder;
139 } else if (resource is _MemoryFolder) { 128 } else if (resource is _MemoryFolder) {
140 return resource; 129 return resource;
141 } else { 130 } else {
142 String message = 131 String message =
143 'Folder expected at ' "'$path'" 'but ${resource.runtimeType} found'; 132 'Folder expected at ' "'$path'" 'but ${resource.runtimeType} found';
144 throw new ArgumentError(message); 133 throw new ArgumentError(message);
145 } 134 }
146 } 135 }
147 136
137 File updateFile(String path, String content, [int stamp]) {
138 path = posix.normalize(path);
139 newFolder(posix.dirname(path));
140 _MemoryFile file = new _MemoryFile(this, path);
141 _pathToResource[path] = file;
142 _pathToContent[path] = content;
143 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++;
144 _notifyWatchers(path, ChangeType.MODIFY);
145 return file;
146 }
147
148 void _checkFileAtPath(String path) { 148 void _checkFileAtPath(String path) {
149 _MemoryResource resource = _pathToResource[path]; 149 _MemoryResource resource = _pathToResource[path];
150 if (resource is! _MemoryFile) { 150 if (resource is! _MemoryFile) {
151 throw new ArgumentError( 151 throw new ArgumentError(
152 'File expected at "$path" but ${resource.runtimeType} found'); 152 'File expected at "$path" but ${resource.runtimeType} found');
153 } 153 }
154 } 154 }
155 155
156 void _checkFolderAtPath(String path) { 156 void _checkFolderAtPath(String path) {
157 _MemoryResource resource = _pathToResource[path]; 157 _MemoryResource resource = _pathToResource[path];
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 String childPath = canonicalizePath(relPath); 391 String childPath = canonicalizePath(relPath);
392 _MemoryResource resource = _provider._pathToResource[childPath]; 392 _MemoryResource resource = _provider._pathToResource[childPath];
393 if (resource is _MemoryFolder) { 393 if (resource is _MemoryFolder) {
394 return resource; 394 return resource;
395 } 395 }
396 return new _MemoryFolder(_provider, childPath); 396 return new _MemoryFolder(_provider, childPath);
397 } 397 }
398 398
399 @override 399 @override
400 List<Resource> getChildren() { 400 List<Resource> getChildren() {
401 if (!exists) {
402 throw new FileSystemException(path, 'Folder does not exist.');
403 }
401 List<Resource> children = <Resource>[]; 404 List<Resource> children = <Resource>[];
402 _provider._pathToResource.forEach((resourcePath, resource) { 405 _provider._pathToResource.forEach((resourcePath, resource) {
403 if (posix.dirname(resourcePath) == path) { 406 if (posix.dirname(resourcePath) == path) {
404 children.add(resource); 407 children.add(resource);
405 } 408 }
406 }); 409 });
407 return children; 410 return children;
408 } 411 }
409 412
410 @override 413 @override
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 bool operator ==(other) { 447 bool operator ==(other) {
445 if (runtimeType != other.runtimeType) { 448 if (runtimeType != other.runtimeType) {
446 return false; 449 return false;
447 } 450 }
448 return path == other.path; 451 return path == other.path;
449 } 452 }
450 453
451 @override 454 @override
452 String toString() => path; 455 String toString() => path;
453 } 456 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/file_system/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698