Index: pkg/front_end/lib/src/base/uri_resolver.dart |
diff --git a/pkg/front_end/lib/src/base/uri_resolver.dart b/pkg/front_end/lib/src/base/uri_resolver.dart |
index db469f0003df510d13a843e5714d15aa220f65be..0c6a4209743afe02849f32f3ca51c2a0948c90ae 100644 |
--- a/pkg/front_end/lib/src/base/uri_resolver.dart |
+++ b/pkg/front_end/lib/src/base/uri_resolver.dart |
@@ -2,13 +2,15 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-import 'package:path/path.dart' as p; |
- |
-/// The class `UriResolver` implements the rules for resolving URIs to file |
-/// paths. |
-/// |
-/// TODO(paulberry): Is it necessary to support the "http" scheme? |
+/// The class `UriResolver` implements the rules for resolving "dart:" and |
+/// "package:" URIs. |
class UriResolver { |
+ /// The URI scheme used for "package" URIs. |
+ static const PACKAGE_SCHEME = 'package'; |
+ |
+ /// The URI scheme used for "dart" URIs. |
+ static const DART_SCHEME = 'dart'; |
+ |
/// A map from package name to the file URI of the "lib" directory of the |
/// corresponding package. This is equivalent to the format returned by |
/// the "package_config" package's parse() function. |
@@ -18,36 +20,27 @@ class UriResolver { |
/// of the defining compilation unit of the SDK library. |
final Map<String, Uri> sdkLibraries; |
- /// The path context which should be used to convert from file URIs to file |
- /// paths. |
- final p.Context pathContext; |
- |
- /// The URI scheme used for "package" URIs. |
- static const PACKAGE_SCHEME = 'package'; |
+ UriResolver(this.packages, this.sdkLibraries); |
- /// The URI scheme used for "dart" URIs. |
- static const DART_SCHEME = 'dart'; |
- |
- /// The URI scheme used for "file" URIs. |
- static const FILE_SCHEME = 'file'; |
- |
- UriResolver(this.packages, this.sdkLibraries, this.pathContext); |
- |
- /// Converts a URI to a file path. |
+ /// Converts "package:" and "dart:" URIs to the locations of the corresponding |
+ /// files. |
/// |
- /// If the given URI is valid, and of a recognized form, returns the file path |
- /// it corresponds to. Otherwise returns `null`. It is not necessary for the |
- /// URI to be absolute (relative URIs will be converted to relative file |
- /// paths). |
+ /// If the given URI is a "package:" or "dart:" URI, is well formed, and names |
+ /// a package or dart library that is recognized, returns the URI it resolves |
+ /// to. If the given URI is a "package:" or "dart:" URI, and is ill-formed |
+ /// or names a package or dart library that is not recognized, returns `null`. |
/// |
- /// Note that no I/O is performed; the file path that is returned will be |
+ /// If the given URI has any scheme other than "package:" or "dart:", it is |
+ /// returned unchanged. |
+ /// |
+ /// It is not necessary for the URI to be absolute (relative URIs will be |
+ /// passed through unchanged). |
+ /// |
+ /// Note that no I/O is performed; the URI that is returned will be |
/// independent of whether or not any particular file exists on the file |
/// system. |
- String resolve(Uri uri) { |
- Uri fileUri; |
- if (uri.scheme == FILE_SCHEME) { |
- fileUri = uri; |
- } else { |
+ Uri resolve(Uri uri) { |
+ if (uri.scheme == DART_SCHEME || uri.scheme == PACKAGE_SCHEME) { |
var path = uri.path; |
var slashIndex = path.indexOf('/'); |
String prefix; |
@@ -67,9 +60,9 @@ class UriResolver { |
libUri = sdkLibraries[prefix]; |
} |
if (libUri == null) return null; |
- fileUri = libUri.resolve(rest); |
- if (fileUri.scheme != FILE_SCHEME) return null; |
+ return libUri.resolve(rest); |
+ } else { |
+ return uri; |
} |
- return pathContext.fromUri(fileUri); |
} |
} |