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

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

Issue 1191933004: add file watching support (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 6 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
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 /** 177 /**
178 * An in-memory implementation of [File] which acts like a symbolic link to a 178 * An in-memory implementation of [File] which acts like a symbolic link to a
179 * non-existent file. 179 * non-existent file.
180 */ 180 */
181 class _MemoryDummyLink extends _MemoryResource implements File { 181 class _MemoryDummyLink extends _MemoryResource implements File {
182 _MemoryDummyLink(MemoryResourceProvider provider, String path) 182 _MemoryDummyLink(MemoryResourceProvider provider, String path)
183 : super(provider, path); 183 : super(provider, path);
184 184
185 @override 185 @override
186 Stream<WatchEvent> get changes {
187 throw new FileSystemException(path, "File does not exist");
188 }
189
190 @override
186 bool get exists => false; 191 bool get exists => false;
187 192
188 int get modificationStamp { 193 int get modificationStamp {
189 int stamp = _provider._pathToTimestamp[path]; 194 int stamp = _provider._pathToTimestamp[path];
190 if (stamp == null) { 195 if (stamp == null) {
191 throw new FileSystemException(path, "File does not exist"); 196 throw new FileSystemException(path, "File does not exist");
192 } 197 }
193 return stamp; 198 return stamp;
194 } 199 }
195 200
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 356 }
352 357
353 /** 358 /**
354 * An in-memory implementation of [Folder]. 359 * An in-memory implementation of [Folder].
355 */ 360 */
356 class _MemoryFolder extends _MemoryResource implements Folder { 361 class _MemoryFolder extends _MemoryResource implements Folder {
357 _MemoryFolder(MemoryResourceProvider provider, String path) 362 _MemoryFolder(MemoryResourceProvider provider, String path)
358 : super(provider, path); 363 : super(provider, path);
359 364
360 @override 365 @override
361 Stream<WatchEvent> get changes {
362 StreamController<WatchEvent> streamController =
363 new StreamController<WatchEvent>();
364 if (!_provider._pathToWatchers.containsKey(path)) {
365 _provider._pathToWatchers[path] = <StreamController<WatchEvent>>[];
366 }
367 _provider._pathToWatchers[path].add(streamController);
368 streamController.done.then((_) {
369 _provider._pathToWatchers[path].remove(streamController);
370 if (_provider._pathToWatchers[path].isEmpty) {
371 _provider._pathToWatchers.remove(path);
372 }
373 });
374 return streamController.stream;
375 }
376
377 @override
378 bool get exists => _provider._pathToResource[path] is _MemoryFolder; 366 bool get exists => _provider._pathToResource[path] is _MemoryFolder;
379 367
380 @override 368 @override
381 String canonicalizePath(String relPath) { 369 String canonicalizePath(String relPath) {
382 relPath = posix.normalize(relPath); 370 relPath = posix.normalize(relPath);
383 String childPath = posix.join(path, relPath); 371 String childPath = posix.join(path, relPath);
384 childPath = posix.normalize(childPath); 372 childPath = posix.normalize(childPath);
385 return childPath; 373 return childPath;
386 } 374 }
387 375
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 423
436 /** 424 /**
437 * An in-memory implementation of [Resource]. 425 * An in-memory implementation of [Resource].
438 */ 426 */
439 abstract class _MemoryResource implements Resource { 427 abstract class _MemoryResource implements Resource {
440 final MemoryResourceProvider _provider; 428 final MemoryResourceProvider _provider;
441 final String path; 429 final String path;
442 430
443 _MemoryResource(this._provider, this.path); 431 _MemoryResource(this._provider, this.path);
444 432
433 Stream<WatchEvent> get changes {
434 StreamController<WatchEvent> streamController =
435 new StreamController<WatchEvent>();
436 if (!_provider._pathToWatchers.containsKey(path)) {
437 _provider._pathToWatchers[path] = <StreamController<WatchEvent>>[];
438 }
439 _provider._pathToWatchers[path].add(streamController);
440 streamController.done.then((_) {
441 _provider._pathToWatchers[path].remove(streamController);
442 if (_provider._pathToWatchers[path].isEmpty) {
443 _provider._pathToWatchers.remove(path);
444 }
445 });
446 return streamController.stream;
447 }
448
445 @override 449 @override
446 get hashCode => path.hashCode; 450 get hashCode => path.hashCode;
447 451
448 @override 452 @override
449 Folder get parent { 453 Folder get parent {
450 String parentPath = posix.dirname(path); 454 String parentPath = posix.dirname(path);
451 if (parentPath == path) { 455 if (parentPath == path) {
452 return null; 456 return null;
453 } 457 }
454 return _provider.getResource(parentPath); 458 return _provider.getResource(parentPath);
455 } 459 }
456 460
457 @override 461 @override
458 String get shortName => posix.basename(path); 462 String get shortName => posix.basename(path);
459 463
460 @override 464 @override
461 bool operator ==(other) { 465 bool operator ==(other) {
462 if (runtimeType != other.runtimeType) { 466 if (runtimeType != other.runtimeType) {
463 return false; 467 return false;
464 } 468 }
465 return path == other.path; 469 return path == other.path;
466 } 470 }
467 471
468 @override 472 @override
469 String toString() => path; 473 String toString() => path;
470 } 474 }
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