| 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 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 @override | 44 @override |
| 45 Source resolveAbsolute(Uri uri) { | 45 Source resolveAbsolute(Uri uri) { |
| 46 if (!isPackageUri(uri)) { | 46 if (!isPackageUri(uri)) { |
| 47 return null; | 47 return null; |
| 48 } | 48 } |
| 49 // Prepare path. | 49 // Prepare path. |
| 50 String path = uri.path; | 50 String path = uri.path; |
| 51 // Prepare path components. | 51 // Prepare path components. |
| 52 String pkgName; | |
| 53 String relPath; | |
| 54 int index = path.indexOf('/'); | 52 int index = path.indexOf('/'); |
| 55 if (index == -1 || index == 0) { | 53 if (index == -1 || index == 0) { |
| 56 return null; | 54 return null; |
| 57 } else { | |
| 58 // <pkgName>/<relPath> | |
| 59 pkgName = path.substring(0, index); | |
| 60 relPath = path.substring(index + 1); | |
| 61 } | 55 } |
| 56 // <pkgName>/<relPath> |
| 57 String pkgName = path.substring(0, index); |
| 58 String relPath = path.substring(index + 1); |
| 62 // Try to find an existing file. | 59 // Try to find an existing file. |
| 63 List<Folder> packageDirs = packageMap[pkgName]; | 60 List<Folder> packageDirs = packageMap[pkgName]; |
| 64 if (packageDirs != null) { | 61 if (packageDirs != null) { |
| 65 for (Folder packageDir in packageDirs) { | 62 for (Folder packageDir in packageDirs) { |
| 66 if (packageDir.exists) { | 63 if (packageDir.exists) { |
| 67 Resource result = packageDir.getChild(relPath); | 64 Resource result = packageDir.getChild(relPath); |
| 68 if (result is File && result.exists) { | 65 if (result is File && result.exists) { |
| 69 return result.createSource(uri); | 66 return result.createSource(uri); |
| 70 } | 67 } |
| 71 } | 68 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 93 return null; | 90 return null; |
| 94 } | 91 } |
| 95 | 92 |
| 96 /** | 93 /** |
| 97 * Returns `true` if [uri] is a `package` URI. | 94 * Returns `true` if [uri] is a `package` URI. |
| 98 */ | 95 */ |
| 99 static bool isPackageUri(Uri uri) { | 96 static bool isPackageUri(Uri uri) { |
| 100 return uri.scheme == PACKAGE_SCHEME; | 97 return uri.scheme == PACKAGE_SCHEME; |
| 101 } | 98 } |
| 102 } | 99 } |
| OLD | NEW |