Chromium Code Reviews| 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); | |
| 32 } | 31 } |
| 33 | 32 |
| 34 @override | 33 @override |
| 35 bool hasResultsForSource(Source source) { | 34 bool hasResultsForSource(Source source) { |
| 36 String uriString = source.uri.toString(); | 35 String uriString = source.uri.toString(); |
| 37 return resynthesizer.hasLibrarySummary(uriString); | 36 return resynthesizer.hasLibrarySummary(uriString); |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 /** | 40 /** |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 } | 113 } |
| 115 | 114 |
| 116 /** | 115 /** |
| 117 * The [ResultProvider] that provides results using summary resynthesizer. | 116 * The [ResultProvider] that provides results using summary resynthesizer. |
| 118 */ | 117 */ |
| 119 abstract class ResynthesizerResultProvider extends ResultProvider { | 118 abstract class ResynthesizerResultProvider extends ResultProvider { |
| 120 final InternalAnalysisContext context; | 119 final InternalAnalysisContext context; |
| 121 final SummaryDataStore _dataStore; | 120 final SummaryDataStore _dataStore; |
| 122 | 121 |
| 123 _FileBasedSummaryResynthesizer _resynthesizer; | 122 _FileBasedSummaryResynthesizer _resynthesizer; |
| 124 ResynthesizerResultProvider _sdkProvider; | |
| 125 | 123 |
| 126 ResynthesizerResultProvider(this.context, this._dataStore); | 124 ResynthesizerResultProvider(this.context, this._dataStore); |
| 127 | 125 |
| 128 SummaryResynthesizer get resynthesizer => _resynthesizer; | 126 SummaryResynthesizer get resynthesizer => _resynthesizer; |
| 129 | 127 |
| 130 /** | 128 /** |
| 131 * Add a new [bundle] to the resynthesizer. | 129 * Add a new [bundle] to the resynthesizer. |
| 132 */ | 130 */ |
| 133 void addBundle(String path, PackageBundle bundle) { | 131 void addBundle(String path, PackageBundle bundle) { |
| 134 _dataStore.addBundle(path, bundle); | 132 _dataStore.addBundle(path, bundle); |
| 135 } | 133 } |
| 136 | 134 |
| 137 @override | 135 @override |
| 138 bool compute(CacheEntry entry, ResultDescriptor result) { | 136 bool compute(CacheEntry entry, ResultDescriptor result) { |
| 139 if (_sdkProvider != null && _sdkProvider.compute(entry, result)) { | 137 AnalysisTarget target = entry.target; |
| 138 | |
| 139 if (result == TYPE_PROVIDER) { | |
| 140 entry.setValue(result as ResultDescriptor<TypeProvider>, | |
| 141 _resynthesizer.typeProvider, TargetedResult.EMPTY_LIST); | |
| 140 return true; | 142 return true; |
| 141 } | 143 } |
| 142 AnalysisTarget target = entry.target; | |
| 143 | 144 |
| 144 // LINE_INFO can be provided using just the UnlinkedUnit. | 145 // LINE_INFO can be provided using just the UnlinkedUnit. |
| 145 if (target is Source && result == LINE_INFO) { | 146 if (target is Source && result == LINE_INFO) { |
| 146 String uriString = target.uri.toString(); | 147 String uriString = target.uri.toString(); |
| 147 UnlinkedUnit unlinkedUnit = _dataStore.unlinkedMap[uriString]; | 148 UnlinkedUnit unlinkedUnit = _dataStore.unlinkedMap[uriString]; |
| 148 if (unlinkedUnit != null) { | 149 if (unlinkedUnit != null) { |
| 149 List<int> lineStarts = unlinkedUnit.lineStarts; | 150 List<int> lineStarts = unlinkedUnit.lineStarts; |
| 150 if (lineStarts.isNotEmpty) { | 151 if (lineStarts.isNotEmpty) { |
| 151 LineInfo lineInfo = new LineInfo(lineStarts); | 152 LineInfo lineInfo = new LineInfo(lineStarts); |
| 152 entry.setValue(result as ResultDescriptor<LineInfo>, lineInfo, | 153 entry.setValue(result as ResultDescriptor<LineInfo>, lineInfo, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 } | 258 } |
| 258 // Unknown target. | 259 // Unknown target. |
| 259 return false; | 260 return false; |
| 260 } | 261 } |
| 261 | 262 |
| 262 /** | 263 /** |
| 263 * Create the [resynthesizer] instance. | 264 * Create the [resynthesizer] instance. |
| 264 * | 265 * |
| 265 * Subclasses must call this method in their constructors. | 266 * Subclasses must call this method in their constructors. |
| 266 */ | 267 */ |
| 267 void createResynthesizer( | 268 void createResynthesizer() { |
| 268 InternalAnalysisContext sdkContext, TypeProvider typeProvider) { | 269 _resynthesizer = new _FileBasedSummaryResynthesizer(context, |
| 269 // Set the type provider to prevent the context from computing it. | 270 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 } | 271 } |
| 281 | 272 |
| 282 /** | 273 /** |
| 283 * Return `true` if this result provider can provide a result for the | 274 * Return `true` if this result provider can provide a result for the |
| 284 * given [source]. The provider must ensure that [addBundle] is invoked for | 275 * given [source]. The provider must ensure that [addBundle] is invoked for |
| 285 * every bundle that would be required to provide results for the [source]. | 276 * every bundle that would be required to provide results for the [source]. |
| 286 */ | 277 */ |
| 287 bool hasResultsForSource(Source source); | 278 bool hasResultsForSource(Source source); |
| 288 } | 279 } |
| 289 | 280 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 addBundle(path, bundle); | 412 addBundle(path, bundle); |
| 422 } | 413 } |
| 423 } | 414 } |
| 424 | 415 |
| 425 /** | 416 /** |
| 426 * A concrete resynthesizer that serves summaries from given file paths. | 417 * A concrete resynthesizer that serves summaries from given file paths. |
| 427 */ | 418 */ |
| 428 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { | 419 class _FileBasedSummaryResynthesizer extends SummaryResynthesizer { |
| 429 final SummaryDataStore _dataStore; | 420 final SummaryDataStore _dataStore; |
| 430 | 421 |
| 431 _FileBasedSummaryResynthesizer( | 422 _FileBasedSummaryResynthesizer(AnalysisContext context, |
| 432 SummaryResynthesizer parent, | 423 SourceFactory sourceFactory, bool strongMode, this._dataStore) |
| 433 AnalysisContext context, | 424 : super(null, context, sourceFactory, strongMode); |
|
Paul Berry
2017/01/23 22:36:45
It looks like there are no remaining code paths th
scheglov
2017/01/23 22:44:49
Yes, I want to clean this up in the following CL.
| |
| 434 TypeProvider typeProvider, | |
| 435 SourceFactory sourceFactory, | |
| 436 bool strongMode, | |
| 437 this._dataStore) | |
| 438 : super(parent, context, typeProvider, sourceFactory, strongMode); | |
| 439 | 425 |
| 440 @override | 426 @override |
| 441 LinkedLibrary getLinkedSummary(String uri) { | 427 LinkedLibrary getLinkedSummary(String uri) { |
| 442 return _dataStore.linkedMap[uri]; | 428 return _dataStore.linkedMap[uri]; |
| 443 } | 429 } |
| 444 | 430 |
| 445 @override | 431 @override |
| 446 UnlinkedUnit getUnlinkedSummary(String uri) { | 432 UnlinkedUnit getUnlinkedSummary(String uri) { |
| 447 return _dataStore.unlinkedMap[uri]; | 433 return _dataStore.unlinkedMap[uri]; |
| 448 } | 434 } |
| 449 | 435 |
| 450 @override | 436 @override |
| 451 bool hasLibrarySummary(String uri) { | 437 bool hasLibrarySummary(String uri) { |
| 452 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; | 438 LinkedLibrary linkedLibrary = _dataStore.linkedMap[uri]; |
| 453 return linkedLibrary != null; | 439 return linkedLibrary != null; |
| 454 } | 440 } |
| 455 } | 441 } |
| OLD | NEW |