OLD | NEW |
1 import 'dart:io' as io; | 1 import 'dart:io' as io; |
2 | 2 |
3 import 'package:analyzer/dart/element/element.dart'; | 3 import 'package:analyzer/dart/element/element.dart'; |
4 import 'package:analyzer/file_system/file_system.dart'; | 4 import 'package:analyzer/file_system/file_system.dart'; |
5 import 'package:analyzer/src/context/cache.dart'; | 5 import 'package:analyzer/src/context/cache.dart'; |
6 import 'package:analyzer/src/context/context.dart'; | 6 import 'package:analyzer/src/context/context.dart'; |
7 import 'package:analyzer/src/dart/element/element.dart'; | 7 import 'package:analyzer/src/dart/element/element.dart'; |
8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
9 import 'package:analyzer/src/generated/resolver.dart'; | 9 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
11 import 'package:analyzer/src/generated/source_io.dart'; | 11 import 'package:analyzer/src/generated/source_io.dart'; |
12 import 'package:analyzer/src/generated/utilities_dart.dart'; | 12 import 'package:analyzer/src/generated/utilities_dart.dart'; |
13 import 'package:analyzer/src/summary/format.dart'; | 13 import 'package:analyzer/src/summary/format.dart'; |
14 import 'package:analyzer/src/summary/idl.dart'; | 14 import 'package:analyzer/src/summary/idl.dart'; |
15 import 'package:analyzer/src/summary/resynthesize.dart'; | 15 import 'package:analyzer/src/summary/resynthesize.dart'; |
16 import 'package:analyzer/src/task/dart.dart'; | 16 import 'package:analyzer/src/task/dart.dart'; |
17 import 'package:analyzer/src/util/fast_uri.dart'; | 17 import 'package:analyzer/src/util/fast_uri.dart'; |
18 import 'package:analyzer/task/dart.dart'; | 18 import 'package:analyzer/task/dart.dart'; |
19 import 'package:analyzer/task/general.dart'; | 19 import 'package:analyzer/task/general.dart'; |
20 import 'package:analyzer/task/model.dart'; | 20 import 'package:analyzer/task/model.dart'; |
21 import 'package:front_end/src/base/source.dart'; | 21 import 'package:front_end/src/base/source.dart'; |
22 | 22 |
23 /** | 23 /** |
24 * The [ResultProvider] that provides results from input package summaries. | 24 * The [ResultProvider] that provides results from input package summaries. |
25 */ | 25 */ |
26 class InputPackagesResultProvider extends ResynthesizerResultProvider { | 26 class InputPackagesResultProvider extends ResynthesizerResultProvider { |
27 InputPackagesResultProvider( | 27 InputPackagesResultProvider( |
28 InternalAnalysisContext context, SummaryDataStore dataStore) | 28 InternalAnalysisContext context, SummaryDataStore dataStore) |
29 : super(context, dataStore) { | 29 : super(context, dataStore) { |
30 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; | 30 createResynthesizer(); |
31 createResynthesizer(sdkContext, sdkContext.typeProvider); | 31 context.typeProvider = resynthesizer.typeProvider; |
32 } | 32 } |
33 | 33 |
34 @override | 34 @override |
35 bool hasResultsForSource(Source source) { | 35 bool hasResultsForSource(Source source) { |
36 String uriString = source.uri.toString(); | 36 String uriString = source.uri.toString(); |
37 return resynthesizer.hasLibrarySummary(uriString); | 37 return resynthesizer.hasLibrarySummary(uriString); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 /** | 41 /** |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 | 115 |
116 /** | 116 /** |
117 * The [ResultProvider] that provides results using summary resynthesizer. | 117 * The [ResultProvider] that provides results using summary resynthesizer. |
118 */ | 118 */ |
119 abstract class ResynthesizerResultProvider extends ResultProvider { | 119 abstract class ResynthesizerResultProvider extends ResultProvider { |
120 final InternalAnalysisContext context; | 120 final InternalAnalysisContext context; |
121 final SummaryDataStore _dataStore; | 121 final SummaryDataStore _dataStore; |
122 | 122 |
123 _FileBasedSummaryResynthesizer _resynthesizer; | 123 _FileBasedSummaryResynthesizer _resynthesizer; |
124 ResynthesizerResultProvider _sdkProvider; | |
125 | 124 |
126 ResynthesizerResultProvider(this.context, this._dataStore); | 125 ResynthesizerResultProvider(this.context, this._dataStore); |
127 | 126 |
128 SummaryResynthesizer get resynthesizer => _resynthesizer; | 127 SummaryResynthesizer get resynthesizer => _resynthesizer; |
129 | 128 |
130 /** | 129 /** |
131 * Add a new [bundle] to the resynthesizer. | 130 * Add a new [bundle] to the resynthesizer. |
132 */ | 131 */ |
133 void addBundle(String path, PackageBundle bundle) { | 132 void addBundle(String path, PackageBundle bundle) { |
134 _dataStore.addBundle(path, bundle); | 133 _dataStore.addBundle(path, bundle); |
135 } | 134 } |
136 | 135 |
137 @override | 136 @override |
138 bool compute(CacheEntry entry, ResultDescriptor result) { | 137 bool compute(CacheEntry entry, ResultDescriptor result) { |
139 if (_sdkProvider != null && _sdkProvider.compute(entry, result)) { | 138 AnalysisTarget target = entry.target; |
| 139 |
| 140 if (result == TYPE_PROVIDER) { |
| 141 entry.setValue(result as ResultDescriptor<TypeProvider>, |
| 142 _resynthesizer.typeProvider, TargetedResult.EMPTY_LIST); |
140 return true; | 143 return true; |
141 } | 144 } |
142 AnalysisTarget target = entry.target; | |
143 | 145 |
144 // LINE_INFO can be provided using just the UnlinkedUnit. | 146 // LINE_INFO can be provided using just the UnlinkedUnit. |
145 if (target is Source && result == LINE_INFO) { | 147 if (target is Source && result == LINE_INFO) { |
146 String uriString = target.uri.toString(); | 148 String uriString = target.uri.toString(); |
147 UnlinkedUnit unlinkedUnit = _dataStore.unlinkedMap[uriString]; | 149 UnlinkedUnit unlinkedUnit = _dataStore.unlinkedMap[uriString]; |
148 if (unlinkedUnit != null) { | 150 if (unlinkedUnit != null) { |
149 List<int> lineStarts = unlinkedUnit.lineStarts; | 151 List<int> lineStarts = unlinkedUnit.lineStarts; |
150 if (lineStarts.isNotEmpty) { | 152 if (lineStarts.isNotEmpty) { |
151 LineInfo lineInfo = new LineInfo(lineStarts); | 153 LineInfo lineInfo = new LineInfo(lineStarts); |
152 entry.setValue(result as ResultDescriptor<LineInfo>, lineInfo, | 154 entry.setValue(result as ResultDescriptor<LineInfo>, lineInfo, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 259 } |
258 // Unknown target. | 260 // Unknown target. |
259 return false; | 261 return false; |
260 } | 262 } |
261 | 263 |
262 /** | 264 /** |
263 * Create the [resynthesizer] instance. | 265 * Create the [resynthesizer] instance. |
264 * | 266 * |
265 * Subclasses must call this method in their constructors. | 267 * Subclasses must call this method in their constructors. |
266 */ | 268 */ |
267 void createResynthesizer( | 269 void createResynthesizer() { |
268 InternalAnalysisContext sdkContext, TypeProvider typeProvider) { | 270 _resynthesizer = new _FileBasedSummaryResynthesizer(context, |
269 // Set the type provider to prevent the context from computing it. | 271 context.sourceFactory, context.analysisOptions.strongMode, _dataStore); |
270 context.typeProvider = typeProvider; | |
271 // Create a chained resynthesizer. | |
272 _sdkProvider = sdkContext?.resultProvider; | |
273 _resynthesizer = new _FileBasedSummaryResynthesizer( | |
274 _sdkProvider?.resynthesizer, | |
275 context, | |
276 typeProvider, | |
277 context.sourceFactory, | |
278 context.analysisOptions.strongMode, | |
279 _dataStore); | |
280 } | 272 } |
281 | 273 |
282 /** | 274 /** |
283 * Return `true` if this result provider can provide a result for the | 275 * Return `true` if this result provider can provide a result for the |
284 * given [source]. The provider must ensure that [addBundle] is invoked for | 276 * given [source]. The provider must ensure that [addBundle] is invoked for |
285 * every bundle that would be required to provide results for the [source]. | 277 * every bundle that would be required to provide results for the [source]. |
286 */ | 278 */ |
287 bool hasResultsForSource(Source source); | 279 bool hasResultsForSource(Source source); |
288 } | 280 } |
289 | 281 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 addBundle(path, bundle); | 413 addBundle(path, bundle); |
422 } | 414 } |
423 } | 415 } |
424 | 416 |
425 /** | 417 /** |
426 * A concrete resynthesizer that serves summaries from given file paths. | 418 * A concrete resynthesizer that serves summaries from given file paths. |
427 */ | 419 */ |
428 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { | 420 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { |
429 final SummaryDataStore _dataStore; | 421 final SummaryDataStore _dataStore; |
430 | 422 |
431 _FileBasedSummaryResynthesizer( | 423 _FileBasedSummaryResynthesizer(AnalysisContext context, |
432 SummaryResynthesizer parent, | 424 SourceFactory sourceFactory, bool strongMode, this._dataStore) |
433 AnalysisContext context, | 425 : super(null, context, sourceFactory, strongMode); |
434 TypeProvider typeProvider, | |
435 SourceFactory sourceFactory, | |
436 bool strongMode, | |
437 this._dataStore) | |
438 : super(parent, context, typeProvider, sourceFactory, strongMode); | |
439 | 426 |
440 @override | 427 @override |
441 LinkedLibrary getLinkedSummary(String uri) { | 428 LinkedLibrary getLinkedSummary(String uri) { |
442 return _dataStore.linkedMap[uri]; | 429 return _dataStore.linkedMap[uri]; |
443 } | 430 } |
444 | 431 |
445 @override | 432 @override |
446 UnlinkedUnit getUnlinkedSummary(String uri) { | 433 UnlinkedUnit getUnlinkedSummary(String uri) { |
447 return _dataStore.unlinkedMap[uri]; | 434 return _dataStore.unlinkedMap[uri]; |
448 } | 435 } |
449 | 436 |
450 @override | 437 @override |
451 bool hasLibrarySummary(String uri) { | 438 bool hasLibrarySummary(String uri) { |
452 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; | 439 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; |
453 return linkedLibrary != null; | 440 return linkedLibrary != null; |
454 } | 441 } |
455 } | 442 } |
OLD | NEW |