| 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 | 9 |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 // Return a NonExistingSource instance. | 81 // Return a NonExistingSource instance. |
| 82 // This helps provide more meaningful error messages to users | 82 // This helps provide more meaningful error messages to users |
| 83 // (a missing file error, as opposed to an invalid URI error). | 83 // (a missing file error, as opposed to an invalid URI error). |
| 84 return new NonExistingSource(uri.toString(), UriKind.PACKAGE_URI); | 84 return new NonExistingSource(uri.toString(), UriKind.PACKAGE_URI); |
| 85 } | 85 } |
| 86 | 86 |
| 87 @override |
| 88 Uri restoreAbsolute(Source source) { |
| 89 String sourcePath = source.fullName; |
| 90 for (String pkgName in packageMap.keys) { |
| 91 List<Folder> pkgFolders = packageMap[pkgName]; |
| 92 for (Folder pkgFolder in pkgFolders) { |
| 93 String pkgFolderPath = pkgFolder.path; |
| 94 if (sourcePath.startsWith(pkgFolderPath)) { |
| 95 String relPath = sourcePath.substring(pkgFolderPath.length); |
| 96 return new Uri(path: '${PACKAGE_SCHEME}:$pkgName$relPath'); |
| 97 } |
| 98 } |
| 99 } |
| 100 return null; |
| 101 } |
| 102 |
| 87 /** | 103 /** |
| 88 * Returns `true` if [uri] is a `package` URI. | 104 * Returns `true` if [uri] is a `package` URI. |
| 89 */ | 105 */ |
| 90 static bool isPackageUri(Uri uri) { | 106 static bool isPackageUri(Uri uri) { |
| 91 return uri.scheme == PACKAGE_SCHEME; | 107 return uri.scheme == PACKAGE_SCHEME; |
| 92 } | 108 } |
| 93 } | 109 } |
| OLD | NEW |