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

Side by Side Diff: lib/src/analysis_context.dart

Issue 1879373004: Implement modular compilation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « lib/runtime/harmony_feature_check.js ('k') | lib/src/analyzer/context.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:analyzer/src/generated/engine.dart';
6 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
7 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
8 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
9 import 'package:analyzer/src/generated/source_io.dart';
10
11 import 'dart_sdk.dart';
12 import 'multi_package_resolver.dart';
13 import 'options.dart';
14
15 /// Creates an [AnalysisContext] with dev_compiler type rules and inference,
16 /// using [createSourceFactory] to set up its [SourceFactory].
17 AnalysisContext createAnalysisContextWithSources(
18 SourceResolverOptions srcOptions,
19 {DartUriResolver sdkResolver,
20 List<UriResolver> fileResolvers}) {
21 AnalysisEngine.instance.processRequiredPlugins();
22 var srcFactory = createSourceFactory(srcOptions,
23 sdkResolver: sdkResolver, fileResolvers: fileResolvers);
24 return createAnalysisContext()..sourceFactory = srcFactory;
25 }
26
27 /// Creates an analysis context that contains our restricted typing rules.
28 AnalysisContext createAnalysisContext() {
29 var res = AnalysisEngine.instance.createAnalysisContext();
30 res.analysisOptions.strongMode = true;
31 return res;
32 }
33
34 /// Creates a SourceFactory configured by the [options].
35 ///
36 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver]
37 /// to entirely override the DartUriResolver.
38 ///
39 /// If supplied, [fileResolvers] will override the default `file:` and
40 /// `package:` URI resolvers.
41 SourceFactory createSourceFactory(SourceResolverOptions options,
42 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) {
43 sdkResolver ??= options.useMockSdk
44 ? createMockSdkResolver(mockSdkSources)
45 : createSdkPathResolver(options.dartSdkPath);
46
47 var resolvers = <UriResolver>[];
48 if (options.customUrlMappings.isNotEmpty) {
49 resolvers.add(new CustomUriResolver(options.customUrlMappings));
50 }
51 resolvers.add(sdkResolver);
52 if (fileResolvers == null) fileResolvers = createFileResolvers(options);
53 resolvers.addAll(fileResolvers);
54 return new SourceFactory(resolvers);
55 }
56
57 List<UriResolver> createFileResolvers(SourceResolverOptions options) {
58 return [
59 new FileUriResolver(),
60 options.useMultiPackage
61 ? new MultiPackageResolver(options.packagePaths)
62 : new PackageUriResolver([new JavaFile(options.packageRoot)])
63 ];
64 }
65
66 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents.
67 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) =>
68 new MockDartSdk(mockSources, reportMissing: true).resolver;
69
70 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath].
71 DartUriResolver createSdkPathResolver(String sdkPath) {
72 var sdk = new DirectoryBasedDartSdk(
73 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true);
74 sdk.context.analysisOptions.strongMode = true;
75 return new DartUriResolver(sdk);
76 }
OLDNEW
« no previous file with comments | « lib/runtime/harmony_feature_check.js ('k') | lib/src/analyzer/context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698