Chromium Code Reviews| 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 resource; | 5 library resource; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; | 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 /** | 52 /** |
| 53 * The abstract class [Resource] is an abstraction of file or folder. | 53 * The abstract class [Resource] is an abstraction of file or folder. |
| 54 */ | 54 */ |
| 55 abstract class Resource { | 55 abstract class Resource { |
| 56 /** | 56 /** |
| 57 * Return `true` if this resource exists. | 57 * Return `true` if this resource exists. |
| 58 */ | 58 */ |
| 59 bool get exists; | 59 bool get exists; |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Return the full (long) version of the name that can be displayed to the | 62 * Return the full path to this resource. |
| 63 * user to denote this resource. | |
| 64 */ | 63 */ |
| 65 String get fullName; | 64 String get path; |
| 66 | 65 |
| 67 /** | 66 /** |
| 68 * Return a short version of the name that can be displayed to the user to | 67 * Return a short version of the name that can be displayed to the user to |
| 69 * denote this resource. | 68 * denote this resource. |
| 70 */ | 69 */ |
| 71 String get shortName; | 70 String get shortName; |
| 72 } | 71 } |
| 73 | 72 |
| 74 | 73 |
| 75 /** | 74 /** |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 95 | 94 |
| 96 @override | 95 @override |
| 97 bool operator ==(other) { | 96 bool operator ==(other) { |
| 98 return identical(this, other); | 97 return identical(this, other); |
| 99 } | 98 } |
| 100 | 99 |
| 101 @override | 100 @override |
| 102 bool get exists => _provider._pathToResource.containsKey(_path); | 101 bool get exists => _provider._pathToResource.containsKey(_path); |
| 103 | 102 |
| 104 @override | 103 @override |
| 105 String get fullName => _path; | 104 String get path => _path; |
|
scheglov
2014/05/29 18:19:03
We could just drop this getter now and rename _pat
| |
| 106 | 105 |
| 107 @override | 106 @override |
| 108 get hashCode => _path.hashCode; | 107 get hashCode => _path.hashCode; |
| 109 | 108 |
| 110 @override | 109 @override |
| 111 String get shortName => posix.basename(_path); | 110 String get shortName => posix.basename(_path); |
| 112 | 111 |
| 113 @override | 112 @override |
| 114 String toString() => fullName; | 113 String toString() => path; |
| 115 } | 114 } |
| 116 | 115 |
| 117 | 116 |
| 118 /** | 117 /** |
| 119 * An in-memory implementation of [File]. | 118 * An in-memory implementation of [File]. |
| 120 */ | 119 */ |
| 121 class _MemoryFile extends _MemoryResource implements File { | 120 class _MemoryFile extends _MemoryResource implements File { |
| 122 _MemoryFile(MemoryResourceProvider provider, String path) : | 121 _MemoryFile(MemoryResourceProvider provider, String path) : |
| 123 super(provider, path); | 122 super(provider, path); |
| 124 | 123 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 return false; | 172 return false; |
| 174 } | 173 } |
| 175 | 174 |
| 176 @override | 175 @override |
| 177 TimestampedData<String> get contents { | 176 TimestampedData<String> get contents { |
| 178 return new TimestampedData<String>(modificationStamp, _file._content); | 177 return new TimestampedData<String>(modificationStamp, _file._content); |
| 179 } | 178 } |
| 180 | 179 |
| 181 @override | 180 @override |
| 182 String get encoding { | 181 String get encoding { |
| 183 return '${new String.fromCharCode(uriKind.encoding)}${_file.fullName}'; | 182 return '${new String.fromCharCode(uriKind.encoding)}${_file.path}'; |
| 184 } | 183 } |
| 185 | 184 |
| 186 @override | 185 @override |
| 187 bool exists() => _file.exists; | 186 bool exists() => _file.exists; |
| 188 | 187 |
| 189 @override | 188 @override |
| 190 String get fullName => _file.fullName; | 189 String get fullName => _file.path; |
| 191 | 190 |
| 192 @override | 191 @override |
| 193 int get hashCode => _file.hashCode; | 192 int get hashCode => _file.hashCode; |
| 194 | 193 |
| 195 @override | 194 @override |
| 196 bool get isInSystemLibrary => false; | 195 bool get isInSystemLibrary => false; |
| 197 | 196 |
| 198 @override | 197 @override |
| 199 int get modificationStamp => _file._timestamp; | 198 int get modificationStamp => _file._timestamp; |
| 200 | 199 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 */ | 407 */ |
| 409 abstract class _PhysicalResource implements Resource { | 408 abstract class _PhysicalResource implements Resource { |
| 410 final io.FileSystemEntity _entry; | 409 final io.FileSystemEntity _entry; |
| 411 | 410 |
| 412 _PhysicalResource(this._entry); | 411 _PhysicalResource(this._entry); |
| 413 | 412 |
| 414 @override | 413 @override |
| 415 bool get exists => _entry.existsSync(); | 414 bool get exists => _entry.existsSync(); |
| 416 | 415 |
| 417 @override | 416 @override |
| 418 String get fullName => _entry.absolute.path; | 417 String get path => _entry.absolute.path; |
| 419 | 418 |
| 420 @override | 419 @override |
| 421 get hashCode => _entry.hashCode; | 420 get hashCode => _entry.hashCode; |
| 422 | 421 |
| 423 @override | 422 @override |
| 424 String get shortName => basename(fullName); | 423 String get shortName => basename(path); |
| 425 | 424 |
| 426 @override | 425 @override |
| 427 String toString() => fullName; | 426 String toString() => path; |
| 428 } | 427 } |
| 429 | 428 |
| 430 | 429 |
| 431 /** | 430 /** |
| 432 * A `dart:io` based implementation of [ResourceProvider]. | 431 * A `dart:io` based implementation of [ResourceProvider]. |
| 433 */ | 432 */ |
| 434 class PhysicalResourceProvider implements ResourceProvider { | 433 class PhysicalResourceProvider implements ResourceProvider { |
| 435 static final PhysicalResourceProvider INSTANCE = new PhysicalResourceProvider. _(); | 434 static final PhysicalResourceProvider INSTANCE = new PhysicalResourceProvider. _(); |
| 436 | 435 |
| 437 PhysicalResourceProvider._(); | 436 PhysicalResourceProvider._(); |
| 438 | 437 |
| 439 @override | 438 @override |
| 440 Resource getResource(String path) { | 439 Resource getResource(String path) { |
| 441 if (io.FileSystemEntity.isDirectorySync(path)) { | 440 if (io.FileSystemEntity.isDirectorySync(path)) { |
| 442 io.Directory directory = new io.Directory(path); | 441 io.Directory directory = new io.Directory(path); |
| 443 return new _PhysicalFolder(directory); | 442 return new _PhysicalFolder(directory); |
| 444 } else { | 443 } else { |
| 445 io.File file = new io.File(path); | 444 io.File file = new io.File(path); |
| 446 return new _PhysicalFile(file); | 445 return new _PhysicalFile(file); |
| 447 } | 446 } |
| 448 } | 447 } |
| 449 } | 448 } |
| OLD | NEW |