Chromium Code Reviews| Index: pkg/analyzer/lib/file_system/memory_file_system.dart |
| diff --git a/pkg/analyzer/lib/file_system/memory_file_system.dart b/pkg/analyzer/lib/file_system/memory_file_system.dart |
| index b038f45eb92ab1863a5b45e62e64dd41ea49d581..4de46a34c4636a231438b8d95a174b45ce4bd203 100644 |
| --- a/pkg/analyzer/lib/file_system/memory_file_system.dart |
| +++ b/pkg/analyzer/lib/file_system/memory_file_system.dart |
| @@ -47,6 +47,30 @@ class MemoryResourceProvider implements ResourceProvider { |
| @override |
| Context get pathContext => posix; |
| + /** |
| + * Simulate revoked file access |
| + * and return an object that can be passed to [restore]. |
| + */ |
| + clear() { |
| + var restorePoint = new _MemoryRestorePoint(this); |
| + _pathToResource.clear(); |
| + _pathToContent.clear(); |
| + _pathToTimestamp.clear(); |
| + // TODO(danrubel) notify watchers |
| + return restorePoint; |
| + } |
| + |
| + /** |
| + * Simulate restored file access based upon some earlier call to [clear]. |
| + */ |
| + void restore(var restorePoint) { |
| + _pathToResource.clear(); |
| + _pathToContent.clear(); |
| + _pathToTimestamp.clear(); |
| + (restorePoint as _MemoryRestorePoint).restore(this); |
| + // TODO(danrubel) notify watchers |
| + } |
| + |
| void deleteFile(String path) { |
| _checkFileAtPath(path); |
| _pathToResource.remove(path); |
| @@ -149,6 +173,30 @@ class MemoryResourceProvider implements ResourceProvider { |
| /** |
| + * A restore point captures the [MemoryResourceProvider] state |
| + * so that it can be restored at later point. |
| + */ |
| +class _MemoryRestorePoint { |
|
Paul Berry
2015/02/20 22:00:26
I'm not really comfortable adding this level of tr
danrubel
2015/02/21 03:09:30
How do we simulate revoked and restored access? Th
Paul Berry
2015/02/23 18:54:58
I was imagining that in the 'project removed then
danrubel
2015/02/24 02:29:45
I have moved this functionality into the test itse
|
| + final Map<String, _MemoryResource> _pathToResource = |
| + new HashMap<String, _MemoryResource>(); |
| + final Map<String, String> _pathToContent = new HashMap<String, String>(); |
| + final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); |
| + |
| + _MemoryRestorePoint(MemoryResourceProvider provider) { |
| + _pathToResource.addAll(provider._pathToResource); |
| + _pathToContent.addAll(provider._pathToContent); |
| + _pathToTimestamp.addAll(provider._pathToTimestamp); |
| + } |
| + |
| + void restore(MemoryResourceProvider provider) { |
| + provider._pathToResource.addAll(_pathToResource); |
| + provider._pathToContent.addAll(_pathToContent); |
| + provider._pathToTimestamp.addAll(_pathToTimestamp); |
| + } |
| +} |
| + |
| + |
| +/** |
| * An in-memory implementation of [File] which acts like a symbolic link to a |
| * non-existent file. |
| */ |