Chromium Code Reviews| 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 f4271ff6327e5964c193de72483f0e7e8e67c5fe..351c22ef21fae525300aa33264aeebcf23cdc45a 100644 |
| --- a/pkg/analyzer/lib/src/summary/resynthesize.dart |
| +++ b/pkg/analyzer/lib/src/summary/resynthesize.dart |
| @@ -15,50 +15,18 @@ import 'package:analyzer/src/generated/source_io.dart'; |
| import 'package:analyzer/src/summary/format.dart'; |
| /** |
| - * Callback used by [SummaryResynthesizer] to obtain the linked summary for |
| - * a given URI. |
| - */ |
| -typedef LinkedLibrary GetLinkedSummaryCallback(String uri); |
| - |
| -/** |
| - * Callback used by [SummaryResynthesizer] to obtain the unlinked summary for a |
| - * given URI. |
| - */ |
| -typedef UnlinkedUnit GetUnlinkedSummaryCallback(String uri); |
| - |
| -/** |
| - * Callback used by [SummaryResynthesizer] to check whether it can access |
| - * summaries of the library with the given [uri]. |
| - */ |
| -typedef bool HasLibrarySummaryCallback(String uri); |
| - |
| -/** |
| * Implementation of [ElementResynthesizer] used when resynthesizing an element |
| * model from summaries. |
| */ |
| class SummaryResynthesizer extends ElementResynthesizer { |
| /** |
| - * The parent [SummaryResynthesizer] which is asked to resynthesis elements |
| - * before this resynthesizer attempts to do this. Can be `null`. |
| + * 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; |
| /** |
| - * Callback used to check whether summaries for a given URI can be accessed. |
| - */ |
| - final HasLibrarySummaryCallback hasLibrarySummary; |
| - |
| - /** |
| - * Callback used to obtain the linked summary for a given URI. |
| - */ |
| - final GetLinkedSummaryCallback getLinkedSummary; |
| - |
| - /** |
| - * Callback used to obtain the unlinked summary for a given URI. |
| - */ |
| - final GetUnlinkedSummaryCallback getUnlinkedSummary; |
| - |
| - /** |
| * Source factory used to convert URIs to [Source] objects. |
| */ |
| final SourceFactory sourceFactory; |
| @@ -89,13 +57,7 @@ class SummaryResynthesizer extends ElementResynthesizer { |
| final Map<String, LibraryElement> _resynthesizedLibraries = |
| <String, LibraryElement>{}; |
| - SummaryResynthesizer( |
| - this.parent, |
| - AnalysisContext context, |
| - this.typeProvider, |
| - this.hasLibrarySummary, |
| - this.getLinkedSummary, |
| - this.getUnlinkedSummary, |
| + SummaryResynthesizer(this.parent, AnalysisContext context, this.typeProvider, |
| this.sourceFactory) |
| : super(context); |
| @@ -147,15 +109,15 @@ class SummaryResynthesizer extends ElementResynthesizer { |
| return parent.getLibraryElement(uri); |
| } |
| return _resynthesizedLibraries.putIfAbsent(uri, () { |
| - LinkedLibrary serializedLibrary = getLinkedSummary(uri); |
| + LinkedLibrary serializedLibrary = _getLinkedSummaryOrThrow(uri); |
| List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[ |
| - getUnlinkedSummary(uri) |
| + _getUnlinkedSummaryOrThrow(uri) |
| ]; |
| Source librarySource = _getSource(uri); |
| for (String part in serializedUnits[0].publicNamespace.parts) { |
| Source partSource = sourceFactory.resolveUri(librarySource, part); |
| String partAbsUri = partSource.uri.toString(); |
| - serializedUnits.add(getUnlinkedSummary(partAbsUri)); |
| + serializedUnits.add(_getUnlinkedSummaryOrThrow(partAbsUri)); |
| } |
| _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( |
| this, serializedLibrary, serializedUnits, librarySource); |
| @@ -166,11 +128,71 @@ class SummaryResynthesizer extends ElementResynthesizer { |
| } |
| /** |
| + * Return the [LinkedLibrary] for the given [uri] or `null` if it could not |
| + * be found. |
| + */ |
| + LinkedLibrary getLinkedSummary(String uri) { |
|
Paul Berry
2016/01/15 16:37:38
I'm concerned about the interface contract implied
scheglov
2016/01/15 16:54:50
Done.
|
| + if (parent != null) { |
| + LinkedLibrary summary = parent.getLinkedSummary(uri); |
| + if (summary != null) { |
| + return summary; |
| + } |
| + } |
| + return null; |
| + } |
| + |
| + /** |
| + * Return the [UnlinkedUnit] for the given [uri] or `null` if it could not |
| + * be found. |
| + */ |
| + UnlinkedUnit getUnlinkedSummary(String uri) { |
| + if (parent != null) { |
| + UnlinkedUnit summary = parent.getUnlinkedSummary(uri); |
| + if (summary != null) { |
| + return summary; |
| + } |
| + } |
| + return null; |
| + } |
| + |
| + /** |
| + * Return `true` if this resynthesizer get provide summaries of the libraries |
|
Paul Berry
2016/01/15 16:37:38
s/get/can/
|
| + * with the given [uri]. |
| + */ |
| + bool hasLibrarySummary(String uri) { |
| + return false; |
| + } |
| + |
| + /** |
| + * Return the [LinkedLibrary] for the given [uri] or throw [StateError] if it |
| + * could not be found. |
| + */ |
| + LinkedLibrary _getLinkedSummaryOrThrow(String uri) { |
| + LinkedLibrary summary = getLinkedSummary(uri); |
| + if (summary != null) { |
| + return summary; |
| + } |
| + throw new StateError('Unable to find linked summary: $uri'); |
| + } |
| + |
| + /** |
| * Get the [Source] object for the given [uri]. |
| */ |
| Source _getSource(String uri) { |
| return _sources.putIfAbsent(uri, () => sourceFactory.forUri(uri)); |
| } |
| + |
| + /** |
| + * Return the [UnlinkedUnit] for the given [uri] or throw [StateError] if it |
| + * could not be found. |
| + */ |
| + UnlinkedUnit _getUnlinkedSummaryOrThrow(String uri) { |
| + UnlinkedUnit summary = getUnlinkedSummary(uri); |
| + if (summary != null) { |
| + return summary; |
| + } |
| + throw new StateError('Unable to find unlinked summary: $uri'); |
| + } |
| } |
| /** |
| @@ -1054,7 +1076,7 @@ class _LibraryResynthesizer { |
| String partUri; |
| if (unit != 0) { |
| UnlinkedUnit referencedLibraryDefiningUnit = |
| - summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri); |
| + summaryResynthesizer._getUnlinkedSummaryOrThrow(referencedLibraryUri); |
| String uri = |
| referencedLibraryDefiningUnit.publicNamespace.parts[unit - 1]; |
| Source partSource = summaryResynthesizer.sourceFactory |