| 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 analyzer.file_system.memory_file_system; | 5 library analyzer.file_system.memory_file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 */ | 21 */ |
| 22 class MemoryResourceProvider implements ResourceProvider { | 22 class MemoryResourceProvider implements ResourceProvider { |
| 23 final Map<String, _MemoryResource> _pathToResource = | 23 final Map<String, _MemoryResource> _pathToResource = |
| 24 new HashMap<String, _MemoryResource>(); | 24 new HashMap<String, _MemoryResource>(); |
| 25 final Map<String, String> _pathToContent = new HashMap<String, String>(); | 25 final Map<String, String> _pathToContent = new HashMap<String, String>(); |
| 26 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); | 26 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); |
| 27 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = | 27 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = |
| 28 new HashMap<String, List<StreamController<WatchEvent>>>(); | 28 new HashMap<String, List<StreamController<WatchEvent>>>(); |
| 29 int nextStamp = 0; | 29 int nextStamp = 0; |
| 30 | 30 |
| 31 final AbsolutePathContext absolutePathContext = | 31 final Context _pathContext; |
| 32 new AbsolutePathContext(false); | 32 final AbsolutePathContext absolutePathContext; |
| 33 |
| 34 MemoryResourceProvider({bool isWindows: false}) |
| 35 : _pathContext = isWindows ? windows : posix, |
| 36 absolutePathContext = new AbsolutePathContext(isWindows); |
| 33 | 37 |
| 34 @override | 38 @override |
| 35 Context get pathContext => posix; | 39 Context get pathContext => _pathContext; |
| 36 | 40 |
| 37 /** | 41 /** |
| 38 * Delete the file with the given path. | 42 * Delete the file with the given path. |
| 39 */ | 43 */ |
| 40 void deleteFile(String path) { | 44 void deleteFile(String path) { |
| 41 _checkFileAtPath(path); | 45 _checkFileAtPath(path); |
| 42 _pathToResource.remove(path); | 46 _pathToResource.remove(path); |
| 43 _pathToContent.remove(path); | 47 _pathToContent.remove(path); |
| 44 _pathToTimestamp.remove(path); | 48 _pathToTimestamp.remove(path); |
| 45 _notifyWatchers(path, ChangeType.REMOVE); | 49 _notifyWatchers(path, ChangeType.REMOVE); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 _MemoryFile file = new _MemoryFile(this, path); | 124 _MemoryFile file = new _MemoryFile(this, path); |
| 121 _pathToResource[path] = file; | 125 _pathToResource[path] = file; |
| 122 _pathToContent[path] = content; | 126 _pathToContent[path] = content; |
| 123 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++; | 127 _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++; |
| 124 _notifyWatchers(path, ChangeType.ADD); | 128 _notifyWatchers(path, ChangeType.ADD); |
| 125 return file; | 129 return file; |
| 126 } | 130 } |
| 127 | 131 |
| 128 Folder newFolder(String path) { | 132 Folder newFolder(String path) { |
| 129 path = pathContext.normalize(path); | 133 path = pathContext.normalize(path); |
| 130 if (!path.startsWith(pathContext.separator)) { | 134 if (!pathContext.isAbsolute(path)) { |
| 131 throw new ArgumentError( | 135 throw new ArgumentError("Path must be absolute : $path"); |
| 132 "Path must start with '${pathContext.separator}' : $path"); | |
| 133 } | 136 } |
| 134 _MemoryResource resource = _pathToResource[path]; | 137 _MemoryResource resource = _pathToResource[path]; |
| 135 if (resource == null) { | 138 if (resource == null) { |
| 136 String parentPath = pathContext.dirname(path); | 139 String parentPath = pathContext.dirname(path); |
| 137 if (parentPath != path) { | 140 if (parentPath != path) { |
| 138 newFolder(parentPath); | 141 newFolder(parentPath); |
| 139 } | 142 } |
| 140 _MemoryFolder folder = new _MemoryFolder(this, path); | 143 _MemoryFolder folder = new _MemoryFolder(this, path); |
| 141 _pathToResource[path] = folder; | 144 _pathToResource[path] = folder; |
| 142 _pathToTimestamp[path] = nextStamp++; | 145 _pathToTimestamp[path] = nextStamp++; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 bool operator ==(other) { | 492 bool operator ==(other) { |
| 490 if (runtimeType != other.runtimeType) { | 493 if (runtimeType != other.runtimeType) { |
| 491 return false; | 494 return false; |
| 492 } | 495 } |
| 493 return path == other.path; | 496 return path == other.path; |
| 494 } | 497 } |
| 495 | 498 |
| 496 @override | 499 @override |
| 497 String toString() => path; | 500 String toString() => path; |
| 498 } | 501 } |
| OLD | NEW |