Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1622)

Unified Diff: pkg/analyzer/lib/src/summary/summary_sdk.dart

Issue 1591483002: Prepare for chaining resynthesizers from AC to SDK AC. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fallback to the SDK. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 e45cbc691ca549f5bb718f5c6b31e30fc0cb9f56..5deb8a60b33bde4b03a72649d0b947958f28b9f8 100644
--- a/pkg/analyzer/lib/src/summary/summary_sdk.dart
+++ b/pkg/analyzer/lib/src/summary/summary_sdk.dart
@@ -10,8 +10,10 @@ 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/engine.dart';
import 'package:analyzer/src/generated/resolver.dart';
-import 'package:analyzer/src/generated/source.dart' show Source, SourceKind;
+import 'package:analyzer/src/generated/source.dart'
+ show DartUriResolver, Source, SourceFactory, SourceKind;
import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary/resynthesize.dart';
import 'package:analyzer/src/task/dart.dart'
@@ -32,38 +34,36 @@ 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 {
+class SdkSummaryResultProvider extends AboutToComputeResultHelper {
final SdkBundle bundle;
final SummaryTypeProvider typeProvider = new SummaryTypeProvider();
-
- SummaryResynthesizer resynthesizer;
-
- SummarySdkAnalysisContext(this.bundle);
+ SummaryResynthesizer summaryResynthesizer;
+
+ SdkSummaryResultProvider(InternalAnalysisContext context, this.bundle)
+ : super(context) {
+ summaryResynthesizer = new SummaryResynthesizer(
+ null,
+ context,
+ typeProvider,
+ (String uri) => uri.startsWith('dart:'),
+ _getPrelinkedSummary,
+ _getUnlinkedSummary,
+ context.sourceFactory);
+ _buildCoreLibrary();
+ _buildAsyncLibrary();
+ summaryResynthesizer.finalizeCoreAsyncLibraries();
+ }
@override
- bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) {
- if (resynthesizer == null) {
- resynthesizer = new SummaryResynthesizer(
- null,
- this,
- typeProvider,
- (String uri) => uri.startsWith('dart:'),
- _getPrelinkedSummary,
- _getUnlinkedSummary,
- sourceFactory);
- _buildCoreLibrary();
- _buildAsyncLibrary();
- }
+ bool compute(CacheEntry entry, ResultDescriptor result) {
if (result == TYPE_PROVIDER) {
+// print('SummarySdkAnalysisContext: $result');
entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST);
return true;
}
AnalysisTarget target = entry.target;
-// print('SummarySdkAnalysisContext: $result of $target');
if (target is Source && target.isInSystemLibrary) {
+// print('SummarySdkAnalysisContext: $result of $target');
if (result == LIBRARY_ELEMENT1 ||
result == LIBRARY_ELEMENT2 ||
result == LIBRARY_ELEMENT3 ||
@@ -76,7 +76,8 @@ class SummarySdkAnalysisContext extends SdkAnalysisContext {
// TODO(scheglov) try to find a way to avoid listing every result
// e.g. "result.whenComplete == LIBRARY_ELEMENT"
String uri = target.uri.toString();
- LibraryElement libraryElement = resynthesizer.getLibraryElement(uri);
+ LibraryElement libraryElement =
+ summaryResynthesizer.getLibraryElement(uri);
entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST);
return true;
} else if (result == READY_LIBRARY_ELEMENT2 ||
@@ -86,12 +87,9 @@ class SummarySdkAnalysisContext extends SdkAnalysisContext {
return true;
} else if (result == SOURCE_KIND) {
String uri = target.uri.toString();
- if (bundle.prelinkedLibraryUris.contains(uri)) {
- entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST);
- return true;
- }
- if (bundle.unlinkedUnitUris.contains(uri)) {
- entry.setValue(result, SourceKind.PART, TargetedResult.EMPTY_LIST);
+ SourceKind kind = _getSourceKind(uri);
+ if (kind != null) {
+ entry.setValue(result, kind, TargetedResult.EMPTY_LIST);
return true;
}
return false;
@@ -103,15 +101,20 @@ class SummarySdkAnalysisContext extends SdkAnalysisContext {
}
void _buildAsyncLibrary() {
- LibraryElement library = resynthesizer.getLibraryElement('dart:async');
+ LibraryElement library =
+ summaryResynthesizer.getLibraryElement('dart:async');
typeProvider.initializeAsync(library);
}
void _buildCoreLibrary() {
- LibraryElement library = resynthesizer.getLibraryElement('dart:core');
+ LibraryElement library =
+ summaryResynthesizer.getLibraryElement('dart:core');
typeProvider.initializeCore(library);
}
+ /**
+ * Return the [PrelinkedLibrary] for the given [uri] or throw [StateError].
+ */
PrelinkedLibrary _getPrelinkedSummary(String uri) {
for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) {
if (bundle.prelinkedLibraryUris[i] == uri) {
@@ -121,6 +124,22 @@ class SummarySdkAnalysisContext extends SdkAnalysisContext {
throw new StateError('Unable to find prelinked summary for $uri');
}
+ /**
+ * Return the [SourceKind] of the given [uri] or `null` if it is unknown.
+ */
+ SourceKind _getSourceKind(String uri) {
+ if (bundle.prelinkedLibraryUris.contains(uri)) {
+ return SourceKind.LIBRARY;
+ }
+ if (bundle.unlinkedUnitUris.contains(uri)) {
+ return SourceKind.PART;
+ }
+ return null;
+ }
+
+ /**
+ * Return the [UnlinkedUnit] for the given [uri] or throw [StateError].
+ */
UnlinkedUnit _getUnlinkedSummary(String uri) {
for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
if (bundle.unlinkedUnitUris[i] == uri) {
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698