| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.source.io; | 8 library engine.source.io; |
| 9 | 9 |
| 10 import 'source.dart'; | 10 import 'source.dart'; |
| 11 import 'java_core.dart'; | 11 import 'java_core.dart'; |
| 12 import 'java_io.dart'; | 12 import 'java_io.dart'; |
| 13 import 'utilities_general.dart'; | 13 import 'utilities_general.dart'; |
| 14 import 'engine.dart'; | 14 import 'engine.dart'; |
| 15 export 'source.dart'; | 15 export 'source.dart'; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Instances of interface `LocalSourcePredicate` are used to determine if the gi
ven | 18 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's. |
| 19 * [Source] is "local" in some sense, so can be updated. | |
| 20 */ | 19 */ |
| 21 abstract class LocalSourcePredicate { | 20 class RelativeFileUriResolver extends UriResolver { |
| 22 /** | 21 /** |
| 23 * Instance of [LocalSourcePredicate] that always returns `false`. | 22 * The name of the `file` scheme. |
| 24 */ | 23 */ |
| 25 static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE(); | 24 static String FILE_SCHEME = "file"; |
| 26 | 25 |
| 27 /** | 26 /** |
| 28 * Instance of [LocalSourcePredicate] that always returns `true`. | 27 * Return `true` if the given URI is a `file` URI. |
| 28 * |
| 29 * @param uri the URI being tested |
| 30 * @return `true` if the given URI is a `file` URI |
| 29 */ | 31 */ |
| 30 static final LocalSourcePredicate TRUE = new LocalSourcePredicate_TRUE(); | 32 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * Instance of [LocalSourcePredicate] that returns `true` for all [Source]s | 35 * The directories for the relatvie URI's |
| 34 * except of SDK. | |
| 35 */ | 36 */ |
| 36 static final LocalSourcePredicate NOT_SDK = new LocalSourcePredicate_NOT_SDK()
; | 37 final List<JavaFile> _relativeDirectories; |
| 37 | 38 |
| 38 /** | 39 /** |
| 39 * Determines if the given [Source] is local. | 40 * The root directory for all the source trees |
| 40 * | |
| 41 * @param source the [Source] to analyze | |
| 42 * @return `true` if the given [Source] is local | |
| 43 */ | 41 */ |
| 44 bool isLocal(Source source); | 42 final JavaFile _rootDirectory; |
| 45 } | |
| 46 | 43 |
| 47 class LocalSourcePredicate_FALSE implements LocalSourcePredicate { | 44 /** |
| 45 * Initialize a newly created resolver to resolve `file` URI's relative to the
given root |
| 46 * directory. |
| 47 */ |
| 48 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) : supe
r(); |
| 49 |
| 48 @override | 50 @override |
| 49 bool isLocal(Source source) => false; | 51 Source fromEncoding(UriKind kind, Uri uri) { |
| 50 } | 52 if (kind == UriKind.FILE_URI) { |
| 53 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); |
| 54 } |
| 55 return null; |
| 56 } |
| 51 | 57 |
| 52 class LocalSourcePredicate_TRUE implements LocalSourcePredicate { | |
| 53 @override | 58 @override |
| 54 bool isLocal(Source source) => true; | 59 Source resolveAbsolute(Uri uri) { |
| 55 } | 60 String rootPath = _rootDirectory.toURI().path; |
| 56 | 61 String uriPath = uri.path; |
| 57 class LocalSourcePredicate_NOT_SDK implements LocalSourcePredicate { | 62 if (uriPath != null && uriPath.startsWith(rootPath)) { |
| 58 @override | 63 String filePath = uri.path.substring(rootPath.length); |
| 59 bool isLocal(Source source) => source.uriKind != UriKind.DART_URI; | 64 for (JavaFile dir in _relativeDirectories) { |
| 65 JavaFile file = new JavaFile.relative(dir, filePath); |
| 66 if (file.exists()) { |
| 67 return new FileBasedSource.con2(file, UriKind.FILE_URI); |
| 68 } |
| 69 } |
| 70 } |
| 71 return null; |
| 72 } |
| 60 } | 73 } |
| 61 | 74 |
| 62 /** | 75 /** |
| 63 * Instances of the class `FileBasedSource` implement a source that represents a
file. | 76 * Instances of the class `FileBasedSource` implement a source that represents a
file. |
| 64 */ | 77 */ |
| 65 class FileBasedSource implements Source { | 78 class FileBasedSource implements Source { |
| 66 /** | 79 /** |
| 67 * The file represented by this source. | 80 * The file represented by this source. |
| 68 */ | 81 */ |
| 69 final JavaFile file; | 82 final JavaFile file; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 try { | 119 try { |
| 107 return contentsFromFile; | 120 return contentsFromFile; |
| 108 } finally { | 121 } finally { |
| 109 handle.stop(); | 122 handle.stop(); |
| 110 } | 123 } |
| 111 } | 124 } |
| 112 | 125 |
| 113 @override | 126 @override |
| 114 String get encoding { | 127 String get encoding { |
| 115 if (_encoding == null) { | 128 if (_encoding == null) { |
| 116 _encoding = "${uriKind.encoding}${file.toURI().toString()}"; | 129 _encoding = "${new String.fromCharCode(uriKind.encoding)}${file.toURI().to
String()}"; |
| 117 } | 130 } |
| 118 return _encoding; | 131 return _encoding; |
| 119 } | 132 } |
| 120 | 133 |
| 121 @override | 134 @override |
| 122 String get fullName => file.getAbsolutePath(); | 135 String get fullName => file.getAbsolutePath(); |
| 123 | 136 |
| 124 @override | 137 @override |
| 125 int get modificationStamp => file.lastModified(); | 138 int get modificationStamp => file.lastModified(); |
| 126 | 139 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 * @return the contents of the source paired with the modification stamp of th
e source | 174 * @return the contents of the source paired with the modification stamp of th
e source |
| 162 * @throws Exception if the contents of this source could not be accessed | 175 * @throws Exception if the contents of this source could not be accessed |
| 163 * @see #getContents() | 176 * @see #getContents() |
| 164 */ | 177 */ |
| 165 TimestampedData<String> get contentsFromFile { | 178 TimestampedData<String> get contentsFromFile { |
| 166 return new TimestampedData<String>(file.lastModified(), file.readAsStringSyn
c()); | 179 return new TimestampedData<String>(file.lastModified(), file.readAsStringSyn
c()); |
| 167 } | 180 } |
| 168 } | 181 } |
| 169 | 182 |
| 170 /** | 183 /** |
| 184 * Instances of the class `FileUriResolver` resolve `file` URI's. |
| 185 */ |
| 186 class FileUriResolver extends UriResolver { |
| 187 /** |
| 188 * The name of the `file` scheme. |
| 189 */ |
| 190 static String FILE_SCHEME = "file"; |
| 191 |
| 192 /** |
| 193 * Return `true` if the given URI is a `file` URI. |
| 194 * |
| 195 * @param uri the URI being tested |
| 196 * @return `true` if the given URI is a `file` URI |
| 197 */ |
| 198 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; |
| 199 |
| 200 @override |
| 201 Source fromEncoding(UriKind kind, Uri uri) { |
| 202 if (kind == UriKind.FILE_URI) { |
| 203 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); |
| 204 } |
| 205 return null; |
| 206 } |
| 207 |
| 208 @override |
| 209 Source resolveAbsolute(Uri uri) { |
| 210 if (!isFileUri(uri)) { |
| 211 return null; |
| 212 } |
| 213 return new FileBasedSource.con1(new JavaFile.fromUri(uri)); |
| 214 } |
| 215 } |
| 216 |
| 217 /** |
| 171 * An implementation of an non-existing [Source]. | 218 * An implementation of an non-existing [Source]. |
| 172 */ | 219 */ |
| 173 class NonExistingSource implements Source { | 220 class NonExistingSource implements Source { |
| 174 final String _name; | 221 final String _name; |
| 175 | 222 |
| 176 final UriKind uriKind; | 223 final UriKind uriKind; |
| 177 | 224 |
| 178 NonExistingSource(this._name, this.uriKind); | 225 NonExistingSource(this._name, this.uriKind); |
| 179 | 226 |
| 180 @override | 227 @override |
| (...skipping 21 matching lines...) Expand all Loading... |
| 202 @override | 249 @override |
| 203 bool get isInSystemLibrary => false; | 250 bool get isInSystemLibrary => false; |
| 204 | 251 |
| 205 @override | 252 @override |
| 206 Source resolveRelative(Uri relativeUri) { | 253 Source resolveRelative(Uri relativeUri) { |
| 207 throw new UnsupportedOperationException("${_name}does not exist."); | 254 throw new UnsupportedOperationException("${_name}does not exist."); |
| 208 } | 255 } |
| 209 } | 256 } |
| 210 | 257 |
| 211 /** | 258 /** |
| 212 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's. | 259 * Instances of interface `LocalSourcePredicate` are used to determine if the gi
ven |
| 260 * [Source] is "local" in some sense, so can be updated. |
| 213 */ | 261 */ |
| 214 class RelativeFileUriResolver extends UriResolver { | 262 abstract class LocalSourcePredicate { |
| 215 /** | 263 /** |
| 216 * The name of the `file` scheme. | 264 * Instance of [LocalSourcePredicate] that always returns `false`. |
| 217 */ | 265 */ |
| 218 static String FILE_SCHEME = "file"; | 266 static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE(); |
| 219 | 267 |
| 220 /** | 268 /** |
| 221 * Return `true` if the given URI is a `file` URI. | 269 * Instance of [LocalSourcePredicate] that always returns `true`. |
| 222 * | |
| 223 * @param uri the URI being tested | |
| 224 * @return `true` if the given URI is a `file` URI | |
| 225 */ | 270 */ |
| 226 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; | 271 static final LocalSourcePredicate TRUE = new LocalSourcePredicate_TRUE(); |
| 227 | 272 |
| 228 /** | 273 /** |
| 229 * The directories for the relatvie URI's | 274 * Instance of [LocalSourcePredicate] that returns `true` for all [Source]s |
| 275 * except of SDK. |
| 230 */ | 276 */ |
| 231 final List<JavaFile> _relativeDirectories; | 277 static final LocalSourcePredicate NOT_SDK = new LocalSourcePredicate_NOT_SDK()
; |
| 232 | 278 |
| 233 /** | 279 /** |
| 234 * The root directory for all the source trees | 280 * Determines if the given [Source] is local. |
| 281 * |
| 282 * @param source the [Source] to analyze |
| 283 * @return `true` if the given [Source] is local |
| 235 */ | 284 */ |
| 236 final JavaFile _rootDirectory; | 285 bool isLocal(Source source); |
| 286 } |
| 237 | 287 |
| 238 /** | 288 class LocalSourcePredicate_FALSE implements LocalSourcePredicate { |
| 239 * Initialize a newly created resolver to resolve `file` URI's relative to the
given root | 289 @override |
| 240 * directory. | 290 bool isLocal(Source source) => false; |
| 241 */ | 291 } |
| 242 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) : supe
r(); | |
| 243 | 292 |
| 293 class LocalSourcePredicate_TRUE implements LocalSourcePredicate { |
| 244 @override | 294 @override |
| 245 Source fromEncoding(UriKind kind, Uri uri) { | 295 bool isLocal(Source source) => true; |
| 246 if (kind == UriKind.FILE_URI) { | 296 } |
| 247 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); | |
| 248 } | |
| 249 return null; | |
| 250 } | |
| 251 | 297 |
| 298 class LocalSourcePredicate_NOT_SDK implements LocalSourcePredicate { |
| 252 @override | 299 @override |
| 253 Source resolveAbsolute(Uri uri) { | 300 bool isLocal(Source source) => source.uriKind != UriKind.DART_URI; |
| 254 String rootPath = _rootDirectory.toURI().path; | |
| 255 String uriPath = uri.path; | |
| 256 if (uriPath != null && uriPath.startsWith(rootPath)) { | |
| 257 String filePath = uri.path.substring(rootPath.length); | |
| 258 for (JavaFile dir in _relativeDirectories) { | |
| 259 JavaFile file = new JavaFile.relative(dir, filePath); | |
| 260 if (file.exists()) { | |
| 261 return new FileBasedSource.con2(file, UriKind.FILE_URI); | |
| 262 } | |
| 263 } | |
| 264 } | |
| 265 return null; | |
| 266 } | |
| 267 } | 301 } |
| 268 | 302 |
| 269 /** | 303 /** |
| 270 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co
ntext of | 304 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co
ntext of |
| 271 * an application. | 305 * an application. |
| 272 * | 306 * |
| 273 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory | 307 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory |
| 274 * should be canonicalized, but to preserve relative links within a package, the
remainder of the | 308 * should be canonicalized, but to preserve relative links within a package, the
remainder of the |
| 275 * path from the package directory to the leaf should not. | 309 * path from the package directory to the leaf should not. |
| 276 */ | 310 */ |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 * | 508 * |
| 475 * @return the path (not `null`, not empty) | 509 * @return the path (not `null`, not empty) |
| 476 */ | 510 */ |
| 477 String get path => _path; | 511 String get path => _path; |
| 478 | 512 |
| 479 @override | 513 @override |
| 480 int get hashCode => _path.hashCode; | 514 int get hashCode => _path.hashCode; |
| 481 | 515 |
| 482 @override | 516 @override |
| 483 String toString() => "SourceContainer[${_path}]"; | 517 String toString() => "SourceContainer[${_path}]"; |
| 484 } | |
| 485 | |
| 486 /** | |
| 487 * Instances of the class `FileUriResolver` resolve `file` URI's. | |
| 488 */ | |
| 489 class FileUriResolver extends UriResolver { | |
| 490 /** | |
| 491 * The name of the `file` scheme. | |
| 492 */ | |
| 493 static String FILE_SCHEME = "file"; | |
| 494 | |
| 495 /** | |
| 496 * Return `true` if the given URI is a `file` URI. | |
| 497 * | |
| 498 * @param uri the URI being tested | |
| 499 * @return `true` if the given URI is a `file` URI | |
| 500 */ | |
| 501 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; | |
| 502 | |
| 503 @override | |
| 504 Source fromEncoding(UriKind kind, Uri uri) { | |
| 505 if (kind == UriKind.FILE_URI) { | |
| 506 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); | |
| 507 } | |
| 508 return null; | |
| 509 } | |
| 510 | |
| 511 @override | |
| 512 Source resolveAbsolute(Uri uri) { | |
| 513 if (!isFileUri(uri)) { | |
| 514 return null; | |
| 515 } | |
| 516 return new FileBasedSource.con1(new JavaFile.fromUri(uri)); | |
| 517 } | |
| 518 } | 518 } |
| OLD | NEW |