Chromium Code Reviews| Index: pkg/analyzer/lib/src/summary/summary_sdk.dart |
| diff --git a/pkg/analyzer/lib/src/summary/summary_sdk.dart b/pkg/analyzer/lib/src/summary/summary_sdk.dart |
| index da2ca8eee76e335705456147e94407ae3da85282..f112297f9747578bede8b8f9b0b1c184296eb300 100644 |
| --- a/pkg/analyzer/lib/src/summary/summary_sdk.dart |
| +++ b/pkg/analyzer/lib/src/summary/summary_sdk.dart |
| @@ -6,9 +6,115 @@ library analyzer.src.summary.summary_sdk; |
| import 'package:analyzer/dart/element/element.dart'; |
| import 'package:analyzer/dart/element/type.dart'; |
| +import 'package:analyzer/src/context/cache.dart' show CacheEntry; |
| +import 'package:analyzer/src/context/context.dart'; |
| import 'package:analyzer/src/dart/element/type.dart'; |
| import 'package:analyzer/src/generated/constant.dart'; |
| import 'package:analyzer/src/generated/resolver.dart'; |
| +import 'package:analyzer/src/generated/source.dart' show Source, SourceKind; |
| +import 'package:analyzer/src/summary/format.dart'; |
| +import 'package:analyzer/src/summary/resynthesize.dart'; |
| +import 'package:analyzer/src/task/dart.dart' |
| + show |
| + LIBRARY_ELEMENT1, |
| + LIBRARY_ELEMENT2, |
| + LIBRARY_ELEMENT3, |
| + LIBRARY_ELEMENT4, |
| + LIBRARY_ELEMENT5, |
| + LIBRARY_ELEMENT6, |
| + LIBRARY_ELEMENT7, |
| + LIBRARY_ELEMENT8, |
| + READY_LIBRARY_ELEMENT2, |
| + READY_LIBRARY_ELEMENT5, |
| + READY_LIBRARY_ELEMENT6, |
| + TYPE_PROVIDER; |
| +import 'package:analyzer/task/dart.dart'; |
| +import 'package:analyzer/task/model.dart' |
| + show AnalysisTarget, ResultDescriptor, TargetedResult; |
| + |
| +/** |
| + * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle]. |
| + */ |
| +class SummarySdkAnalysisContext extends SdkAnalysisContext { |
| + final SdkBundle bundle; |
| + final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); |
| + |
| + SummaryResynthesizer resynthesizer; |
| + |
| + SummarySdkAnalysisContext(this.bundle); |
| + |
| + @override |
| + bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) { |
| + if (resynthesizer == null) { |
|
Brian Wilkerson
2016/01/05 18:46:18
Is there any reason to do this lazily? It seems li
scheglov
2016/01/05 20:27:57
The property "sourceFactory" is set after the cont
|
| + resynthesizer = new SummaryResynthesizer(this, typeProvider, |
| + _getPrelinkedSummary, _getUnlinkedSummary, sourceFactory); |
| + _buildCoreLibrary(); |
| + _buildAsyncLibrary(); |
| + } |
| + if (result == TYPE_PROVIDER) { |
| + entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST); |
| + return true; |
| + } |
| + AnalysisTarget target = entry.target; |
| + if (target is Source && target.isInSystemLibrary) { |
| + if (result == LIBRARY_ELEMENT1 || |
| + result == LIBRARY_ELEMENT2 || |
| + result == LIBRARY_ELEMENT3 || |
| + result == LIBRARY_ELEMENT4 || |
| + result == LIBRARY_ELEMENT5 || |
| + result == LIBRARY_ELEMENT6 || |
| + result == LIBRARY_ELEMENT7 || |
| + result == LIBRARY_ELEMENT8 || |
| + result == LIBRARY_ELEMENT) { |
|
Paul Berry
2016/01/05 19:33:43
Is it going to be a maintenance burden to keep thi
scheglov
2016/01/05 20:27:57
Sounds interesting.
|
| + String uri = target.uri.toString(); |
| + LibraryElement libraryElement = resynthesizer.getLibraryElement(uri); |
| + entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST); |
| + return true; |
| + } else if (result == READY_LIBRARY_ELEMENT2 || |
| + result == READY_LIBRARY_ELEMENT5 || |
| + result == READY_LIBRARY_ELEMENT6) { |
| + entry.setValue(result, true, TargetedResult.EMPTY_LIST); |
| + return true; |
| + } else if (result == SOURCE_KIND) { |
| + // TODO(scheglov) not every source is a library |
|
Paul Berry
2016/01/05 19:33:43
I think the only way this could be reached is if t
scheglov
2016/01/05 20:27:57
Yes.
For now it is just a placeholder.
Once we wil
|
| + print(target.source.uri); |
|
Brian Wilkerson
2016/01/05 18:46:18
Remove?
scheglov
2016/01/05 20:27:57
Done.
|
| + entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST); |
| + return true; |
|
Brian Wilkerson
2016/01/05 18:46:18
Should this return `false` for now until we can co
scheglov
2016/01/05 20:27:57
Returning `false` mean that we cannot provide this
Brian Wilkerson
2016/01/05 20:42:51
Could we implement it correctly by just testing wh
|
| + } else { |
| + throw new UnimplementedError('$result of $target'); |
|
Brian Wilkerson
2016/01/05 18:46:18
Is this for debugging? If so, perhaps comment it o
scheglov
2016/01/05 20:27:57
Done.
|
| + } |
| + } |
| + return false; |
| + } |
| + |
| + void _buildAsyncLibrary() { |
| + LibraryElement library = resynthesizer.getLibraryElement('dart:async'); |
| + typeProvider.initializeAsync(library); |
| + } |
| + |
| + void _buildCoreLibrary() { |
| + LibraryElement library = resynthesizer.getLibraryElement('dart:core'); |
| + typeProvider.initializeCore(library); |
| + } |
| + |
| + PrelinkedLibrary _getPrelinkedSummary(String uri) { |
| + for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) { |
| + if (bundle.prelinkedLibraryUris[i] == uri) { |
| + return bundle.prelinkedLibraries[i]; |
| + } |
| + } |
| + throw new StateError('Unable to find prelinked summary for $uri'); |
|
Paul Berry
2016/01/05 19:33:43
Is there a danger of this code getting triggered i
scheglov
2016/01/05 20:27:57
No, if a URI is not resolved to an existing Source
|
| + } |
| + |
| + UnlinkedUnit _getUnlinkedSummary(String uri) { |
| + for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { |
| + if (bundle.unlinkedUnitUris[i] == uri) { |
| + return bundle.unlinkedUnits[i]; |
| + } |
| + } |
| + throw new StateError('Unable to find unlinked summary for $uri'); |
| + } |
| +} |
| /** |
| * Implementation of [TypeProvider] which can be initialized separately with |