| OLD | NEW |
| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 }); | 146 }); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * An in-memory implementation of [File] which acts like a symbolic link to a | 152 * An in-memory implementation of [File] which acts like a symbolic link to a |
| 153 * non-existent file. | 153 * non-existent file. |
| 154 */ | 154 */ |
| 155 class _MemoryDummyLink extends _MemoryResource implements File { | 155 class _MemoryDummyLink extends _MemoryResource implements File { |
| 156 _MemoryDummyLink(MemoryResourceProvider provider, String path) : super( | 156 _MemoryDummyLink(MemoryResourceProvider provider, String path) |
| 157 provider, | 157 : super(provider, path); |
| 158 path); | |
| 159 | 158 |
| 160 @override | 159 @override |
| 161 bool get exists => false; | 160 bool get exists => false; |
| 162 | 161 |
| 163 String get _content { | 162 String get _content { |
| 164 throw new MemoryResourceException(path, "File '$path' could not be read"); | 163 throw new MemoryResourceException(path, "File '$path' could not be read"); |
| 165 } | 164 } |
| 166 | 165 |
| 167 int get _timestamp => _provider._pathToTimestamp[path]; | 166 int get _timestamp => _provider._pathToTimestamp[path]; |
| 168 | 167 |
| 169 @override | 168 @override |
| 170 Source createSource([Uri uri]) { | 169 Source createSource([Uri uri]) { |
| 171 throw new MemoryResourceException(path, "File '$path' could not be read"); | 170 throw new MemoryResourceException(path, "File '$path' could not be read"); |
| 172 } | 171 } |
| 173 | 172 |
| 174 @override | 173 @override |
| 175 bool isOrContains(String path) { | 174 bool isOrContains(String path) { |
| 176 return path == this.path; | 175 return path == this.path; |
| 177 } | 176 } |
| 178 } | 177 } |
| 179 | 178 |
| 180 | 179 |
| 181 /** | 180 /** |
| 182 * An in-memory implementation of [File]. | 181 * An in-memory implementation of [File]. |
| 183 */ | 182 */ |
| 184 class _MemoryFile extends _MemoryResource implements File { | 183 class _MemoryFile extends _MemoryResource implements File { |
| 185 _MemoryFile(MemoryResourceProvider provider, String path) : super( | 184 _MemoryFile(MemoryResourceProvider provider, String path) |
| 186 provider, | 185 : super(provider, path); |
| 187 path); | |
| 188 | 186 |
| 189 String get _content { | 187 String get _content { |
| 190 String content = _provider._pathToContent[path]; | 188 String content = _provider._pathToContent[path]; |
| 191 if (content == null) { | 189 if (content == null) { |
| 192 throw new MemoryResourceException(path, "File '$path' does not exist"); | 190 throw new MemoryResourceException(path, "File '$path' does not exist"); |
| 193 } | 191 } |
| 194 return content; | 192 return content; |
| 195 } | 193 } |
| 196 | 194 |
| 197 int get _timestamp => _provider._pathToTimestamp[path]; | 195 int get _timestamp => _provider._pathToTimestamp[path]; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 275 |
| 278 @override | 276 @override |
| 279 String toString() => _file.toString(); | 277 String toString() => _file.toString(); |
| 280 } | 278 } |
| 281 | 279 |
| 282 | 280 |
| 283 /** | 281 /** |
| 284 * An in-memory implementation of [Folder]. | 282 * An in-memory implementation of [Folder]. |
| 285 */ | 283 */ |
| 286 class _MemoryFolder extends _MemoryResource implements Folder { | 284 class _MemoryFolder extends _MemoryResource implements Folder { |
| 287 _MemoryFolder(MemoryResourceProvider provider, String path) : super( | 285 _MemoryFolder(MemoryResourceProvider provider, String path) |
| 288 provider, | 286 : super(provider, path); |
| 289 path); | |
| 290 @override | 287 @override |
| 291 Stream<WatchEvent> get changes { | 288 Stream<WatchEvent> get changes { |
| 292 StreamController<WatchEvent> streamController = | 289 StreamController<WatchEvent> streamController = |
| 293 new StreamController<WatchEvent>(); | 290 new StreamController<WatchEvent>(); |
| 294 if (!_provider._pathToWatchers.containsKey(path)) { | 291 if (!_provider._pathToWatchers.containsKey(path)) { |
| 295 _provider._pathToWatchers[path] = <StreamController<WatchEvent>>[]; | 292 _provider._pathToWatchers[path] = <StreamController<WatchEvent>>[]; |
| 296 } | 293 } |
| 297 _provider._pathToWatchers[path].add(streamController); | 294 _provider._pathToWatchers[path].add(streamController); |
| 298 streamController.done.then((_) { | 295 streamController.done.then((_) { |
| 299 _provider._pathToWatchers[path].remove(streamController); | 296 _provider._pathToWatchers[path].remove(streamController); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 bool operator ==(other) { | 376 bool operator ==(other) { |
| 380 if (runtimeType != other.runtimeType) { | 377 if (runtimeType != other.runtimeType) { |
| 381 return false; | 378 return false; |
| 382 } | 379 } |
| 383 return path == other.path; | 380 return path == other.path; |
| 384 } | 381 } |
| 385 | 382 |
| 386 @override | 383 @override |
| 387 String toString() => path; | 384 String toString() => path; |
| 388 } | 385 } |
| OLD | NEW |