| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 @override | 245 @override |
| 246 bool isOrContains(String path) { | 246 bool isOrContains(String path) { |
| 247 return path == this.path; | 247 return path == this.path; |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 /** | 251 /** |
| 252 * An in-memory implementation of [Source]. | 252 * An in-memory implementation of [Source]. |
| 253 */ | 253 */ |
| 254 class _MemoryFileSource extends Source { | 254 class _MemoryFileSource extends Source { |
| 255 final _MemoryFile _file; | 255 /** |
| 256 * Map from encoded URI/filepath pair to a unique integer identifier. This |
| 257 * identifier is used for equality tests and hash codes. |
| 258 * |
| 259 * The URI and filepath are joined into a pair by separating them with an '@' |
| 260 * character. |
| 261 */ |
| 262 static final Map<String, int> _idTable = new HashMap<String, int>(); |
| 263 |
| 264 final _MemoryFile file; |
| 256 | 265 |
| 257 final Uri uri; | 266 final Uri uri; |
| 258 | 267 |
| 259 _MemoryFileSource(this._file, this.uri); | 268 /** |
| 269 * The unique ID associated with this [_MemoryFileSource]. |
| 270 */ |
| 271 final int id; |
| 272 |
| 273 _MemoryFileSource(_MemoryFile file, Uri uri) |
| 274 : uri = uri, |
| 275 file = file, |
| 276 id = _idTable.putIfAbsent('$uri@${file.path}', () => _idTable.length); |
| 260 | 277 |
| 261 @override | 278 @override |
| 262 TimestampedData<String> get contents { | 279 TimestampedData<String> get contents { |
| 263 return new TimestampedData<String>(modificationStamp, _file._content); | 280 return new TimestampedData<String>(modificationStamp, file._content); |
| 264 } | 281 } |
| 265 | 282 |
| 266 @override | 283 @override |
| 267 String get encoding { | 284 String get encoding { |
| 268 return uri.toString(); | 285 return uri.toString(); |
| 269 } | 286 } |
| 270 | 287 |
| 271 @override | 288 @override |
| 272 String get fullName => _file.path; | 289 String get fullName => file.path; |
| 273 | 290 |
| 274 @override | 291 @override |
| 275 int get hashCode => _file.hashCode; | 292 int get hashCode => id; |
| 276 | 293 |
| 277 @override | 294 @override |
| 278 bool get isInSystemLibrary => uriKind == UriKind.DART_URI; | 295 bool get isInSystemLibrary => uriKind == UriKind.DART_URI; |
| 279 | 296 |
| 280 @override | 297 @override |
| 281 int get modificationStamp { | 298 int get modificationStamp { |
| 282 try { | 299 try { |
| 283 return _file.modificationStamp; | 300 return file.modificationStamp; |
| 284 } on FileSystemException catch (e) { | 301 } on FileSystemException catch (e) { |
| 285 return -1; | 302 return -1; |
| 286 } | 303 } |
| 287 } | 304 } |
| 288 | 305 |
| 289 @override | 306 @override |
| 290 String get shortName => _file.shortName; | 307 String get shortName => file.shortName; |
| 291 | 308 |
| 292 @override | 309 @override |
| 293 UriKind get uriKind { | 310 UriKind get uriKind { |
| 294 String scheme = uri.scheme; | 311 String scheme = uri.scheme; |
| 295 if (scheme == PackageUriResolver.PACKAGE_SCHEME) { | 312 if (scheme == PackageUriResolver.PACKAGE_SCHEME) { |
| 296 return UriKind.PACKAGE_URI; | 313 return UriKind.PACKAGE_URI; |
| 297 } else if (scheme == DartUriResolver.DART_SCHEME) { | 314 } else if (scheme == DartUriResolver.DART_SCHEME) { |
| 298 return UriKind.DART_URI; | 315 return UriKind.DART_URI; |
| 299 } else if (scheme == FileUriResolver.FILE_SCHEME) { | 316 } else if (scheme == FileUriResolver.FILE_SCHEME) { |
| 300 return UriKind.FILE_URI; | 317 return UriKind.FILE_URI; |
| 301 } | 318 } |
| 302 return UriKind.FILE_URI; | 319 return UriKind.FILE_URI; |
| 303 } | 320 } |
| 304 | 321 |
| 305 @override | 322 @override |
| 306 bool operator ==(other) { | 323 bool operator ==(other) { |
| 307 if (other is _MemoryFileSource) { | 324 return other is _MemoryFileSource && other.id == id; |
| 308 return other._file == _file; | |
| 309 } | |
| 310 return false; | |
| 311 } | 325 } |
| 312 | 326 |
| 313 @override | 327 @override |
| 314 bool exists() => _file.exists; | 328 bool exists() => file.exists; |
| 315 | 329 |
| 316 @override | 330 @override |
| 317 Uri resolveRelativeUri(Uri relativeUri) { | 331 Uri resolveRelativeUri(Uri relativeUri) { |
| 318 return uri.resolveUri(relativeUri); | 332 return uri.resolveUri(relativeUri); |
| 319 } | 333 } |
| 320 | 334 |
| 321 @override | 335 @override |
| 322 String toString() => _file.toString(); | 336 String toString() => file.toString(); |
| 323 } | 337 } |
| 324 | 338 |
| 325 /** | 339 /** |
| 326 * An in-memory implementation of [Folder]. | 340 * An in-memory implementation of [Folder]. |
| 327 */ | 341 */ |
| 328 class _MemoryFolder extends _MemoryResource implements Folder { | 342 class _MemoryFolder extends _MemoryResource implements Folder { |
| 329 _MemoryFolder(MemoryResourceProvider provider, String path) | 343 _MemoryFolder(MemoryResourceProvider provider, String path) |
| 330 : super(provider, path); | 344 : super(provider, path); |
| 331 | 345 |
| 332 @override | 346 @override |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 bool operator ==(other) { | 444 bool operator ==(other) { |
| 431 if (runtimeType != other.runtimeType) { | 445 if (runtimeType != other.runtimeType) { |
| 432 return false; | 446 return false; |
| 433 } | 447 } |
| 434 return path == other.path; | 448 return path == other.path; |
| 435 } | 449 } |
| 436 | 450 |
| 437 @override | 451 @override |
| 438 String toString() => path; | 452 String toString() => path; |
| 439 } | 453 } |
| OLD | NEW |