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 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 import 'package:path/path.dart' as pathos; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 Resource result = packageDir.getChild(relPath); | 64 Resource result = packageDir.getChild(relPath); |
65 if (result is File && result.exists) { | 65 if (result is File && result.exists) { |
66 return result.createSource(uri); | 66 return result.createSource(uri); |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 // Return a NonExistingSource instance. | 71 // Return a NonExistingSource instance. |
72 // This helps provide more meaningful error messages to users | 72 // This helps provide more meaningful error messages to users |
73 // (a missing file error, as opposed to an invalid URI error). | 73 // (a missing file error, as opposed to an invalid URI error). |
74 return new NonExistingSource(uri.toString(), UriKind.PACKAGE_URI); | 74 String fullPath = packageDirs != null && packageDirs.isNotEmpty |
| 75 ? packageDirs.first.canonicalizePath(relPath) |
| 76 : relPath; |
| 77 return new NonExistingSource(fullPath, uri, UriKind.PACKAGE_URI); |
75 } | 78 } |
76 | 79 |
77 @override | 80 @override |
78 Uri restoreAbsolute(Source source) { | 81 Uri restoreAbsolute(Source source) { |
79 String sourcePath = source.fullName; | 82 String sourcePath = source.fullName; |
80 Uri bestMatch; | 83 Uri bestMatch; |
81 int bestMatchLength = -1; | 84 int bestMatchLength = -1; |
82 pathos.Context pathContext = resourceProvider.pathContext; | 85 pathos.Context pathContext = resourceProvider.pathContext; |
83 for (String pkgName in packageMap.keys) { | 86 for (String pkgName in packageMap.keys) { |
84 List<Folder> pkgFolders = packageMap[pkgName]; | 87 List<Folder> pkgFolders = packageMap[pkgName]; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return true; | 126 return true; |
124 } | 127 } |
125 | 128 |
126 /** | 129 /** |
127 * Returns `true` if [uri] is a `package` URI. | 130 * Returns `true` if [uri] is a `package` URI. |
128 */ | 131 */ |
129 static bool isPackageUri(Uri uri) { | 132 static bool isPackageUri(Uri uri) { |
130 return uri.scheme == PACKAGE_SCHEME; | 133 return uri.scheme == PACKAGE_SCHEME; |
131 } | 134 } |
132 } | 135 } |
OLD | NEW |