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 'dart:collection'; | 10 import 'dart:collection'; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 */ | 134 */ |
135 FileBasedSource.con1(JavaFile file) : this.con2(file.toURI(), file); | 135 FileBasedSource.con1(JavaFile file) : this.con2(file.toURI(), file); |
136 | 136 |
137 /** | 137 /** |
138 * Initialize a newly created source object. | 138 * Initialize a newly created source object. |
139 * | 139 * |
140 * @param file the file represented by this source | 140 * @param file the file represented by this source |
141 * @param uri the URI from which this source was originally derived | 141 * @param uri the URI from which this source was originally derived |
142 */ | 142 */ |
143 FileBasedSource.con2(Uri uri, JavaFile file) | 143 FileBasedSource.con2(Uri uri, JavaFile file) |
144 : uri = uri, file = file, | 144 : uri = uri, |
| 145 file = file, |
145 id = _idTable.putIfAbsent( | 146 id = _idTable.putIfAbsent( |
146 '$uri@${file.getPath()}', | 147 '$uri@${file.getPath()}', () => _idTable.length); |
147 () => _idTable.length); | |
148 | 148 |
149 @override | 149 @override |
150 TimestampedData<String> get contents { | 150 TimestampedData<String> get contents { |
151 return PerformanceStatistics.io.makeCurrentWhile(() { | 151 return PerformanceStatistics.io.makeCurrentWhile(() { |
152 return contentsFromFile; | 152 return contentsFromFile; |
153 }); | 153 }); |
154 } | 154 } |
155 | 155 |
156 /** | 156 /** |
157 * Get the contents and timestamp of the underlying file. | 157 * Get the contents and timestamp of the underlying file. |
158 * | 158 * |
159 * Clients should consider using the the method [AnalysisContext.getContents] | 159 * Clients should consider using the the method [AnalysisContext.getContents] |
160 * because contexts can have local overrides of the content of a source that t
he source is not | 160 * because contexts can have local overrides of the content of a source that t
he source is not |
161 * aware of. | 161 * aware of. |
162 * | 162 * |
163 * @return the contents of the source paired with the modification stamp of th
e source | 163 * @return the contents of the source paired with the modification stamp of th
e source |
164 * @throws Exception if the contents of this source could not be accessed | 164 * @throws Exception if the contents of this source could not be accessed |
165 * See [contents]. | 165 * See [contents]. |
166 */ | 166 */ |
167 TimestampedData<String> get contentsFromFile { | 167 TimestampedData<String> get contentsFromFile { |
168 return new TimestampedData<String>( | 168 return new TimestampedData<String>( |
169 file.lastModified(), | 169 file.lastModified(), fileReadMode(file.readAsStringSync())); |
170 fileReadMode(file.readAsStringSync())); | |
171 } | 170 } |
172 | 171 |
173 @override | 172 @override |
174 String get encoding { | 173 String get encoding { |
175 if (_encoding == null) { | 174 if (_encoding == null) { |
176 _encoding = uri.toString(); | 175 _encoding = uri.toString(); |
177 } | 176 } |
178 return _encoding; | 177 return _encoding; |
179 } | 178 } |
180 | 179 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 if (isOpaque) { | 225 if (isOpaque) { |
227 String scheme = uri.scheme; | 226 String scheme = uri.scheme; |
228 String part = uri.path; | 227 String part = uri.path; |
229 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) { | 228 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) { |
230 part = "$part/$part.dart"; | 229 part = "$part/$part.dart"; |
231 } | 230 } |
232 baseUri = parseUriWithException("$scheme:/$part"); | 231 baseUri = parseUriWithException("$scheme:/$part"); |
233 } | 232 } |
234 Uri result = baseUri.resolveUri(containedUri); | 233 Uri result = baseUri.resolveUri(containedUri); |
235 if (isOpaque) { | 234 if (isOpaque) { |
236 result = | 235 result = parseUriWithException( |
237 parseUriWithException("${result.scheme}:${result.path.substring(1)}"
); | 236 "${result.scheme}:${result.path.substring(1)}"); |
238 } | 237 } |
239 return result; | 238 return result; |
240 } catch (exception, stackTrace) { | 239 } catch (exception, stackTrace) { |
241 throw new AnalysisException( | 240 throw new AnalysisException( |
242 "Could not resolve URI ($containedUri) relative to source ($uri)", | 241 "Could not resolve URI ($containedUri) relative to source ($uri)", |
243 new CaughtException(exception, stackTrace)); | 242 new CaughtException(exception, stackTrace)); |
244 } | 243 } |
245 } | 244 } |
246 | 245 |
247 @override | 246 @override |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 376 |
378 /** | 377 /** |
379 * Answer the canonical file for the specified package. | 378 * Answer the canonical file for the specified package. |
380 * | 379 * |
381 * @param packagesDirectory the "packages" directory (not `null`) | 380 * @param packagesDirectory the "packages" directory (not `null`) |
382 * @param pkgName the package name (not `null`, not empty) | 381 * @param pkgName the package name (not `null`, not empty) |
383 * @param relPath the path relative to the package directory (not `null`, no l
eading slash, | 382 * @param relPath the path relative to the package directory (not `null`, no l
eading slash, |
384 * but may be empty string) | 383 * but may be empty string) |
385 * @return the file (not `null`) | 384 * @return the file (not `null`) |
386 */ | 385 */ |
387 JavaFile getCanonicalFile(JavaFile packagesDirectory, String pkgName, | 386 JavaFile getCanonicalFile( |
388 String relPath) { | 387 JavaFile packagesDirectory, String pkgName, String relPath) { |
389 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName); | 388 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName); |
390 try { | 389 try { |
391 pkgDir = pkgDir.getCanonicalFile(); | 390 pkgDir = pkgDir.getCanonicalFile(); |
392 } on JavaIOException catch (exception, stackTrace) { | 391 } on JavaIOException catch (exception, stackTrace) { |
393 if (!exception.toString().contains("Required key not available")) { | 392 if (!exception.toString().contains("Required key not available")) { |
394 AnalysisEngine.instance.logger.logError( | 393 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir", |
395 "Canonical failed: $pkgDir", | |
396 new CaughtException(exception, stackTrace)); | 394 new CaughtException(exception, stackTrace)); |
397 } else if (_CanLogRequiredKeyIoException) { | 395 } else if (_CanLogRequiredKeyIoException) { |
398 _CanLogRequiredKeyIoException = false; | 396 _CanLogRequiredKeyIoException = false; |
399 AnalysisEngine.instance.logger.logError( | 397 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir", |
400 "Canonical failed: $pkgDir", | |
401 new CaughtException(exception, stackTrace)); | 398 new CaughtException(exception, stackTrace)); |
402 } | 399 } |
403 } | 400 } |
404 return new JavaFile.relative( | 401 return new JavaFile.relative(pkgDir, relPath.replaceAll( |
405 pkgDir, | 402 '/', new String.fromCharCode(JavaFile.separatorChar))); |
406 relPath.replaceAll('/', new String.fromCharCode(JavaFile.separatorChar))
); | |
407 } | 403 } |
408 | 404 |
409 @override | 405 @override |
410 Source resolveAbsolute(Uri uri) { | 406 Source resolveAbsolute(Uri uri) { |
411 if (!isPackageUri(uri)) { | 407 if (!isPackageUri(uri)) { |
412 return null; | 408 return null; |
413 } | 409 } |
414 String path = uri.path; | 410 String path = uri.path; |
415 if (path == null) { | 411 if (path == null) { |
416 path = uri.path; | 412 path = uri.path; |
(...skipping 21 matching lines...) Expand all Loading... |
438 if (resolvedFile.exists()) { | 434 if (resolvedFile.exists()) { |
439 JavaFile canonicalFile = | 435 JavaFile canonicalFile = |
440 getCanonicalFile(packagesDirectory, pkgName, relPath); | 436 getCanonicalFile(packagesDirectory, pkgName, relPath); |
441 if (_isSelfReference(packagesDirectory, canonicalFile)) { | 437 if (_isSelfReference(packagesDirectory, canonicalFile)) { |
442 uri = canonicalFile.toURI(); | 438 uri = canonicalFile.toURI(); |
443 } | 439 } |
444 return new FileBasedSource.con2(uri, canonicalFile); | 440 return new FileBasedSource.con2(uri, canonicalFile); |
445 } | 441 } |
446 } | 442 } |
447 return new FileBasedSource.con2( | 443 return new FileBasedSource.con2( |
448 uri, | 444 uri, getCanonicalFile(_packagesDirectories[0], pkgName, relPath)); |
449 getCanonicalFile(_packagesDirectories[0], pkgName, relPath)); | |
450 } | 445 } |
451 | 446 |
452 @override | 447 @override |
453 Uri restoreAbsolute(Source source) { | 448 Uri restoreAbsolute(Source source) { |
454 String sourcePath = source.fullName; | 449 String sourcePath = source.fullName; |
455 for (JavaFile packagesDirectory in _packagesDirectories) { | 450 for (JavaFile packagesDirectory in _packagesDirectories) { |
456 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); | 451 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); |
457 if (pkgFolders != null) { | 452 if (pkgFolders != null) { |
458 for (JavaFile pkgFolder in pkgFolders) { | 453 for (JavaFile pkgFolder in pkgFolders) { |
459 try { | 454 try { |
460 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); | 455 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); |
461 if (sourcePath.startsWith(pkgCanonicalPath)) { | 456 if (sourcePath.startsWith(pkgCanonicalPath)) { |
462 String relPath = sourcePath.substring(pkgCanonicalPath.length); | 457 String relPath = sourcePath.substring(pkgCanonicalPath.length); |
463 return parseUriWithException( | 458 return parseUriWithException( |
464 "$PACKAGE_SCHEME:${pkgFolder.getName()}$relPath"); | 459 "$PACKAGE_SCHEME:${pkgFolder.getName()}$relPath"); |
465 } | 460 } |
466 } catch (e) { | 461 } catch (e) {} |
467 } | |
468 } | 462 } |
469 } | 463 } |
470 } | 464 } |
471 return null; | 465 return null; |
472 } | 466 } |
473 | 467 |
474 /** | 468 /** |
475 * @return `true` if "file" was found in "packagesDir", and it is part of the
"lib" folder | 469 * @return `true` if "file" was found in "packagesDir", and it is part of the
"lib" folder |
476 * of the application that contains in this "packagesDir". | 470 * of the application that contains in this "packagesDir". |
477 */ | 471 */ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } | 531 } |
538 | 532 |
539 /** | 533 /** |
540 * Return `true` if the given URI is a `file` URI. | 534 * Return `true` if the given URI is a `file` URI. |
541 * | 535 * |
542 * @param uri the URI being tested | 536 * @param uri the URI being tested |
543 * @return `true` if the given URI is a `file` URI | 537 * @return `true` if the given URI is a `file` URI |
544 */ | 538 */ |
545 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; | 539 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; |
546 } | 540 } |
OLD | NEW |