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

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

Issue 1416863003: Fix PackageUriResolver.restoreAbsolute on Windows (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library engine.source.io; 5 library engine.source.io;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'engine.dart'; 9 import 'engine.dart';
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 canonicalFile, actualUri != null ? actualUri : uri); 460 canonicalFile, actualUri != null ? actualUri : uri);
461 } 461 }
462 } 462 }
463 return new FileBasedSource( 463 return new FileBasedSource(
464 getCanonicalFile(_packagesDirectories[0], pkgName, relPath), 464 getCanonicalFile(_packagesDirectories[0], pkgName, relPath),
465 actualUri != null ? actualUri : uri); 465 actualUri != null ? actualUri : uri);
466 } 466 }
467 467
468 @override 468 @override
469 Uri restoreAbsolute(Source source) { 469 Uri restoreAbsolute(Source source) {
470 String sourcePath = source.fullName; 470 String sourceUri = _toFileUri(source.fullName);
471 for (JavaFile packagesDirectory in _packagesDirectories) { 471 for (JavaFile packagesDirectory in _packagesDirectories) {
472 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); 472 List<JavaFile> pkgFolders = packagesDirectory.listFiles();
473 if (pkgFolders != null) { 473 if (pkgFolders != null) {
474 for (JavaFile pkgFolder in pkgFolders) { 474 for (JavaFile pkgFolder in pkgFolders) {
475 try { 475 try {
476 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); 476 String pkgCanonicalUri = _toFileUri(pkgFolder.getCanonicalPath());
477 if (sourcePath.startsWith(pkgCanonicalPath)) { 477 if (sourceUri.startsWith(pkgCanonicalUri)) {
478 String relPath = sourcePath.substring(pkgCanonicalPath.length); 478 String relPath = sourceUri.substring(pkgCanonicalUri.length);
479 return parseUriWithException( 479 return parseUriWithException(
480 "$PACKAGE_SCHEME:${pkgFolder.getName()}$relPath"); 480 "$PACKAGE_SCHEME:${pkgFolder.getName()}$relPath");
481 } 481 }
482 } catch (e) {} 482 } catch (e) {}
483 } 483 }
484 } 484 }
485 } 485 }
486 return null; 486 return null;
487 } 487 }
488 488
489 /** 489 /**
490 * @return `true` if "file" was found in "packagesDir", and it is part of the "lib" folder 490 * @return `true` if "file" was found in "packagesDir", and it is part of the "lib" folder
491 * of the application that contains in this "packagesDir". 491 * of the application that contains in this "packagesDir".
492 */ 492 */
493 bool _isSelfReference(JavaFile packagesDir, JavaFile file) { 493 bool _isSelfReference(JavaFile packagesDir, JavaFile file) {
494 JavaFile rootDir = packagesDir.getParentFile(); 494 JavaFile rootDir = packagesDir.getParentFile();
495 if (rootDir == null) { 495 if (rootDir == null) {
496 return false; 496 return false;
497 } 497 }
498 String rootPath = rootDir.getAbsolutePath(); 498 String rootPath = rootDir.getAbsolutePath();
499 String filePath = file.getAbsolutePath(); 499 String filePath = file.getAbsolutePath();
500 return filePath.startsWith("$rootPath/lib"); 500 return filePath.startsWith("$rootPath/lib");
501 } 501 }
502 502
503 /** 503 /**
504 * Convert the given file path to a "file:" URI. On Windows, this transforms
505 * backslashes to forward slashes.
506 */
507 String _toFileUri(String filePath) =>
508 JavaFile.pathContext.toUri(filePath).toString();
509
510 /**
504 * Return `true` if the given URI is a `package` URI. 511 * Return `true` if the given URI is a `package` URI.
505 * 512 *
506 * @param uri the URI being tested 513 * @param uri the URI being tested
507 * @return `true` if the given URI is a `package` URI 514 * @return `true` if the given URI is a `package` URI
508 */ 515 */
509 static bool isPackageUri(Uri uri) => PACKAGE_SCHEME == uri.scheme; 516 static bool isPackageUri(Uri uri) => PACKAGE_SCHEME == uri.scheme;
510 } 517 }
511 518
512 /** 519 /**
513 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's. 520 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 559 }
553 560
554 /** 561 /**
555 * Return `true` if the given URI is a `file` URI. 562 * Return `true` if the given URI is a `file` URI.
556 * 563 *
557 * @param uri the URI being tested 564 * @param uri the URI being tested
558 * @return `true` if the given URI is a `file` URI 565 * @return `true` if the given URI is a `file` URI
559 */ 566 */
560 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 567 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
561 } 568 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698