| Index: pkg/analyzer/lib/src/summary/resynthesize.dart
|
| diff --git a/pkg/analyzer/lib/src/summary/resynthesize.dart b/pkg/analyzer/lib/src/summary/resynthesize.dart
|
| index f60514c7574e3a6cb13dd5555ee9be0b139c903b..c4f6caa80ac4ce5a58d4058c88f9e58119a9366c 100644
|
| --- a/pkg/analyzer/lib/src/summary/resynthesize.dart
|
| +++ b/pkg/analyzer/lib/src/summary/resynthesize.dart
|
| @@ -22,7 +22,6 @@ import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
|
| import 'package:analyzer/src/generated/testing/token_factory.dart';
|
| import 'package:analyzer/src/summary/format.dart';
|
| import 'package:analyzer/src/summary/idl.dart';
|
| -import 'package:analyzer/src/summary/summary_sdk.dart';
|
|
|
| /**
|
| * Implementation of [ElementResynthesizer] used when resynthesizing an element
|
| @@ -30,6 +29,13 @@ import 'package:analyzer/src/summary/summary_sdk.dart';
|
| */
|
| abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| /**
|
| + * The parent [SummaryResynthesizer] which is asked to resynthesize elements
|
| + * and get summaries before this resynthesizer attempts to do this.
|
| + * Can be `null`.
|
| + */
|
| + final SummaryResynthesizer parent;
|
| +
|
| + /**
|
| * Source factory used to convert URIs to [Source] objects.
|
| */
|
| final SourceFactory sourceFactory;
|
| @@ -40,9 +46,10 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| final Map<String, Source> _sources = <String, Source>{};
|
|
|
| /**
|
| - * The [TypeProvider] used to obtain SDK types during resynthesis.
|
| + * The [TypeProvider] used to obtain core types (such as Object, int, List,
|
| + * and dynamic) during resynthesis.
|
| */
|
| - TypeProvider _typeProvider;
|
| + final TypeProvider typeProvider;
|
|
|
| /**
|
| * Indicates whether the summary should be resynthesized assuming strong mode
|
| @@ -73,11 +80,9 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| final Map<String, LibraryElement> _resynthesizedLibraries =
|
| <String, LibraryElement>{};
|
|
|
| - SummaryResynthesizer(
|
| - AnalysisContext context, this.sourceFactory, this.strongMode)
|
| - : super(context) {
|
| - _buildTypeProvider();
|
| - }
|
| + SummaryResynthesizer(this.parent, AnalysisContext context, this.typeProvider,
|
| + this.sourceFactory, this.strongMode)
|
| + : super(context);
|
|
|
| /**
|
| * Number of libraries that have been resynthesized so far.
|
| @@ -85,14 +90,23 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| int get resynthesisCount => _resynthesizedLibraries.length;
|
|
|
| /**
|
| - * The [TypeProvider] used to obtain SDK types during resynthesis.
|
| + * Perform delayed finalization of the `dart:core` and `dart:async` libraries.
|
| */
|
| - TypeProvider get typeProvider => _typeProvider;
|
| + void finalizeCoreAsyncLibraries() {
|
| + (_resynthesizedLibraries['dart:core'] as LibraryElementImpl)
|
| + .createLoadLibraryFunction(typeProvider);
|
| + (_resynthesizedLibraries['dart:async'] as LibraryElementImpl)
|
| + .createLoadLibraryFunction(typeProvider);
|
| + }
|
|
|
| @override
|
| Element getElement(ElementLocation location) {
|
| List<String> components = location.components;
|
| String libraryUri = components[0];
|
| + // Ask the parent resynthesizer.
|
| + if (parent != null && parent._hasLibrarySummary(libraryUri)) {
|
| + return parent.getElement(location);
|
| + }
|
| // Resynthesize locally.
|
| if (components.length == 1) {
|
| return getLibraryElement(libraryUri);
|
| @@ -189,8 +203,11 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| * hasn't been resynthesized already.
|
| */
|
| LibraryElement getLibraryElement(String uri) {
|
| + if (parent != null && parent._hasLibrarySummary(uri)) {
|
| + return parent.getLibraryElement(uri);
|
| + }
|
| return _resynthesizedLibraries.putIfAbsent(uri, () {
|
| - LinkedLibrary serializedLibrary = getLinkedSummary(uri);
|
| + LinkedLibrary serializedLibrary = _getLinkedSummaryOrNull(uri);
|
| Source librarySource = _getSource(uri);
|
| if (serializedLibrary == null) {
|
| LibraryElementImpl libraryElement =
|
| @@ -206,7 +223,7 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| libraryElement.exportNamespace = new Namespace({});
|
| return libraryElement;
|
| }
|
| - UnlinkedUnit unlinkedSummary = getUnlinkedSummary(uri);
|
| + UnlinkedUnit unlinkedSummary = _getUnlinkedSummaryOrNull(uri);
|
| if (unlinkedSummary == null) {
|
| throw new StateError('Unable to find unlinked summary: $uri');
|
| }
|
| @@ -217,7 +234,7 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| serializedUnits.add(null);
|
| } else {
|
| String partAbsUri = partSource.uri.toString();
|
| - serializedUnits.add(getUnlinkedSummary(partAbsUri) ??
|
| + serializedUnits.add(_getUnlinkedSummaryOrNull(partAbsUri) ??
|
| new UnlinkedUnitBuilder(codeRange: new CodeRangeBuilder()));
|
| }
|
| }
|
| @@ -250,15 +267,15 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| */
|
| bool hasLibrarySummary(String uri);
|
|
|
| - void _buildTypeProvider() {
|
| - var coreLibrary = getLibraryElement('dart:core') as LibraryElementImpl;
|
| - var asyncLibrary = getLibraryElement('dart:async') as LibraryElementImpl;
|
| - SummaryTypeProvider summaryTypeProvider = new SummaryTypeProvider();
|
| - summaryTypeProvider.initializeCore(coreLibrary);
|
| - summaryTypeProvider.initializeAsync(asyncLibrary);
|
| - coreLibrary.createLoadLibraryFunction(summaryTypeProvider);
|
| - asyncLibrary.createLoadLibraryFunction(summaryTypeProvider);
|
| - _typeProvider = summaryTypeProvider;
|
| + /**
|
| + * Return the [LinkedLibrary] for the given [uri] or return `null` if it
|
| + * could not be found.
|
| + */
|
| + LinkedLibrary _getLinkedSummaryOrNull(String uri) {
|
| + if (parent != null && parent._hasLibrarySummary(uri)) {
|
| + return parent._getLinkedSummaryOrNull(uri);
|
| + }
|
| + return getLinkedSummary(uri);
|
| }
|
|
|
| /**
|
| @@ -267,6 +284,28 @@ abstract class SummaryResynthesizer extends ElementResynthesizer {
|
| Source _getSource(String uri) {
|
| return _sources.putIfAbsent(uri, () => sourceFactory.forUri(uri));
|
| }
|
| +
|
| + /**
|
| + * Return the [UnlinkedUnit] for the given [uri] or return `null` if it
|
| + * could not be found.
|
| + */
|
| + UnlinkedUnit _getUnlinkedSummaryOrNull(String uri) {
|
| + if (parent != null && parent._hasLibrarySummary(uri)) {
|
| + return parent._getUnlinkedSummaryOrNull(uri);
|
| + }
|
| + return getUnlinkedSummary(uri);
|
| + }
|
| +
|
| + /**
|
| + * Return `true` if this resynthesizer can provide summaries of the libraries
|
| + * with the given [uri].
|
| + */
|
| + bool _hasLibrarySummary(String uri) {
|
| + if (parent != null && parent._hasLibrarySummary(uri)) {
|
| + return true;
|
| + }
|
| + return hasLibrarySummary(uri);
|
| + }
|
| }
|
|
|
| /**
|
|
|