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

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

Issue 1355893003: Rewire DDC to use the analyzer task model (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Update pubspec Created 5 years, 2 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/dart/js.js ('k') | lib/src/compiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dev_compiler.src.analysis_context; 5 library dev_compiler.src.analysis_context;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; 8 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
9 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 9 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
10 import 'package:analyzer/src/generated/source.dart' show DartUriResolver; 10 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
11 import 'package:analyzer/src/generated/source_io.dart'; 11 import 'package:analyzer/src/generated/source_io.dart';
12 12
13 import '../strong_mode.dart' show StrongModeOptions; 13 import '../strong_mode.dart' show StrongModeOptions;
14 14
15 import 'checker/resolver.dart'; 15 import 'checker/resolver.dart';
16 import 'dart_sdk.dart'; 16 import 'dart_sdk.dart';
17 import 'multi_package_resolver.dart'; 17 import 'multi_package_resolver.dart';
18 import 'options.dart'; 18 import 'options.dart';
19 19
20 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, 20 /// Creates an [AnalysisContext] with dev_compiler type rules and inference,
21 /// using [createSourceFactory] to set up its [SourceFactory]. 21 /// using [createSourceFactory] to set up its [SourceFactory].
22 AnalysisContext createAnalysisContextWithSources( 22 AnalysisContext createAnalysisContextWithSources(
23 StrongModeOptions strongOptions, SourceResolverOptions srcOptions, 23 StrongModeOptions strongOptions, SourceResolverOptions srcOptions,
24 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { 24 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) {
25 AnalysisEngine.instance.useTaskModel = true;
25 var srcFactory = createSourceFactory(srcOptions, 26 var srcFactory = createSourceFactory(srcOptions,
26 sdkResolver: sdkResolver, fileResolvers: fileResolvers); 27 sdkResolver: sdkResolver, fileResolvers: fileResolvers);
27 return createAnalysisContext(strongOptions)..sourceFactory = srcFactory; 28 return createAnalysisContext(strongOptions)..sourceFactory = srcFactory;
28 } 29 }
29 30
30 /// Creates an analysis context that contains our restricted typing rules. 31 /// Creates an analysis context that contains our restricted typing rules.
31 AnalysisContext createAnalysisContext(StrongModeOptions options) { 32 AnalysisContext createAnalysisContext(StrongModeOptions options) {
32 AnalysisContextImpl res = AnalysisEngine.instance.createAnalysisContext(); 33 var res = AnalysisEngine.instance.createAnalysisContext();
33 enableDevCompilerInference(res, options); 34 res.analysisOptions.strongMode = true;
34 return res; 35 return res;
35 } 36 }
36 37
37 /// Enables dev_compiler inference rules. 38 /// Enables dev_compiler inference rules.
38 // TODO(jmesserly): is there a cleaner way to plug this in? 39 // TODO(jmesserly): is there a cleaner way to plug this in?
39 void enableDevCompilerInference( 40 void enableDevCompilerInference(
40 AnalysisContextImpl context, StrongModeOptions options) { 41 AnalysisContextImpl context, StrongModeOptions options) {
41 context.libraryResolverFactory = (c) => 42 context.libraryResolverFactory = (c) =>
42 new LibraryResolverWithInference(c, options); 43 new LibraryResolverWithInference(c, options);
43 } 44 }
(...skipping 28 matching lines...) Expand all
72 ? new MultiPackageResolver(options.packagePaths) 73 ? new MultiPackageResolver(options.packagePaths)
73 : new PackageUriResolver([new JavaFile(options.packageRoot)]) 74 : new PackageUriResolver([new JavaFile(options.packageRoot)])
74 ]; 75 ];
75 } 76 }
76 77
77 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents. 78 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents.
78 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) => 79 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) =>
79 new MockDartSdk(mockSources, reportMissing: true).resolver; 80 new MockDartSdk(mockSources, reportMissing: true).resolver;
80 81
81 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. 82 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath].
82 DartUriResolver createSdkPathResolver(String sdkPath) => 83 DartUriResolver createSdkPathResolver(String sdkPath) {
83 new DartUriResolver(new DirectoryBasedDartSdk( 84 var sdk = new DirectoryBasedDartSdk(
84 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true)); 85 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true);
86 sdk.context.analysisOptions.strongMode = true;
87 return new DartUriResolver(sdk);
88 }
OLDNEW
« no previous file with comments | « lib/runtime/dart/js.js ('k') | lib/src/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698