Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: pkg/front_end/lib/src/fasta/translate_uri.dart

Issue 2977703002: Refactorings for TranslateUri and its tests. (Closed)
Patch Set: Revert including TODO into documentation comment. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/target_implementation.dart ('k') | pkg/front_end/test/fasta/testing/suite.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ac5a852781257afa7a99928471bae90485590324 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.
Siggi Cherem (dart-lang) 2017/07/11 21:56:02 Just looking at some other CL made me think that I
scheglov 2017/07/11 23:28:31 I replaced `file` with just "file" to underscore t
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.
+ 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
+ /// `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>>{};
« no previous file with comments | « pkg/front_end/lib/src/fasta/target_implementation.dart ('k') | pkg/front_end/test/fasta/testing/suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698