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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2835123004: Add AnalysisDriver.getLibraryByUri(). (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/analysis/library_context.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/driver.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 2a48ddc0e062fbcbb7cc9a75f41f42d42d9b9657..b2300d7093eeddb748f21adaf8518a46417acb16 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -9,7 +9,8 @@ import 'dart:typed_data';
import 'package:analyzer/context/context_root.dart';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement;
+import 'package:analyzer/dart/element/element.dart'
+ show CompilationUnitElement, LibraryElement;
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/exception/exception.dart';
@@ -596,6 +597,21 @@ class AnalysisDriver implements AnalysisDriverGeneric {
return completer.future;
}
+ /**
+ * Return a [Future] that completes with the [LibraryElement] for the given
+ * [uri], which is either resynthesized from the provided external summary
+ * store, or built for a file to which the given [uri] is resolved.
+ */
+ Future<LibraryElement> getLibraryByUri(String uri) async {
+ if (_externalSummaries != null && _externalSummaries.hasUnlinkedUnit(uri)) {
+ return LibraryContext.resynthesizeLibraryElement(analysisOptions,
+ declaredVariables, sourceFactory, _externalSummaries, uri);
+ }
+ Source source = sourceFactory.resolveUri(null, uri);
+ UnitElementResult unitResult = await getUnitElement(source.fullName);
+ return unitResult.element.library;
+ }
+
ApiSignature getResolvedUnitKeyByPath(String path) {
ApiSignature signature = getUnitKeyByPath(path);
var file = fsState.getFileForPath(path);
@@ -1096,17 +1112,19 @@ class AnalysisDriver implements AnalysisDriverGeneric {
/**
* Return the context in which the [library] should be analyzed.
*/
- LibraryContext _createLibraryContext(FileState library) =>
- new LibraryContext.forSingleLibrary(
- library,
- _logger,
- _sdkBundle,
- _byteStore,
- _analysisOptions,
- declaredVariables,
- _sourceFactory,
- _externalSummaries,
- fsState);
+ LibraryContext _createLibraryContext(FileState library) {
+ _testView.numOfCreatedLibraryContexts++;
+ return new LibraryContext.forSingleLibrary(
+ library,
+ _logger,
+ _sdkBundle,
+ _byteStore,
+ _analysisOptions,
+ declaredVariables,
+ _sourceFactory,
+ _externalSummaries,
+ fsState);
+ }
/**
* Fill [_salt] with data.
@@ -1541,6 +1559,8 @@ class AnalysisDriverScheduler {
class AnalysisDriverTestView {
final AnalysisDriver driver;
+ int numOfCreatedLibraryContexts = 0;
+
int numOfAnalyzedLibraries = 0;
AnalysisDriverTestView(this.driver);
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/analysis/library_context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698