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 |
deleted file mode 100644 |
index 74543888c0732d3c30be45ab847a7a7246af8f91..0000000000000000000000000000000000000000 |
--- a/pkg/front_end/lib/src/fasta/translate_uri.dart |
+++ /dev/null |
@@ -1,131 +0,0 @@ |
-// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
-// 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. |
- |
-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 in a [FileSystem]. Translated URIs are |
-/// typically `file:` URIs, but may use a different scheme if the compiler is |
-/// invoked with the `multiRoot` option or in unit tests that use a custom file |
-/// system. |
-class TranslateUri { |
- /// 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). |
- /// 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. `angular`) to the file URIs. |
- final Map<String, Uri> packages; |
- |
- TranslateUri(this.dartLibraries, this.dartPatches, this.packages); |
- |
- /// If the given [uri] is a `dart` 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 in the file system. |
- Uri translate(Uri uri) { |
- if (uri.scheme == "dart") return _translateDartUri(uri); |
- if (uri.scheme == "package") return _translatePackageUri(uri); |
- return null; |
- } |
- |
- /// 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; |
- |
- int index = path.indexOf('/'); |
- if (index == -1) return dartLibraries[path]; |
- |
- String libraryName = path.substring(0, index); |
- String relativePath = path.substring(index + 1); |
- Uri libraryFileUri = dartLibraries[libraryName]; |
- return libraryFileUri?.resolve(relativePath); |
- } |
- |
- /// 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); |
- String path = uri.path.substring(index + 1); |
- Uri root = packages[name]; |
- if (root == null) return null; |
- 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"); |
- |
- // TODO(ahe): Provide a value for this file. |
- Uri patches = null; |
- |
- packages ??= Uri.base.resolve(".packages"); |
- |
- List<int> bytes; |
- try { |
- bytes = await fileSystem.entityForUri(packages).readAsBytes(); |
- } on FileSystemException catch (e) { |
- deprecated_inputError(packages, -1, e.message); |
- } |
- |
- Map<String, Uri> parsedPackages; |
- try { |
- parsedPackages = packages_file.parse(bytes, packages); |
- } on FormatException catch (e) { |
- return deprecated_inputError(packages, e.offset, e.message); |
- } |
- |
- var dartLibraries = await computeDartLibraries(fileSystem, librariesJson); |
- return new TranslateUri(dartLibraries, |
- await computeDartPatches(fileSystem, patches), parsedPackages); |
- } |
-} |
- |
-/// 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 |
- .decode(await fileSystem.entityForUri(uri).readAsString())["libraries"]; |
- Map<String, Uri> result = <String, Uri>{}; |
- libraries.forEach((String name, String path) { |
- result[name] = uri.resolveUri(new Uri.file(path)); |
- }); |
- return result; |
-} |
- |
-Future<Map<String, List<Uri>>> computeDartPatches( |
- FileSystem fileSystem, Uri uri) async { |
- // TODO(ahe): Read patch information. |
- return const <String, List<Uri>>{}; |
-} |