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

Side by Side Diff: pkg/analyzer/lib/source/package_map_resolver.dart

Issue 1070203002: Issue 23133. Fix for restoring 'package:' uris on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/source/package_map_resolver_test.dart » ('j') | 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 source.package_map_resolver; 5 library source.package_map_resolver;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/util/asserts.dart' as asserts; 9 import 'package:analyzer/src/util/asserts.dart' as asserts;
10 import 'package:path/path.dart' as pathos;
10 11
11 /** 12 /**
12 * A [UriResolver] implementation for the `package:` scheme that uses a map of 13 * A [UriResolver] implementation for the `package:` scheme that uses a map of
13 * package names to their directories. 14 * package names to their directories.
14 */ 15 */
15 class PackageMapUriResolver extends UriResolver { 16 class PackageMapUriResolver extends UriResolver {
16 /** 17 /**
17 * The name of the `package` scheme. 18 * The name of the `package` scheme.
18 */ 19 */
19 static const String PACKAGE_SCHEME = "package"; 20 static const String PACKAGE_SCHEME = "package";
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 @override 77 @override
77 Uri restoreAbsolute(Source source) { 78 Uri restoreAbsolute(Source source) {
78 String sourcePath = source.fullName; 79 String sourcePath = source.fullName;
79 Uri bestMatch; 80 Uri bestMatch;
80 int bestMatchLength = -1; 81 int bestMatchLength = -1;
81 for (String pkgName in packageMap.keys) { 82 for (String pkgName in packageMap.keys) {
82 List<Folder> pkgFolders = packageMap[pkgName]; 83 List<Folder> pkgFolders = packageMap[pkgName];
83 for (int i = 0; i < pkgFolders.length; i++) { 84 for (int i = 0; i < pkgFolders.length; i++) {
84 Folder pkgFolder = pkgFolders[i]; 85 Folder pkgFolder = pkgFolders[i];
85 String pkgFolderPath = pkgFolder.path; 86 String pkgFolderPath = pkgFolder.path;
86 // TODO(paulberry): figure out the right thing to do for Windows.
87 if (pkgFolderPath.length > bestMatchLength && 87 if (pkgFolderPath.length > bestMatchLength &&
88 sourcePath.startsWith(pkgFolderPath + '/')) { 88 sourcePath.startsWith(pkgFolderPath + pathos.context.separator)) {
89 String relPath = sourcePath.substring(pkgFolderPath.length + 1); 89 String relPath = sourcePath.substring(pkgFolderPath.length + 1);
90 if (_isReversibleTranslation(pkgFolders, i, relPath)) { 90 if (_isReversibleTranslation(pkgFolders, i, relPath)) {
91 bestMatch = Uri.parse('$PACKAGE_SCHEME:$pkgName/$relPath'); 91 List<String> relPathComponents = pathos.context.split(relPath);
92 String relUriPath = pathos.posix.joinAll(relPathComponents);
93 bestMatch = Uri.parse('$PACKAGE_SCHEME:$pkgName/$relUriPath');
92 bestMatchLength = pkgFolderPath.length; 94 bestMatchLength = pkgFolderPath.length;
93 } 95 }
94 } 96 }
95 } 97 }
96 } 98 }
97 return bestMatch; 99 return bestMatch;
98 } 100 }
99 101
100 /** 102 /**
101 * A translation from file path to package URI has just been found for 103 * A translation from file path to package URI has just been found for
(...skipping 18 matching lines...) Expand all
120 return true; 122 return true;
121 } 123 }
122 124
123 /** 125 /**
124 * Returns `true` if [uri] is a `package` URI. 126 * Returns `true` if [uri] is a `package` URI.
125 */ 127 */
126 static bool isPackageUri(Uri uri) { 128 static bool isPackageUri(Uri uri) {
127 return uri.scheme == PACKAGE_SCHEME; 129 return uri.scheme == PACKAGE_SCHEME;
128 } 130 }
129 } 131 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/source/package_map_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698