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

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

Issue 1830463002: Change analyzer_cli's "package mode" into a "build mode". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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/package_bundle_reader.dart
diff --git a/pkg/analyzer/lib/src/summary/package_bundle_reader.dart b/pkg/analyzer/lib/src/summary/package_bundle_reader.dart
index a58bfd3757f9c02e09ded69f10270924a0bc7311..d2b3455a811cfa1c0201e933aa0b8eeb9f9dfb2e 100644
--- a/pkg/analyzer/lib/src/summary/package_bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary/package_bundle_reader.dart
@@ -15,32 +15,15 @@ import 'package:analyzer/task/model.dart';
import 'package:path/path.dart' as pathos;
/**
- * If [uri] has the `package` scheme in form of `package:pkg/file.dart`,
- * return the `pkg` name. Otherwise return `null`.
- */
-String _getPackageName(Uri uri) {
- if (uri.scheme != 'package') {
- return null;
- }
- String path = uri.path;
- int index = path.indexOf('/');
- if (index == -1) {
- return null;
- }
- return path.substring(0, index);
-}
-
-/**
* The [ResultProvider] that provides results from input package summaries.
*/
class InputPackagesResultProvider extends ResultProvider {
final InternalAnalysisContext _context;
- final Map<String, String> _packageSummaryInputs;
_FileBasedSummaryResynthesizer _resynthesizer;
SummaryResultProvider _sdkProvider;
- InputPackagesResultProvider(this._context, this._packageSummaryInputs) {
+ InputPackagesResultProvider(this._context, SummaryDataStore dataStore) {
InternalAnalysisContext sdkContext = _context.sourceFactory.dartSdk.context;
_sdkProvider = sdkContext.resultProvider;
// Set the type provider to prevent the context from computing it.
@@ -52,7 +35,7 @@ class InputPackagesResultProvider extends ResultProvider {
_context.typeProvider,
_context.sourceFactory,
_context.analysisOptions.strongMode,
- _packageSummaryInputs.values.toList());
+ dataStore);
}
@override
@@ -65,12 +48,11 @@ class InputPackagesResultProvider extends ResultProvider {
if (target is Source) {
Uri uri = target.uri;
// We know how to server results to input packages.
- String sourcePackageName = _getPackageName(uri);
- if (!_packageSummaryInputs.containsKey(sourcePackageName)) {
+ String uriString = uri.toString();
+ if (!_resynthesizer.hasLibrarySummary(uriString)) {
return false;
}
// Provide known results.
- String uriString = uri.toString();
if (result == LIBRARY_ELEMENT1 ||
result == LIBRARY_ELEMENT2 ||
result == LIBRARY_ELEMENT3 ||
@@ -91,11 +73,11 @@ class InputPackagesResultProvider extends ResultProvider {
entry.setValue(result, true, TargetedResult.EMPTY_LIST);
return true;
} else if (result == SOURCE_KIND) {
- if (_resynthesizer.linkedMap.containsKey(uriString)) {
+ if (_resynthesizer._dataStore.linkedMap.containsKey(uriString)) {
entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST);
return true;
}
- if (_resynthesizer.unlinkedMap.containsKey(uriString)) {
+ if (_resynthesizer._dataStore.unlinkedMap.containsKey(uriString)) {
entry.setValue(result, SourceKind.PART, TargetedResult.EMPTY_LIST);
Jennifer Messerly 2016/03/23 17:37:28 Dumb question about this... Here, it looks like a
scheglov 2016/03/23 17:43:22 Yes, library URIs are in both maps.
return true;
}
@@ -107,19 +89,18 @@ class InputPackagesResultProvider extends ResultProvider {
}
/**
- * The [UriResolver] that knows about sources that are parts of packages which
- * are served from their summaries.
+ * The [UriResolver] that knows about sources that are served from their
+ * summaries.
*/
class InSummaryPackageUriResolver extends UriResolver {
- final Map<String, String> _packageSummaryInputs;
+ final SummaryDataStore _dataStore;
- InSummaryPackageUriResolver(this._packageSummaryInputs);
+ InSummaryPackageUriResolver(this._dataStore);
@override
Source resolveAbsolute(Uri uri, [Uri actualUri]) {
actualUri ??= uri;
- String packageName = _getPackageName(actualUri);
- if (_packageSummaryInputs.containsKey(packageName)) {
+ if (_dataStore.unlinkedMap.containsKey(uri.toString())) {
return new _InSummarySource(actualUri);
}
return null;
@@ -127,48 +108,67 @@ class InSummaryPackageUriResolver extends UriResolver {
}
/**
- * A concrete resynthesizer that serves summaries from given file paths.
+ * A [SummaryDataStore] is a container for the data extracted from a set of
+ * summary package bundles. It contains maps which can be used to find linked
+ * and unlinked summaries by URI.
*/
-class _FileBasedSummaryResynthesizer extends SummaryResynthesizer {
+class SummaryDataStore {
+ /**
+ * Map from the URI of a compilation unit to the unlinked summary of that
+ * compilation unit.
+ */
final Map<String, UnlinkedUnit> unlinkedMap = <String, UnlinkedUnit>{};
+
+ /**
+ * Map from the URI of a library to the linked summary of that library.
+ */
final Map<String, LinkedLibrary> linkedMap = <String, LinkedLibrary>{};
+ SummaryDataStore(Iterable<String> summaryPaths) {
+ summaryPaths.forEach(_fillMaps);
+ }
+
+ void _fillMaps(String path) {
+ io.File file = new io.File(path);
+ List<int> buffer = file.readAsBytesSync();
+ PackageBundle bundle = new PackageBundle.fromBuffer(buffer);
+ for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
+ unlinkedMap[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i];
+ }
+ for (int i = 0; i < bundle.linkedLibraryUris.length; i++) {
+ linkedMap[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i];
+ }
+ }
+}
+
+/**
+ * A concrete resynthesizer that serves summaries from given file paths.
+ */
+class _FileBasedSummaryResynthesizer extends SummaryResynthesizer {
+ final SummaryDataStore _dataStore;
+
_FileBasedSummaryResynthesizer(
SummaryResynthesizer parent,
AnalysisContext context,
TypeProvider typeProvider,
SourceFactory sourceFactory,
bool strongMode,
- List<String> summaryPaths)
- : super(parent, context, typeProvider, sourceFactory, strongMode) {
- summaryPaths.forEach(_fillMaps);
- }
+ this._dataStore)
+ : super(parent, context, typeProvider, sourceFactory, strongMode);
@override
LinkedLibrary getLinkedSummary(String uri) {
- return linkedMap[uri];
+ return _dataStore.linkedMap[uri];
}
@override
UnlinkedUnit getUnlinkedSummary(String uri) {
- return unlinkedMap[uri];
+ return _dataStore.unlinkedMap[uri];
}
@override
bool hasLibrarySummary(String uri) {
- return linkedMap.containsKey(uri);
- }
-
- void _fillMaps(String path) {
- io.File file = new io.File(path);
- List<int> buffer = file.readAsBytesSync();
- PackageBundle bundle = new PackageBundle.fromBuffer(buffer);
- for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
- unlinkedMap[bundle.unlinkedUnitUris[i]] = bundle.unlinkedUnits[i];
- }
- for (int i = 0; i < bundle.linkedLibraryUris.length; i++) {
- linkedMap[bundle.linkedLibraryUris[i]] = bundle.linkedLibraries[i];
- }
+ return _dataStore.linkedMap.containsKey(uri);
}
}

Powered by Google App Engine
This is Rietveld 408576698