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

Side by Side Diff: pkg/analyzer/lib/src/generated/source_io.dart

Issue 1245263002: Actual URI support for package URI resolution. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
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 // 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 /** 269 /**
270 * Instances of the class `FileUriResolver` resolve `file` URI's. 270 * Instances of the class `FileUriResolver` resolve `file` URI's.
271 */ 271 */
272 class FileUriResolver extends UriResolver { 272 class FileUriResolver extends UriResolver {
273 /** 273 /**
274 * The name of the `file` scheme. 274 * The name of the `file` scheme.
275 */ 275 */
276 static String FILE_SCHEME = "file"; 276 static String FILE_SCHEME = "file";
277 277
278 @override 278 @override
279 Source resolveAbsolute(Uri uri) { 279 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
280 if (!isFileUri(uri)) { 280 if (!isFileUri(uri)) {
281 return null; 281 return null;
282 } 282 }
283 return new FileBasedSource(new JavaFile.fromUri(uri), uri); 283 return new FileBasedSource(new JavaFile.fromUri(uri), actualUri);
Paul Berry 2015/07/21 19:39:27 There's a subtle change in behavior in the case wh
pquitslund 2015/07/21 20:55:10 Good catch!
284 } 284 }
285 285
286 @override 286 @override
287 Uri restoreAbsolute(Source source) { 287 Uri restoreAbsolute(Source source) {
288 if (source is FileBasedSource) { 288 if (source is FileBasedSource) {
289 return new Uri.file(source.fullName); 289 return new Uri.file(source.fullName);
290 } 290 }
291 return null; 291 return null;
292 } 292 }
293 293
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 _CanLogRequiredKeyIoException = false; 418 _CanLogRequiredKeyIoException = false;
419 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir", 419 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir",
420 new CaughtException(exception, stackTrace)); 420 new CaughtException(exception, stackTrace));
421 } 421 }
422 } 422 }
423 return new JavaFile.relative(pkgDir, relPath.replaceAll( 423 return new JavaFile.relative(pkgDir, relPath.replaceAll(
424 '/', new String.fromCharCode(JavaFile.separatorChar))); 424 '/', new String.fromCharCode(JavaFile.separatorChar)));
425 } 425 }
426 426
427 @override 427 @override
428 Source resolveAbsolute(Uri uri) { 428 Source resolveAbsolute(Uri uri, [Uri actualUri]){
429 if (!isPackageUri(uri)) { 429 if (!isPackageUri(uri)) {
430 return null; 430 return null;
431 } 431 }
432 String path = uri.path; 432 String path = uri.path;
433 if (path == null) { 433 if (path == null) {
434 path = uri.path; 434 path = uri.path;
435 if (path == null) { 435 if (path == null) {
436 return null; 436 return null;
437 } 437 }
438 } 438 }
(...skipping 17 matching lines...) Expand all
456 if (resolvedFile.exists()) { 456 if (resolvedFile.exists()) {
457 JavaFile canonicalFile = 457 JavaFile canonicalFile =
458 getCanonicalFile(packagesDirectory, pkgName, relPath); 458 getCanonicalFile(packagesDirectory, pkgName, relPath);
459 if (_isSelfReference(packagesDirectory, canonicalFile)) { 459 if (_isSelfReference(packagesDirectory, canonicalFile)) {
460 uri = canonicalFile.toURI(); 460 uri = canonicalFile.toURI();
461 } 461 }
462 return new FileBasedSource(canonicalFile, uri); 462 return new FileBasedSource(canonicalFile, uri);
463 } 463 }
464 } 464 }
465 return new FileBasedSource( 465 return new FileBasedSource(
466 getCanonicalFile(_packagesDirectories[0], pkgName, relPath), uri); 466 getCanonicalFile(_packagesDirectories[0], pkgName, relPath), actualUri);
Paul Berry 2015/07/21 19:39:27 This has the same problem as above, but it's defin
pquitslund 2015/07/21 20:55:10 Absolutely. Spot on. Thanks!
467 } 467 }
468 468
469 @override 469 @override
470 Uri restoreAbsolute(Source source) { 470 Uri restoreAbsolute(Source source) {
471 String sourcePath = source.fullName; 471 String sourcePath = source.fullName;
472 for (JavaFile packagesDirectory in _packagesDirectories) { 472 for (JavaFile packagesDirectory in _packagesDirectories) {
473 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); 473 List<JavaFile> pkgFolders = packagesDirectory.listFiles();
474 if (pkgFolders != null) { 474 if (pkgFolders != null) {
475 for (JavaFile pkgFolder in pkgFolders) { 475 for (JavaFile pkgFolder in pkgFolders) {
476 try { 476 try {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 final JavaFile _rootDirectory; 530 final JavaFile _rootDirectory;
531 531
532 /** 532 /**
533 * Initialize a newly created resolver to resolve `file` URI's relative to the given root 533 * Initialize a newly created resolver to resolve `file` URI's relative to the given root
534 * directory. 534 * directory.
535 */ 535 */
536 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) 536 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories)
537 : super(); 537 : super();
538 538
539 @override 539 @override
540 Source resolveAbsolute(Uri uri) { 540 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
541 String rootPath = _rootDirectory.toURI().path; 541 String rootPath = _rootDirectory.toURI().path;
542 String uriPath = uri.path; 542 String uriPath = uri.path;
543 if (uriPath != null && uriPath.startsWith(rootPath)) { 543 if (uriPath != null && uriPath.startsWith(rootPath)) {
544 String filePath = uri.path.substring(rootPath.length); 544 String filePath = uri.path.substring(rootPath.length);
545 for (JavaFile dir in _relativeDirectories) { 545 for (JavaFile dir in _relativeDirectories) {
546 JavaFile file = new JavaFile.relative(dir, filePath); 546 JavaFile file = new JavaFile.relative(dir, filePath);
547 if (file.exists()) { 547 if (file.exists()) {
548 return new FileBasedSource(file, uri); 548 return new FileBasedSource(file, actualUri);
Paul Berry 2015/07/21 19:39:27 Similar problem here, although I can't assess the
pquitslund 2015/07/21 20:55:10 Done.
549 } 549 }
550 } 550 }
551 } 551 }
552 return null; 552 return null;
553 } 553 }
554 554
555 /** 555 /**
556 * Return `true` if the given URI is a `file` URI. 556 * Return `true` if the given URI is a `file` URI.
557 * 557 *
558 * @param uri the URI being tested 558 * @param uri the URI being tested
559 * @return `true` if the given URI is a `file` URI 559 * @return `true` if the given URI is a `file` URI
560 */ 560 */
561 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 561 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
562 } 562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698