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 | 10 |
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"; |
20 | 21 |
21 /** | 22 /** |
22 * A table mapping package names to the path of the directories containing | 23 * A table mapping package names to the path of the directories containing |
23 * the package. | 24 * the package. |
24 */ | 25 */ |
25 final Map<String, List<Folder>> packageMap; | 26 final Map<String, List<Folder>> packageMap; |
26 | 27 |
27 /** | 28 /** |
28 * The [ResourceProvider] for this resolver. | 29 * The [ResourceProvider] for this resolver. |
29 */ | 30 */ |
30 final ResourceProvider resourceProvider; | 31 final ResourceProvider resourceProvider; |
31 | 32 |
32 /** | 33 /** |
33 * Create a new [PackageMapUriResolver]. | 34 * Create a new [PackageMapUriResolver]. |
34 * | 35 * |
35 * [packageMap] is a table mapping package names to the paths of the | 36 * [packageMap] is a table mapping package names to the paths of the |
36 * directories containing the package | 37 * directories containing the package |
37 */ | 38 */ |
38 PackageMapUriResolver(this.resourceProvider, this.packageMap); | 39 PackageMapUriResolver(this.resourceProvider, this.packageMap) { |
| 40 asserts.notNull(resourceProvider); |
| 41 asserts.notNull(packageMap); |
| 42 } |
39 | 43 |
40 @override | 44 @override |
41 Source resolveAbsolute(Uri uri) { | 45 Source resolveAbsolute(Uri uri) { |
42 if (!isPackageUri(uri)) { | 46 if (!isPackageUri(uri)) { |
43 return null; | 47 return null; |
44 } | 48 } |
45 // Prepare path. | 49 // Prepare path. |
46 String path = uri.path; | 50 String path = uri.path; |
47 // Prepare path components. | 51 // Prepare path components. |
48 String pkgName; | 52 String pkgName; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return null; | 93 return null; |
90 } | 94 } |
91 | 95 |
92 /** | 96 /** |
93 * Returns `true` if [uri] is a `package` URI. | 97 * Returns `true` if [uri] is a `package` URI. |
94 */ | 98 */ |
95 static bool isPackageUri(Uri uri) { | 99 static bool isPackageUri(Uri uri) { |
96 return uri.scheme == PACKAGE_SCHEME; | 100 return uri.scheme == PACKAGE_SCHEME; |
97 } | 101 } |
98 } | 102 } |
OLD | NEW |