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

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

Issue 940313003: Add File.modificationStamp accessor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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;
11 import 'package:analyzer/src/generated/source_io.dart'; 11 import 'package:analyzer/src/generated/source_io.dart';
12 import 'package:path/path.dart'; 12 import 'package:path/path.dart';
13 import 'package:watcher/watcher.dart'; 13 import 'package:watcher/watcher.dart';
14 14
15 import 'file_system.dart'; 15 import 'file_system.dart';
16 16
17 17
18 /** 18 /**
19 * Exception thrown when a memory [Resource] file operation fails.
20 */
21 class MemoryResourceException {
22 final path;
23 final message;
24
25 MemoryResourceException(this.path, this.message);
26
27 @override
28 String toString() {
29 return "MemoryResourceException(path=$path; message=$message)";
30 }
31 }
32
33
34 /**
35 * An in-memory implementation of [ResourceProvider]. 19 * An in-memory implementation of [ResourceProvider].
36 * Use `/` as a path separator. 20 * Use `/` as a path separator.
37 */ 21 */
38 class MemoryResourceProvider implements ResourceProvider { 22 class MemoryResourceProvider implements ResourceProvider {
39 final Map<String, _MemoryResource> _pathToResource = 23 final Map<String, _MemoryResource> _pathToResource =
40 new HashMap<String, _MemoryResource>(); 24 new HashMap<String, _MemoryResource>();
41 final Map<String, String> _pathToContent = new HashMap<String, String>(); 25 final Map<String, String> _pathToContent = new HashMap<String, String>();
42 final Map<String, int> _pathToTimestamp = new HashMap<String, int>(); 26 final Map<String, int> _pathToTimestamp = new HashMap<String, int>();
43 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers = 27 final Map<String, List<StreamController<WatchEvent>>> _pathToWatchers =
44 new HashMap<String, List<StreamController<WatchEvent>>>(); 28 new HashMap<String, List<StreamController<WatchEvent>>>();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 * An in-memory implementation of [File] which acts like a symbolic link to a 136 * An in-memory implementation of [File] which acts like a symbolic link to a
153 * non-existent file. 137 * non-existent file.
154 */ 138 */
155 class _MemoryDummyLink extends _MemoryResource implements File { 139 class _MemoryDummyLink extends _MemoryResource implements File {
156 _MemoryDummyLink(MemoryResourceProvider provider, String path) 140 _MemoryDummyLink(MemoryResourceProvider provider, String path)
157 : super(provider, path); 141 : super(provider, path);
158 142
159 @override 143 @override
160 bool get exists => false; 144 bool get exists => false;
161 145
162 String get _content { 146 int get modificationStamp {
163 throw new MemoryResourceException(path, "File '$path' could not be read"); 147 int stamp = _provider._pathToTimestamp[path];
148 if (stamp == null) {
149 return -1;
Brian Wilkerson 2015/02/23 17:29:53 Should this throw an exception? Is there an OS tha
150 }
151 return stamp;
164 } 152 }
165 153
166 int get _timestamp => _provider._pathToTimestamp[path]; 154 String get _content {
155 throw new FileSystemException(path, 'File could not be read');
156 }
167 157
168 @override 158 @override
169 Source createSource([Uri uri]) { 159 Source createSource([Uri uri]) {
170 throw new MemoryResourceException(path, "File '$path' could not be read"); 160 throw new FileSystemException(path, 'File could not be read');
171 } 161 }
172 162
173 @override 163 @override
174 bool isOrContains(String path) { 164 bool isOrContains(String path) {
175 return path == this.path; 165 return path == this.path;
176 } 166 }
177 } 167 }
178 168
179 169
180 /** 170 /**
181 * An in-memory implementation of [File]. 171 * An in-memory implementation of [File].
182 */ 172 */
183 class _MemoryFile extends _MemoryResource implements File { 173 class _MemoryFile extends _MemoryResource implements File {
184 _MemoryFile(MemoryResourceProvider provider, String path) 174 _MemoryFile(MemoryResourceProvider provider, String path)
185 : super(provider, path); 175 : super(provider, path);
186 176
177 int get modificationStamp {
178 int stamp = _provider._pathToTimestamp[path];
179 if (stamp == null) {
180 throw new FileSystemException(path, 'File does not exist.');
181 }
182 return stamp;
183 }
184
187 String get _content { 185 String get _content {
188 String content = _provider._pathToContent[path]; 186 String content = _provider._pathToContent[path];
189 if (content == null) { 187 if (content == null) {
190 throw new MemoryResourceException(path, "File '$path' does not exist"); 188 throw new FileSystemException(path, "File does not exist");
191 } 189 }
192 return content; 190 return content;
193 } 191 }
194 192
195 int get _timestamp => _provider._pathToTimestamp[path];
196
197 @override 193 @override
198 Source createSource([Uri uri]) { 194 Source createSource([Uri uri]) {
199 if (uri == null) { 195 if (uri == null) {
200 uri = posix.toUri(path); 196 uri = posix.toUri(path);
201 } 197 }
202 return new _MemoryFileSource(this, uri); 198 return new _MemoryFileSource(this, uri);
203 } 199 }
204 200
205 @override 201 @override
206 bool isOrContains(String path) { 202 bool isOrContains(String path) {
(...skipping 25 matching lines...) Expand all
232 @override 228 @override
233 String get fullName => _file.path; 229 String get fullName => _file.path;
234 230
235 @override 231 @override
236 int get hashCode => _file.hashCode; 232 int get hashCode => _file.hashCode;
237 233
238 @override 234 @override
239 bool get isInSystemLibrary => uriKind == UriKind.DART_URI; 235 bool get isInSystemLibrary => uriKind == UriKind.DART_URI;
240 236
241 @override 237 @override
242 int get modificationStamp => _file._timestamp; 238 int get modificationStamp {
239 try {
240 return _file.modificationStamp;
241 } on FileSystemException catch (e) {
Brian Wilkerson 2015/02/23 17:29:53 Why is this exception is being caught?
242 return -1;
243 }
244 }
243 245
244 @override 246 @override
245 String get shortName => _file.shortName; 247 String get shortName => _file.shortName;
246 248
247 @override 249 @override
248 UriKind get uriKind { 250 UriKind get uriKind {
249 String scheme = uri.scheme; 251 String scheme = uri.scheme;
250 if (scheme == PackageUriResolver.PACKAGE_SCHEME) { 252 if (scheme == PackageUriResolver.PACKAGE_SCHEME) {
251 return UriKind.PACKAGE_URI; 253 return UriKind.PACKAGE_URI;
252 } else if (scheme == DartUriResolver.DART_SCHEME) { 254 } else if (scheme == DartUriResolver.DART_SCHEME) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 bool operator ==(other) { 378 bool operator ==(other) {
377 if (runtimeType != other.runtimeType) { 379 if (runtimeType != other.runtimeType) {
378 return false; 380 return false;
379 } 381 }
380 return path == other.path; 382 return path == other.path;
381 } 383 }
382 384
383 @override 385 @override
384 String toString() => path; 386 String toString() => path;
385 } 387 }
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