OLD | NEW |
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; | |
14 | |
15 import 'checker/resolver.dart'; | |
16 import 'dart_sdk.dart'; | 13 import 'dart_sdk.dart'; |
17 import 'multi_package_resolver.dart'; | 14 import 'multi_package_resolver.dart'; |
18 import 'options.dart'; | 15 import 'options.dart'; |
19 | 16 |
20 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, | 17 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, |
21 /// using [createSourceFactory] to set up its [SourceFactory]. | 18 /// using [createSourceFactory] to set up its [SourceFactory]. |
22 AnalysisContext createAnalysisContextWithSources( | 19 AnalysisContext createAnalysisContextWithSources( |
23 StrongModeOptions strongOptions, SourceResolverOptions srcOptions, | 20 SourceResolverOptions srcOptions, |
24 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { | 21 {DartUriResolver sdkResolver, |
| 22 List<UriResolver> fileResolvers}) { |
25 AnalysisEngine.instance.useTaskModel = true; | 23 AnalysisEngine.instance.useTaskModel = true; |
26 var srcFactory = createSourceFactory(srcOptions, | 24 var srcFactory = createSourceFactory(srcOptions, |
27 sdkResolver: sdkResolver, fileResolvers: fileResolvers); | 25 sdkResolver: sdkResolver, fileResolvers: fileResolvers); |
28 return createAnalysisContext(strongOptions)..sourceFactory = srcFactory; | 26 return createAnalysisContext()..sourceFactory = srcFactory; |
29 } | 27 } |
30 | 28 |
31 /// Creates an analysis context that contains our restricted typing rules. | 29 /// Creates an analysis context that contains our restricted typing rules. |
32 AnalysisContext createAnalysisContext(StrongModeOptions options) { | 30 AnalysisContext createAnalysisContext() { |
33 var res = AnalysisEngine.instance.createAnalysisContext(); | 31 var res = AnalysisEngine.instance.createAnalysisContext(); |
34 res.analysisOptions.strongMode = true; | 32 res.analysisOptions.strongMode = true; |
35 return res; | 33 return res; |
36 } | 34 } |
37 | 35 |
38 /// Enables dev_compiler inference rules. | |
39 // TODO(jmesserly): is there a cleaner way to plug this in? | |
40 void enableDevCompilerInference( | |
41 AnalysisContextImpl context, StrongModeOptions options) { | |
42 context.libraryResolverFactory = (c) => | |
43 new LibraryResolverWithInference(c, options); | |
44 } | |
45 | |
46 /// Creates a SourceFactory configured by the [options]. | 36 /// Creates a SourceFactory configured by the [options]. |
47 /// | 37 /// |
48 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] | 38 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] |
49 /// to entirely override the DartUriResolver. | 39 /// to entirely override the DartUriResolver. |
50 /// | 40 /// |
51 /// If supplied, [fileResolvers] will override the default `file:` and | 41 /// If supplied, [fileResolvers] will override the default `file:` and |
52 /// `package:` URI resolvers. | 42 /// `package:` URI resolvers. |
53 SourceFactory createSourceFactory(SourceResolverOptions options, | 43 SourceFactory createSourceFactory(SourceResolverOptions options, |
54 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { | 44 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { |
55 var sdkResolver = options.useMockSdk | 45 var sdkResolver = options.useMockSdk |
(...skipping 23 matching lines...) Expand all Loading... |
79 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) => | 69 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) => |
80 new MockDartSdk(mockSources, reportMissing: true).resolver; | 70 new MockDartSdk(mockSources, reportMissing: true).resolver; |
81 | 71 |
82 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 72 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
83 DartUriResolver createSdkPathResolver(String sdkPath) { | 73 DartUriResolver createSdkPathResolver(String sdkPath) { |
84 var sdk = new DirectoryBasedDartSdk( | 74 var sdk = new DirectoryBasedDartSdk( |
85 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true); | 75 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true); |
86 sdk.context.analysisOptions.strongMode = true; | 76 sdk.context.analysisOptions.strongMode = true; |
87 return new DartUriResolver(sdk); | 77 return new DartUriResolver(sdk); |
88 } | 78 } |
OLD | NEW |