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

Unified Diff: lib/src/analysis_context.dart

Issue 1235503010: fixes #219, able to compile multiple entry points (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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
Index: lib/src/analysis_context.dart
diff --git a/lib/src/analysis_context.dart b/lib/src/analysis_context.dart
index e323783f9b043992641a04f9346ddc74fa5a2cf1..6dcaaa8d500792217d38d91db3bd7513f647f2bc 100644
--- a/lib/src/analysis_context.dart
+++ b/lib/src/analysis_context.dart
@@ -4,14 +4,11 @@
library dev_compiler.src.analysis_context;
-import 'package:analyzer/file_system/file_system.dart';
-import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
import 'package:analyzer/src/generated/source_io.dart';
-import 'package:path/path.dart' as path;
import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions;
@@ -33,11 +30,18 @@ AnalysisContext createAnalysisContextWithSources(
/// Creates an analysis context that contains our restricted typing rules.
AnalysisContext createAnalysisContext(StrongModeOptions options) {
AnalysisContextImpl res = AnalysisEngine.instance.createAnalysisContext();
- res.libraryResolverFactory =
- (context) => new LibraryResolverWithInference(context, options);
+ enableDevCompilerInference(res, options);
return res;
}
+/// Enables dev_compiler inference rules.
+// TODO(jmesserly): is there a cleaner way to plug this in?
+void enableDevCompilerInference(
+ AnalysisContextImpl context, StrongModeOptions options) {
+ context.libraryResolverFactory =
+ (c) => new LibraryResolverWithInference(c, options);
+}
+
/// Creates a SourceFactory configured by the [options].
///
/// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver]
@@ -46,7 +50,7 @@ AnalysisContext createAnalysisContext(StrongModeOptions options) {
/// If supplied, [fileResolvers] will override the default `file:` and
/// `package:` URI resolvers.
SourceFactory createSourceFactory(SourceResolverOptions options,
- {DartUriResolver sdkResolver, List fileResolvers}) {
+ {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) {
var sdkResolver = options.useMockSdk
? createMockSdkResolver(mockSdkSources)
: createSdkPathResolver(options.dartSdkPath);
@@ -56,19 +60,20 @@ SourceFactory createSourceFactory(SourceResolverOptions options,
resolvers.add(new CustomUriResolver(options.customUrlMappings));
}
resolvers.add(sdkResolver);
- if (options.useImplicitHtml) {
- resolvers.add(_createImplicitEntryResolver(options));
- }
- if (fileResolvers == null) {
- fileResolvers = [new FileUriResolver()];
- fileResolvers.add(options.useMultiPackage
- ? new MultiPackageResolver(options.packagePaths)
- : new PackageUriResolver([new JavaFile(options.packageRoot)]));
- }
+ if (fileResolvers == null) fileResolvers = createFileResolvers(options);
resolvers.addAll(fileResolvers);
return new SourceFactory(resolvers);
}
+List<UriResolver> createFileResolvers(SourceResolverOptions options) {
+ return [
+ new FileUriResolver(),
+ options.useMultiPackage
+ ? new MultiPackageResolver(options.packagePaths)
+ : new PackageUriResolver([new JavaFile(options.packageRoot)])
+ ];
+}
+
/// Creates a [DartUriResolver] that uses a mock 'dart:' library contents.
DartUriResolver createMockSdkResolver(Map<String, String> mockSources) =>
new MockDartSdk(mockSources, reportMissing: true).resolver;
@@ -77,26 +82,3 @@ DartUriResolver createMockSdkResolver(Map<String, String> mockSources) =>
DartUriResolver createSdkPathResolver(String sdkPath) => new DartUriResolver(
new DirectoryBasedDartSdk(
new JavaFile(sdkPath), /*useDart2jsPaths:*/ true));
-
-UriResolver _createImplicitEntryResolver(SourceResolverOptions options) {
- var entry = path.absolute(SourceResolverOptions.implicitHtmlFile);
- var src = path.absolute(options.entryPointFile);
- var provider = new MemoryResourceProvider();
- provider.newFile(
- entry, '<body><script type="application/dart" src="$src"></script>');
- return new ExistingSourceUriResolver(new ResourceUriResolver(provider));
-}
-
-/// A UriResolver that continues to the next one if it fails to find an existing
-/// source file. This is unlike normal URI resolvers, that always return
-/// something, even if it is a non-existing file.
-class ExistingSourceUriResolver implements UriResolver {
- final UriResolver resolver;
- ExistingSourceUriResolver(this.resolver);
-
- Source resolveAbsolute(Uri uri) {
- var src = resolver.resolveAbsolute(uri);
- return src.exists() ? src : null;
- }
- Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source);
-}
« no previous file with comments | « lib/devc.dart ('k') | lib/src/checker/checker.dart » ('j') | lib/src/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698