@@ -8,9 +8,8 @@ import 'package:analyzer/dart/analysis/declared_variables.dart';
8
8
import 'package:analyzer/file_system/file_system.dart' ;
9
9
import 'package:analyzer/src/context/packages.dart' ;
10
10
import 'package:analyzer/src/context/source.dart' ;
11
- import 'package:analyzer/src/dart/analysis/context_builder.dart' ;
12
11
import 'package:analyzer/src/dart/analysis/context_builder2.dart' ;
13
- import 'package:analyzer/src/dart/analysis/context_locator .dart' ;
12
+ import 'package:analyzer/src/dart/analysis/context_locator2 .dart' ;
14
13
import 'package:analyzer/src/dart/analysis/context_root.dart' ;
15
14
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart' ;
16
15
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
@@ -29,12 +28,12 @@ import '../resolution/context_collection_resolution.dart';
29
28
30
29
main () {
31
30
defineReflectiveSuite (() {
32
- defineReflectiveTests (ContextBuilderImplTest );
31
+ defineReflectiveTests (ContextBuilderImplTest2 );
33
32
});
34
33
}
35
34
36
35
@reflectiveTest
37
- class ContextBuilderImplTest with ResourceProviderMixin {
36
+ class ContextBuilderImplTest2 with ResourceProviderMixin {
38
37
late final ContextBuilderImpl2 contextBuilder;
39
38
late final ContextRoot contextRoot;
40
39
@@ -64,24 +63,26 @@ class ContextBuilderImplTest with ResourceProviderMixin {
64
63
65
64
void test_analysisOptions_invalid () {
66
65
var projectPath = convertPath ('/home/test' );
67
- newAnalysisOptionsYamlFile (projectPath, ';' );
66
+ var optionsFile = newAnalysisOptionsYamlFile (projectPath, ';' );
68
67
69
68
var analysisContext = _createSingleAnalysisContext (projectPath);
70
- var analysisOptions = analysisContext.analysisOptionsImpl;
69
+ var analysisOptions =
70
+ analysisContext.getAnalysisOptionsImplForFile (optionsFile);
71
71
_expectEqualOptions (analysisOptions, AnalysisOptionsImpl ());
72
72
}
73
73
74
74
void test_analysisOptions_languageOptions () {
75
75
var projectPath = convertPath ('/home/test' );
76
- newAnalysisOptionsYamlFile (
76
+ var optionsFile = newAnalysisOptionsYamlFile (
77
77
projectPath,
78
78
AnalysisOptionsFileConfig (
79
79
strictRawTypes: true ,
80
80
).toContent (),
81
81
);
82
82
83
83
var analysisContext = _createSingleAnalysisContext (projectPath);
84
- var analysisOptions = analysisContext.analysisOptionsImpl;
84
+ var analysisOptions =
85
+ analysisContext.getAnalysisOptionsImplForFile (optionsFile);
85
86
_expectEqualOptions (
86
87
analysisOptions,
87
88
AnalysisOptionsImpl ()..strictRawTypes = true ,
@@ -90,22 +91,23 @@ class ContextBuilderImplTest with ResourceProviderMixin {
90
91
91
92
void test_analysisOptions_sdkVersionConstraint_hasPubspec_hasSdk () {
92
93
var projectPath = convertPath ('/home/test' );
93
- newPubspecYamlFile (projectPath, '''
94
+ var pubspec = newPubspecYamlFile (projectPath, '''
94
95
environment:
95
96
sdk: ^2.1.0
96
97
''' );
97
98
98
99
var analysisContext = _createSingleAnalysisContext (projectPath);
99
- var analysisOptions = analysisContext.analysisOptionsImpl;
100
+ var analysisOptions =
101
+ analysisContext.getAnalysisOptionsImplForFile (pubspec);
100
102
expect (analysisOptions.sdkVersionConstraint.toString (), '^2.1.0' );
101
103
}
102
104
103
105
void test_analysisOptions_sdkVersionConstraint_noPubspec () {
104
106
var projectPath = convertPath ('/home/test' );
105
- newFile ('$projectPath /lib/a.dart' , '' );
107
+ var file = newFile ('$projectPath /lib/a.dart' , '' );
106
108
107
109
var analysisContext = _createSingleAnalysisContext (projectPath);
108
- var analysisOptions = analysisContext.driver.analysisOptions ;
110
+ var analysisOptions = analysisContext.getAnalysisOptionsForFile (file) ;
109
111
expect (analysisOptions.sdkVersionConstraint, isNull);
110
112
}
111
113
@@ -207,11 +209,11 @@ environment:
207
209
208
210
/// Return a single expected analysis context at the [path] .
209
211
DriverBasedAnalysisContext _createSingleAnalysisContext (String path) {
210
- var roots = ContextLocatorImpl (
212
+ var roots = ContextLocatorImpl2 (
211
213
resourceProvider: resourceProvider,
212
214
).locateRoots (includedPaths: [path]);
213
215
214
- return ContextBuilderImpl (
216
+ return ContextBuilderImpl2 (
215
217
resourceProvider: resourceProvider,
216
218
).createContext (
217
219
contextRoot: roots.single,
@@ -239,11 +241,10 @@ environment:
239
241
}
240
242
241
243
extension on DriverBasedAnalysisContext {
242
- AnalysisOptionsImpl get analysisOptionsImpl {
243
- return driver.analysisOptions as AnalysisOptionsImpl ;
244
- }
245
-
246
244
List <UriResolver > get uriResolvers {
247
245
return (driver.sourceFactory as SourceFactoryImpl ).resolvers;
248
246
}
247
+
248
+ AnalysisOptionsImpl getAnalysisOptionsImplForFile (File file) =>
249
+ getAnalysisOptionsForFile (file) as AnalysisOptionsImpl ;
249
250
}
0 commit comments