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 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'package:args/args.dart' show ArgParser, ArgResults; | 6 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 7 import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; |
7 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; | 8 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; |
8 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
9 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; | 10 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; |
10 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; | 11 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; |
11 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 12 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 13 import 'package:analyzer/src/generated/source.dart'; |
12 import 'package:analyzer/src/generated/source_io.dart' | 14 import 'package:analyzer/src/generated/source_io.dart' |
13 show | 15 show |
14 CustomUriResolver, | 16 CustomUriResolver, |
15 DartUriResolver, | 17 DartUriResolver, |
16 FileUriResolver, | 18 FileUriResolver, |
17 PackageUriResolver, | 19 PackageUriResolver, |
18 SourceFactory, | 20 SourceFactory, |
19 UriResolver; | 21 UriResolver; |
20 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 22 import 'package:analyzer/src/summary/package_bundle_reader.dart' |
21 show | 23 show |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 mappings[splitMapping[0]] = path.absolute(splitMapping[1]); | 106 mappings[splitMapping[0]] = path.absolute(splitMapping[1]); |
105 } | 107 } |
106 } | 108 } |
107 return mappings; | 109 return mappings; |
108 } | 110 } |
109 } | 111 } |
110 | 112 |
111 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, | 113 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, |
112 /// using [createSourceFactory] to set up its [SourceFactory]. | 114 /// using [createSourceFactory] to set up its [SourceFactory]. |
113 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options, | 115 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options, |
114 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { | 116 {DartUriResolver sdkResolver, |
| 117 List<UriResolver> fileResolvers, |
| 118 ResourceProvider resourceProvider}) { |
115 AnalysisEngine.instance.processRequiredPlugins(); | 119 AnalysisEngine.instance.processRequiredPlugins(); |
116 | 120 |
117 sdkResolver ??= options.useMockSdk | 121 sdkResolver ??= options.useMockSdk |
118 ? createMockSdkResolver(mockSdkSources) | 122 ? createMockSdkResolver(mockSdkSources) |
119 : createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath); | 123 : createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath); |
120 | 124 |
121 // Read the summaries. | 125 // Read the summaries. |
122 SummaryDataStore summaryData; | 126 SummaryDataStore summaryData; |
123 if (options.summaryPaths.isNotEmpty) { | 127 if (options.summaryPaths.isNotEmpty) { |
124 summaryData = new SummaryDataStore(options.summaryPaths); | 128 summaryData = new SummaryDataStore(options.summaryPaths); |
125 } | 129 } |
126 | 130 |
127 var srcFactory = _createSourceFactory(options, | 131 var srcFactory = _createSourceFactory(options, |
128 sdkResolver: sdkResolver, | 132 sdkResolver: sdkResolver, |
129 fileResolvers: fileResolvers, | 133 fileResolvers: fileResolvers, |
130 summaryData: summaryData); | 134 summaryData: summaryData, |
| 135 resourceProvider: resourceProvider); |
131 | 136 |
132 var context = createAnalysisContext(); | 137 var context = createAnalysisContext(); |
133 context.sourceFactory = srcFactory; | 138 context.sourceFactory = srcFactory; |
134 if (summaryData != null) { | 139 if (summaryData != null) { |
135 context.typeProvider = sdkResolver.dartSdk.context.typeProvider; | 140 context.typeProvider = sdkResolver.dartSdk.context.typeProvider; |
136 context.resultProvider = | 141 context.resultProvider = |
137 new InputPackagesResultProvider(context, summaryData); | 142 new InputPackagesResultProvider(context, summaryData); |
138 } | 143 } |
139 return context; | 144 return context; |
140 } | 145 } |
(...skipping 10 matching lines...) Expand all Loading... |
151 /// Creates a SourceFactory configured by the [options]. | 156 /// Creates a SourceFactory configured by the [options]. |
152 /// | 157 /// |
153 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] | 158 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] |
154 /// to entirely override the DartUriResolver. | 159 /// to entirely override the DartUriResolver. |
155 /// | 160 /// |
156 /// If supplied, [fileResolvers] will override the default `file:` and | 161 /// If supplied, [fileResolvers] will override the default `file:` and |
157 /// `package:` URI resolvers. | 162 /// `package:` URI resolvers. |
158 SourceFactory _createSourceFactory(AnalyzerOptions options, | 163 SourceFactory _createSourceFactory(AnalyzerOptions options, |
159 {DartUriResolver sdkResolver, | 164 {DartUriResolver sdkResolver, |
160 List<UriResolver> fileResolvers, | 165 List<UriResolver> fileResolvers, |
161 SummaryDataStore summaryData}) { | 166 SummaryDataStore summaryData, |
| 167 ResourceProvider resourceProvider}) { |
162 var resolvers = <UriResolver>[]; | 168 var resolvers = <UriResolver>[]; |
163 if (options.customUrlMappings.isNotEmpty) { | 169 if (options.customUrlMappings.isNotEmpty) { |
164 resolvers.add(new CustomUriResolver(options.customUrlMappings)); | 170 resolvers.add(new CustomUriResolver(options.customUrlMappings)); |
165 } | 171 } |
166 resolvers.add(sdkResolver); | 172 resolvers.add(sdkResolver); |
167 if (summaryData != null) { | 173 if (summaryData != null) { |
168 resolvers.add(new InSummaryPackageUriResolver(summaryData)); | 174 resolvers.add(new InSummaryPackageUriResolver(summaryData)); |
169 } | 175 } |
170 | 176 |
171 if (fileResolvers == null) fileResolvers = createFileResolvers(options); | 177 if (fileResolvers == null) fileResolvers = createFileResolvers(options); |
172 resolvers.addAll(fileResolvers); | 178 resolvers.addAll(fileResolvers); |
173 return new SourceFactory(resolvers); | 179 return new SourceFactory(resolvers, null, resourceProvider); |
174 } | 180 } |
175 | 181 |
176 List<UriResolver> createFileResolvers(AnalyzerOptions options) { | 182 List<UriResolver> createFileResolvers(AnalyzerOptions options) { |
177 return [ | 183 return [ |
178 new FileUriResolver(), | 184 new FileUriResolver(), |
179 options.useMultiPackage | 185 options.useMultiPackage |
180 ? new MultiPackageResolver(options.packagePaths) | 186 ? new MultiPackageResolver(options.packagePaths) |
181 : new PackageUriResolver([new JavaFile(options.packageRoot)]) | 187 : new PackageUriResolver([new JavaFile(options.packageRoot)]) |
182 ]; | 188 ]; |
183 } | 189 } |
(...skipping 10 matching lines...) Expand all Loading... |
194 return sdk; | 200 return sdk; |
195 } | 201 } |
196 | 202 |
197 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 203 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
198 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { | 204 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { |
199 var sdk = (sdkSummaryPath != null) | 205 var sdk = (sdkSummaryPath != null) |
200 ? new SummaryBasedDartSdk(sdkSummaryPath, true) | 206 ? new SummaryBasedDartSdk(sdkSummaryPath, true) |
201 : _createDirectoryBasedDartSdk(sdkPath); | 207 : _createDirectoryBasedDartSdk(sdkPath); |
202 return new DartUriResolver(sdk); | 208 return new DartUriResolver(sdk); |
203 } | 209 } |
OLD | NEW |