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

Unified Diff: lib/src/analyzer/context.dart

Issue 1928843002: Add explicit-sources flag and create an ExplicitSourceResolver for analyzer. Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: reuse the same flag, make it a boolean to use explicit resolver instead Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/analyzer/context.dart
diff --git a/lib/src/analyzer/context.dart b/lib/src/analyzer/context.dart
index d04a6ae5b63108877a4f2e187c903fa55cf9b60f..5cfd0da12375fac001b7504c54b76d3f3a5d98cc 100644
--- a/lib/src/analyzer/context.dart
+++ b/lib/src/analyzer/context.dart
@@ -12,6 +12,7 @@ import 'package:analyzer/src/generated/source_io.dart'
show
CustomUriResolver,
DartUriResolver,
+ ExplicitSourceResolver,
FileUriResolver,
PackageUriResolver,
SourceFactory,
@@ -29,9 +30,13 @@ import 'multi_package_resolver.dart' show MultiPackageResolver;
/// Options used to set up Source URI resolution in the analysis context.
class AnalyzerOptions {
- /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart"
+ /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart".
final Map<String, String> customUrlMappings;
+ /// Whether the [customUrlMappings] are all inclusive, in which case an error
+ /// should be produced if a lookup fails.
+ final bool allInclusive;
+
/// Package root when resolving 'package:' urls the standard way.
final String packageRoot;
@@ -53,6 +58,7 @@ class AnalyzerOptions {
this.useMockSdk: false,
String dartSdkPath,
this.customUrlMappings: const {},
+ this.allInclusive: false,
this.packageRoot: 'packages/',
this.packagePaths: const []})
: dartSdkPath = dartSdkPath ?? getSdkDir().path;
@@ -62,6 +68,7 @@ class AnalyzerOptions {
useMockSdk = false,
dartSdkPath = args['dart-sdk'] ?? getSdkDir().path,
customUrlMappings = _parseUrlMappings(args['url-mapping']),
+ allInclusive = args['all-inclusive'],
packageRoot = args['package-root'],
packagePaths = args['package-paths']?.split(',') ?? [];
@@ -82,6 +89,10 @@ class AnalyzerOptions {
'library.dart as the source for an import of of "libraryUri".',
allowMultiple: true,
splitCommas: false)
+ ..addFlag('all-inclusive',
+ help: 'whether all `package:` uris are explicitly listed \n'
+ 'via the url-mapping flag.',
+ defaultsTo: false)
..addOption('package-paths',
help: 'use a list of directories to resolve "package:" imports');
}
@@ -148,7 +159,7 @@ SourceFactory _createSourceFactory(AnalyzerOptions options,
List<UriResolver> fileResolvers,
SummaryDataStore summaryData}) {
var resolvers = <UriResolver>[];
- if (options.customUrlMappings.isNotEmpty) {
+ if (!options.allInclusive && options.customUrlMappings.isNotEmpty) {
resolvers.add(new CustomUriResolver(options.customUrlMappings));
}
resolvers.add(sdkResolver);
@@ -162,12 +173,26 @@ SourceFactory _createSourceFactory(AnalyzerOptions options,
}
List<UriResolver> createFileResolvers(AnalyzerOptions options) {
- return [
- new FileUriResolver(),
- options.useMultiPackage
- ? new MultiPackageResolver(options.packagePaths)
- : new PackageUriResolver([new JavaFile(options.packageRoot)])
- ];
+ var resolvers = <UriResolver>[];
+ if (options.allInclusive) {
+ resolvers.add(new ExplicitSourceResolver(
+ _createUriToFileMap(options.customUrlMappings)));
+ }
+ resolvers.add(new FileUriResolver());
+ resolvers.add(options.useMultiPackage
+ ? new MultiPackageResolver(options.packagePaths)
+ : new PackageUriResolver([new JavaFile(options.packageRoot)]));
+ return resolvers;
+}
+
+// TODO(sigmund): delete, this was adapted from analyzer_cli, ideally this
+// should be shared code in package:analyzer.
+Map<Uri, JavaFile> _createUriToFileMap(Map<String, String> mapping) {
+ var uriToFileMap = <Uri, JavaFile>{};
+ mapping.forEach((key, value) {
+ uriToFileMap[Uri.parse(key)] = new JavaFile(value);
+ });
+ return uriToFileMap;
}
/// Creates a [DartUriResolver] that uses a mock 'dart:' library contents.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698