| 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' show TypeProvider; | 9 import 'package:analyzer/src/generated/resolver.dart'; |
| 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 createResynthesizer(); | 30 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; |
| 31 context.typeProvider = resynthesizer.typeProvider; | 31 createResynthesizer(sdkContext, sdkContext.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; |
| 124 | 125 |
| 125 ResynthesizerResultProvider(this.context, this._dataStore); | 126 ResynthesizerResultProvider(this.context, this._dataStore); |
| 126 | 127 |
| 127 SummaryResynthesizer get resynthesizer => _resynthesizer; | 128 SummaryResynthesizer get resynthesizer => _resynthesizer; |
| 128 | 129 |
| 129 /** | 130 /** |
| 130 * Add a new [bundle] to the resynthesizer. | 131 * Add a new [bundle] to the resynthesizer. |
| 131 */ | 132 */ |
| 132 void addBundle(String path, PackageBundle bundle) { | 133 void addBundle(String path, PackageBundle bundle) { |
| 133 _dataStore.addBundle(path, bundle); | 134 _dataStore.addBundle(path, bundle); |
| 134 } | 135 } |
| 135 | 136 |
| 136 @override | 137 @override |
| 137 bool compute(CacheEntry entry, ResultDescriptor result) { | 138 bool compute(CacheEntry entry, ResultDescriptor result) { |
| 138 AnalysisTarget target = entry.target; | 139 if (_sdkProvider != null && _sdkProvider.compute(entry, result)) { |
| 139 | |
| 140 if (result == TYPE_PROVIDER) { | |
| 141 entry.setValue(result as ResultDescriptor<TypeProvider>, | |
| 142 _resynthesizer.typeProvider, TargetedResult.EMPTY_LIST); | |
| 143 return true; | 140 return true; |
| 144 } | 141 } |
| 142 AnalysisTarget target = entry.target; |
| 145 | 143 |
| 146 // LINE_INFO can be provided using just the UnlinkedUnit. | 144 // LINE_INFO can be provided using just the UnlinkedUnit. |
| 147 if (target is Source && result == LINE_INFO) { | 145 if (target is Source && result == LINE_INFO) { |
| 148 String uriString = target.uri.toString(); | 146 String uriString = target.uri.toString(); |
| 149 UnlinkedUnit unlinkedUnit = _dataStore.unlinkedMap[uriString]; | 147 UnlinkedUnit unlinkedUnit = _dataStore.unlinkedMap[uriString]; |
| 150 if (unlinkedUnit != null) { | 148 if (unlinkedUnit != null) { |
| 151 List<int> lineStarts = unlinkedUnit.lineStarts; | 149 List<int> lineStarts = unlinkedUnit.lineStarts; |
| 152 if (lineStarts.isNotEmpty) { | 150 if (lineStarts.isNotEmpty) { |
| 153 LineInfo lineInfo = new LineInfo(lineStarts); | 151 LineInfo lineInfo = new LineInfo(lineStarts); |
| 154 entry.setValue(result as ResultDescriptor<LineInfo>, lineInfo, | 152 entry.setValue(result as ResultDescriptor<LineInfo>, lineInfo, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 257 } |
| 260 // Unknown target. | 258 // Unknown target. |
| 261 return false; | 259 return false; |
| 262 } | 260 } |
| 263 | 261 |
| 264 /** | 262 /** |
| 265 * Create the [resynthesizer] instance. | 263 * Create the [resynthesizer] instance. |
| 266 * | 264 * |
| 267 * Subclasses must call this method in their constructors. | 265 * Subclasses must call this method in their constructors. |
| 268 */ | 266 */ |
| 269 void createResynthesizer() { | 267 void createResynthesizer( |
| 270 _resynthesizer = new _FileBasedSummaryResynthesizer(context, | 268 InternalAnalysisContext sdkContext, TypeProvider typeProvider) { |
| 271 context.sourceFactory, context.analysisOptions.strongMode, _dataStore); | 269 // Set the type provider to prevent the context from computing it. |
| 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); |
| 272 } | 280 } |
| 273 | 281 |
| 274 /** | 282 /** |
| 275 * Return `true` if this result provider can provide a result for the | 283 * Return `true` if this result provider can provide a result for the |
| 276 * given [source]. The provider must ensure that [addBundle] is invoked for | 284 * given [source]. The provider must ensure that [addBundle] is invoked for |
| 277 * every bundle that would be required to provide results for the [source]. | 285 * every bundle that would be required to provide results for the [source]. |
| 278 */ | 286 */ |
| 279 bool hasResultsForSource(Source source); | 287 bool hasResultsForSource(Source source); |
| 280 } | 288 } |
| 281 | 289 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 addBundle(path, bundle); | 421 addBundle(path, bundle); |
| 414 } | 422 } |
| 415 } | 423 } |
| 416 | 424 |
| 417 /** | 425 /** |
| 418 * A concrete resynthesizer that serves summaries from given file paths. | 426 * A concrete resynthesizer that serves summaries from given file paths. |
| 419 */ | 427 */ |
| 420 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { | 428 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { |
| 421 final SummaryDataStore _dataStore; | 429 final SummaryDataStore _dataStore; |
| 422 | 430 |
| 423 _FileBasedSummaryResynthesizer(AnalysisContext context, | 431 _FileBasedSummaryResynthesizer( |
| 424 SourceFactory sourceFactory, bool strongMode, this._dataStore) | 432 SummaryResynthesizer parent, |
| 425 : super(context, sourceFactory, strongMode); | 433 AnalysisContext context, |
| 434 TypeProvider typeProvider, |
| 435 SourceFactory sourceFactory, |
| 436 bool strongMode, |
| 437 this._dataStore) |
| 438 : super(parent, context, typeProvider, sourceFactory, strongMode); |
| 426 | 439 |
| 427 @override | 440 @override |
| 428 LinkedLibrary getLinkedSummary(String uri) { | 441 LinkedLibrary getLinkedSummary(String uri) { |
| 429 return _dataStore.linkedMap[uri]; | 442 return _dataStore.linkedMap[uri]; |
| 430 } | 443 } |
| 431 | 444 |
| 432 @override | 445 @override |
| 433 UnlinkedUnit getUnlinkedSummary(String uri) { | 446 UnlinkedUnit getUnlinkedSummary(String uri) { |
| 434 return _dataStore.unlinkedMap[uri]; | 447 return _dataStore.unlinkedMap[uri]; |
| 435 } | 448 } |
| 436 | 449 |
| 437 @override | 450 @override |
| 438 bool hasLibrarySummary(String uri) { | 451 bool hasLibrarySummary(String uri) { |
| 439 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; | 452 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; |
| 440 return linkedLibrary != null; | 453 return linkedLibrary != null; |
| 441 } | 454 } |
| 442 } | 455 } |
| OLD | NEW |