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

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: 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 4d9b9feb6ce4ce6b59fabe8221debbe1dcc68723..2a7e10b7c66bb0c07b7a456e67d49be9abd81732 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,32 +34,30 @@ 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(context, typeProvider,
+ _getPrelinkedSummary, _getUnlinkedSummary, context.sourceFactory);
+ _buildCoreLibrary();
+ _buildAsyncLibrary();
+ summaryResynthesizer.finalizeCoreAsyncLibraries();
+ }
@override
- bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) {
- if (resynthesizer == null) {
- resynthesizer = new SummaryResynthesizer(this, typeProvider,
- _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 ||
@@ -70,7 +70,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 ||
@@ -80,12 +81,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;
@@ -97,15 +95,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) {
@@ -115,6 +118,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) {

Powered by Google App Engine
This is Rietveld 408576698