Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/translate_uri.dart |
| diff --git a/pkg/front_end/lib/src/fasta/translate_uri.dart b/pkg/front_end/lib/src/fasta/translate_uri.dart |
| index 2f0e3b0c1fcb6ec133d079824f11626fe3fbb0da..667f5e0fe2c46c7b9b53c09313f3a2f8ce1f162c 100644 |
| --- a/pkg/front_end/lib/src/fasta/translate_uri.dart |
| +++ b/pkg/front_end/lib/src/fasta/translate_uri.dart |
| @@ -5,33 +5,52 @@ |
| library fasta.translate_uri; |
| import 'dart:async' show Future; |
| - |
| import 'dart:convert' show JSON; |
| import 'package:front_end/file_system.dart' |
| show FileSystem, FileSystemException; |
| - |
| import 'package:package_config/packages_file.dart' as packages_file show parse; |
| import 'deprecated_problems.dart' show deprecated_inputError; |
| +/// Instances of [TranslateUri] translate absolute `dart` and `package` URIs |
| +/// into corresponding `file` URIs. |
| class TranslateUri { |
| - final Map<String, Uri> packages; |
| + /// Mapping from Dart library names (e.g. `math`) to `file` URIs. |
| final Map<String, Uri> dartLibraries; |
| - // TODO(ahe): We probably want this to be `Map<String, Uri>`, that is, just |
| - // one patch library (with parts). |
| - final Map<String, List<Uri>> patches; |
| + /// Mapping from Dart library names to the `file` URIs of patches to apply. |
| + /// TODO(ahe): We probably want this to be `Map<String, Uri>`, that is, just |
|
Siggi Cherem (dart-lang)
2017/07/11 20:38:44
nit: remove one "/" so we keep TODOs as local comm
scheglov
2017/07/11 21:15:30
I did this, but there are reasons to keep TODOs in
|
| + /// one patch library (with parts). |
| + final Map<String, List<Uri>> dartPatches; |
| + |
| + /// Mapping from package names (e.g. `path` or `angular`) to the `file` URIs. |
| + final Map<String, Uri> packages; |
| + |
| + TranslateUri(this.dartLibraries, this.dartPatches, this.packages); |
| - TranslateUri(this.packages, this.dartLibraries, this.patches); |
| + /// Returns true if [uri] is private to the platform libraries (and thus not |
| + /// accessible from user code). |
| + bool isPlatformImplementation(Uri uri) { |
| + if (uri.scheme != "dart") return false; |
| + String path = uri.path; |
| + return dartLibraries[path] == null || path.startsWith("_"); |
| + } |
| + /// If the given [uri] is a `file` or `package` URI, return the corresponding |
|
Siggi Cherem (dart-lang)
2017/07/11 21:41:29
`file` => `dart`
scheglov
2017/07/11 21:53:50
Done.
|
| + /// `file` URI (possibly `null` if there is no corresponding `file` URI); |
| + /// otherwise (e.g. when the [uri] is already a `file` URI) return `null`. |
| + /// This is the URIs only transformation, there is no guarantee that the |
| + /// corresponding file exists. |
| Uri translate(Uri uri) { |
| - if (uri.scheme == "dart") return translateDartUri(uri); |
| - if (uri.scheme == "package") return translatePackageUri(uri); |
| + if (uri.scheme == "dart") return _translateDartUri(uri); |
| + if (uri.scheme == "package") return _translatePackageUri(uri); |
| return null; |
| } |
| - Uri translateDartUri(Uri uri) { |
| + /// Return the file URI that corresponds to the given `dart` URI, or `null` |
| + /// if there is no corresponding Dart library registered. |
| + Uri _translateDartUri(Uri uri) { |
| if (!uri.isScheme('dart')) return null; |
| String path = uri.path; |
| @@ -44,7 +63,10 @@ class TranslateUri { |
| return libraryFileUri?.resolve(relativePath); |
| } |
| - Uri translatePackageUri(Uri uri) { |
| + /// Return the file URI that corresponds to the given `package` URI, or `null` |
| + /// if the `package` [uri] format is invalid, or there is no corresponding |
| + /// package registered. |
| + Uri _translatePackageUri(Uri uri) { |
| int index = uri.path.indexOf("/"); |
| if (index == -1) return null; |
| String name = uri.path.substring(0, index); |
| @@ -54,14 +76,6 @@ class TranslateUri { |
| return root.resolve(path); |
| } |
| - /// Returns true if [uri] is private to the platform libraries (and thus not |
| - /// accessible from user code). |
| - bool isPlatformImplementation(Uri uri) { |
| - if (uri.scheme != "dart") return false; |
| - String path = uri.path; |
| - return dartLibraries[path] == null || path.startsWith("_"); |
| - } |
| - |
| static Future<TranslateUri> parse(FileSystem fileSystem, Uri sdk, |
| {Uri packages}) async { |
| Uri librariesJson = sdk?.resolve("lib/libraries.json"); |
| @@ -84,14 +98,17 @@ class TranslateUri { |
| } on FormatException catch (e) { |
| return deprecated_inputError(packages, e.offset, e.message); |
| } |
| - return new TranslateUri( |
| - parsedPackages, |
| - await computeLibraries(fileSystem, librariesJson), |
| - await computePatches(fileSystem, patches)); |
| + |
| + var dartLibraries = await computeDartLibraries(fileSystem, librariesJson); |
| + return new TranslateUri(dartLibraries, |
| + await computeDartPatches(fileSystem, patches), parsedPackages); |
| } |
| } |
| -Future<Map<String, Uri>> computeLibraries( |
| +/// Read the JSON file with defined SDK libraries from the given [uri] in the |
| +/// [fileSystem] and return the mapping from parsed Dart library names (e.g. |
| +/// `math`) to `file` URIs. |
| +Future<Map<String, Uri>> computeDartLibraries( |
| FileSystem fileSystem, Uri uri) async { |
| if (uri == null) return const <String, Uri>{}; |
| Map<String, String> libraries = JSON |
| @@ -103,7 +120,7 @@ Future<Map<String, Uri>> computeLibraries( |
| return result; |
| } |
| -Future<Map<String, List<Uri>>> computePatches( |
| +Future<Map<String, List<Uri>>> computeDartPatches( |
| FileSystem fileSystem, Uri uri) async { |
| // TODO(ahe): Read patch information. |
| return const <String, List<Uri>>{}; |