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

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

Issue 952333002: Don't do folder existence checks when parsing pub list results. (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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 169
170 /** 170 /**
171 * An in-memory implementation of [File]. 171 * An in-memory implementation of [File].
172 */ 172 */
173 class _MemoryFile extends _MemoryResource implements File { 173 class _MemoryFile extends _MemoryResource implements File {
174 _MemoryFile(MemoryResourceProvider provider, String path) 174 _MemoryFile(MemoryResourceProvider provider, String path)
175 : super(provider, path); 175 : super(provider, path);
176 176
177 @override
178 bool get exists => _provider._pathToResource[path] is _MemoryFile;
179
177 int get modificationStamp { 180 int get modificationStamp {
178 int stamp = _provider._pathToTimestamp[path]; 181 int stamp = _provider._pathToTimestamp[path];
179 if (stamp == null) { 182 if (stamp == null) {
180 throw new FileSystemException(path, 'File does not exist.'); 183 throw new FileSystemException(path, 'File does not exist.');
181 } 184 }
182 return stamp; 185 return stamp;
183 } 186 }
184 187
185 String get _content { 188 String get _content {
186 String content = _provider._pathToContent[path]; 189 String content = _provider._pathToContent[path];
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 String toString() => _file.toString(); 282 String toString() => _file.toString();
280 } 283 }
281 284
282 285
283 /** 286 /**
284 * An in-memory implementation of [Folder]. 287 * An in-memory implementation of [Folder].
285 */ 288 */
286 class _MemoryFolder extends _MemoryResource implements Folder { 289 class _MemoryFolder extends _MemoryResource implements Folder {
287 _MemoryFolder(MemoryResourceProvider provider, String path) 290 _MemoryFolder(MemoryResourceProvider provider, String path)
288 : super(provider, path); 291 : super(provider, path);
292
289 @override 293 @override
290 Stream<WatchEvent> get changes { 294 Stream<WatchEvent> get changes {
291 StreamController<WatchEvent> streamController = 295 StreamController<WatchEvent> streamController =
292 new StreamController<WatchEvent>(); 296 new StreamController<WatchEvent>();
293 if (!_provider._pathToWatchers.containsKey(path)) { 297 if (!_provider._pathToWatchers.containsKey(path)) {
294 _provider._pathToWatchers[path] = <StreamController<WatchEvent>>[]; 298 _provider._pathToWatchers[path] = <StreamController<WatchEvent>>[];
295 } 299 }
296 _provider._pathToWatchers[path].add(streamController); 300 _provider._pathToWatchers[path].add(streamController);
297 streamController.done.then((_) { 301 streamController.done.then((_) {
298 _provider._pathToWatchers[path].remove(streamController); 302 _provider._pathToWatchers[path].remove(streamController);
299 if (_provider._pathToWatchers[path].isEmpty) { 303 if (_provider._pathToWatchers[path].isEmpty) {
300 _provider._pathToWatchers.remove(path); 304 _provider._pathToWatchers.remove(path);
301 } 305 }
302 }); 306 });
303 return streamController.stream; 307 return streamController.stream;
304 } 308 }
305 309
306 @override 310 @override
311 bool get exists => _provider._pathToResource[path] is _MemoryFolder;
312
313 @override
307 String canonicalizePath(String relPath) { 314 String canonicalizePath(String relPath) {
308 relPath = posix.normalize(relPath); 315 relPath = posix.normalize(relPath);
309 String childPath = posix.join(path, relPath); 316 String childPath = posix.join(path, relPath);
310 childPath = posix.normalize(childPath); 317 childPath = posix.normalize(childPath);
311 return childPath; 318 return childPath;
312 } 319 }
313 320
314 @override 321 @override
315 bool contains(String path) { 322 bool contains(String path) {
316 return posix.isWithin(this.path, path); 323 return posix.isWithin(this.path, path);
317 } 324 }
318 325
319 @override 326 @override
320 Resource getChild(String relPath) { 327 Resource getChild(String relPath) {
321 String childPath = canonicalizePath(relPath); 328 String childPath = canonicalizePath(relPath);
322 _MemoryResource resource = _provider._pathToResource[childPath]; 329 _MemoryResource resource = _provider._pathToResource[childPath];
323 if (resource == null) { 330 if (resource == null) {
324 resource = new _MemoryFile(_provider, childPath); 331 resource = new _MemoryFile(_provider, childPath);
325 } 332 }
326 return resource; 333 return resource;
327 } 334 }
328 335
329 @override 336 @override
337 _MemoryFolder getChildAssumingFolder(String relPath) {
338 String childPath = canonicalizePath(relPath);
339 _MemoryResource resource = _provider._pathToResource[childPath];
340 if (resource is _MemoryFolder) {
341 return resource;
342 }
343 return new _MemoryFolder(_provider, childPath);
344 }
345
346 @override
330 List<Resource> getChildren() { 347 List<Resource> getChildren() {
331 List<Resource> children = <Resource>[]; 348 List<Resource> children = <Resource>[];
332 _provider._pathToResource.forEach((resourcePath, resource) { 349 _provider._pathToResource.forEach((resourcePath, resource) {
333 if (posix.dirname(resourcePath) == path) { 350 if (posix.dirname(resourcePath) == path) {
334 children.add(resource); 351 children.add(resource);
335 } 352 }
336 }); 353 });
337 return children; 354 return children;
338 } 355 }
339 356
(...skipping 10 matching lines...) Expand all
350 /** 367 /**
351 * An in-memory implementation of [Resource]. 368 * An in-memory implementation of [Resource].
352 */ 369 */
353 abstract class _MemoryResource implements Resource { 370 abstract class _MemoryResource implements Resource {
354 final MemoryResourceProvider _provider; 371 final MemoryResourceProvider _provider;
355 final String path; 372 final String path;
356 373
357 _MemoryResource(this._provider, this.path); 374 _MemoryResource(this._provider, this.path);
358 375
359 @override 376 @override
360 bool get exists => _provider._pathToResource.containsKey(path);
361
362 @override
363 get hashCode => path.hashCode; 377 get hashCode => path.hashCode;
364 378
365 @override 379 @override
366 Folder get parent { 380 Folder get parent {
367 String parentPath = posix.dirname(path); 381 String parentPath = posix.dirname(path);
368 if (parentPath == path) { 382 if (parentPath == path) {
369 return null; 383 return null;
370 } 384 }
371 return _provider.getResource(parentPath); 385 return _provider.getResource(parentPath);
372 } 386 }
373 387
374 @override 388 @override
375 String get shortName => posix.basename(path); 389 String get shortName => posix.basename(path);
376 390
377 @override 391 @override
378 bool operator ==(other) { 392 bool operator ==(other) {
379 if (runtimeType != other.runtimeType) { 393 if (runtimeType != other.runtimeType) {
380 return false; 394 return false;
381 } 395 }
382 return path == other.path; 396 return path == other.path;
383 } 397 }
384 398
385 @override 399 @override
386 String toString() => path; 400 String toString() => path;
387 } 401 }
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