| Index: pkg/analyzer/lib/source/embedder.dart
|
| diff --git a/pkg/analyzer/lib/source/embedder.dart b/pkg/analyzer/lib/source/embedder.dart
|
| index 5874d4f9873a5f67fc4f0e6d391590c03d063b75..5e111f4bc0a2f465d5dc9e93abc44ce18fbb434b 100644
|
| --- a/pkg/analyzer/lib/source/embedder.dart
|
| +++ b/pkg/analyzer/lib/source/embedder.dart
|
| @@ -16,7 +16,6 @@ import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
|
| import 'package:analyzer/src/generated/sdk.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
| import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
|
| -import 'package:path/path.dart' as pathos;
|
| import 'package:yaml/yaml.dart';
|
|
|
| const String _DART_COLON_PREFIX = 'dart:';
|
| @@ -116,8 +115,8 @@ class EmbedderUriResolver extends DartUriResolver {
|
| /// Construct a [EmbedderUriResolver] from a package map
|
| /// (see [PackageMapProvider]).
|
| EmbedderUriResolver(Map<Folder, YamlMap> embedderYamls)
|
| - : super(new _EmbedderSdk()) {
|
| - (dartSdk as _EmbedderSdk)._resolver = this;
|
| + : super(new EmbedderSdk()) {
|
| + (dartSdk as EmbedderSdk)._resolver = this;
|
| if (embedderYamls == null) {
|
| return;
|
| }
|
| @@ -144,105 +143,25 @@ class EmbedderUriResolver extends DartUriResolver {
|
| // _embedder.yaml file in libDir.
|
| return;
|
| }
|
| - String key = name;
|
| - String value = libDir.canonicalizePath(file);
|
| - _urlMappings[key] = value;
|
| + String libPath = libDir.canonicalizePath(file);
|
| + _urlMappings[name] = libPath;
|
| String shortName = name.substring(_DART_COLON_PREFIX.length);
|
| SdkLibraryImpl library = new SdkLibraryImpl(shortName);
|
| - library.path = value;
|
| - (dartSdk as _EmbedderSdk)._librariesMap.setLibrary(name, library);
|
| + library.path = libPath;
|
| + (dartSdk as EmbedderSdk)._librariesMap.setLibrary(name, library);
|
| }
|
|
|
| /// Number of embedder libraries.
|
| int get length => _urlMappings.length;
|
|
|
| - /// Return the path mapping for [libName] or null if there is none.
|
| - String operator [](String libName) => _urlMappings[libName];
|
| -
|
| - @override
|
| - Source resolveAbsolute(Uri importUri, [Uri actualUri]) {
|
| - String libraryName = _libraryName(importUri);
|
| - String partPath = _partPath(importUri);
|
| - // Lookup library name in mappings.
|
| - String mapping = _urlMappings[libraryName];
|
| - if (mapping == null) {
|
| - // Not found.
|
| - return null;
|
| - }
|
| - // This mapping points to the main entry file of the dart: library.
|
| - Uri libraryEntry = new Uri.file(mapping);
|
| - if (!libraryEntry.isAbsolute) {
|
| - // We expect an absolute path.
|
| - return null;
|
| - }
|
| -
|
| - if (partPath != null) {
|
| - return _resolvePart(libraryEntry, partPath, importUri);
|
| - } else {
|
| - return _resolveEntry(libraryEntry, importUri);
|
| - }
|
| - }
|
| -
|
| @override
|
| Uri restoreAbsolute(Source source) {
|
| - String extensionName = _findExtensionNameFor(source.fullName);
|
| - if (extensionName != null) {
|
| - return Uri.parse(extensionName);
|
| - }
|
| - // TODO(johnmccutchan): Handle restoring parts.
|
| - return null;
|
| - }
|
| -
|
| - /// Return the extension name for [fullName] or `null`.
|
| - String _findExtensionNameFor(String fullName) {
|
| - String result;
|
| - _urlMappings.forEach((extensionName, pathMapping) {
|
| - if (pathMapping == fullName) {
|
| - result = extensionName;
|
| - }
|
| - });
|
| - return result;
|
| - }
|
| -
|
| - /// Return the library name of [importUri].
|
| - String _libraryName(Uri importUri) {
|
| - String uri = importUri.toString();
|
| - int index = uri.indexOf('/');
|
| - if (index >= 0) {
|
| - return uri.substring(0, index);
|
| - }
|
| - return uri;
|
| - }
|
| -
|
| - /// Return the part path of [importUri].
|
| - String _partPath(Uri importUri) {
|
| - String uri = importUri.toString();
|
| - int index = uri.indexOf('/');
|
| - if (index >= 0) {
|
| - return uri.substring(index + 1);
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - /// Resolve an import of an sdk extension.
|
| - Source _resolveEntry(Uri libraryEntry, Uri importUri) {
|
| - // Library entry.
|
| - JavaFile javaFile = new JavaFile.fromUri(libraryEntry);
|
| - return new FileBasedSource(javaFile, importUri);
|
| - }
|
| -
|
| - /// Resolve a 'part' statement inside an sdk extension.
|
| - Source _resolvePart(Uri libraryEntry, String partPath, Uri importUri) {
|
| - // Library part.
|
| - String directory = pathos.dirname(libraryEntry.path);
|
| - Uri partUri = new Uri.file(pathos.join(directory, partPath));
|
| - assert(partUri.isAbsolute);
|
| - JavaFile javaFile = new JavaFile.fromUri(partUri);
|
| - return new FileBasedSource(javaFile, importUri);
|
| + Source sdkSource = dartSdk.fromFileUri(Uri.parse(source.fullName));
|
| + return sdkSource?.uri;
|
| }
|
| }
|
|
|
| -class _EmbedderSdk implements DartSdk {
|
| +class EmbedderSdk implements DartSdk {
|
| // TODO(danrubel) Refactor this with DirectoryBasedDartSdk
|
|
|
| /// The resolver associated with this embedder sdk.
|
| @@ -285,12 +204,11 @@ class _EmbedderSdk implements DartSdk {
|
| Source fromFileUri(Uri uri) {
|
| JavaFile file = new JavaFile.fromUri(uri);
|
| String filePath = file.getAbsolutePath();
|
| - String srcPath = filePath.replaceAll('\\', '/');
|
|
|
| String path;
|
| for (SdkLibrary library in _librariesMap.sdkLibraries) {
|
| String libraryPath = library.path;
|
| - if (srcPath == libraryPath) {
|
| + if (filePath == libraryPath) {
|
| path = '$_DART_COLON_PREFIX${library.shortName}';
|
| break;
|
| }
|
| @@ -303,10 +221,10 @@ class _EmbedderSdk implements DartSdk {
|
| continue;
|
| }
|
| String prefix = libraryPath.substring(0, index + 1);
|
| - if (!srcPath.startsWith(prefix)) {
|
| + if (!filePath.startsWith(prefix)) {
|
| continue;
|
| }
|
| - var relPath = srcPath.substring(prefix.length);
|
| + var relPath = filePath.substring(prefix.length);
|
| path = '$_DART_COLON_PREFIX${library.shortName}/$relPath';
|
| break;
|
| }
|
|
|