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

Unified Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1768713002: Fixes to associating existing elements with an AST (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments 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/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index b94806d2f4da0eaabde1b0e7e5b6d466cc5abf2c..11a704df7352bf0d201c622b9c5e6e520c47657c 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -1004,24 +1004,46 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
Map<Source, SourceKind> exportSourceKindMap =
getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME);
//
- // Build elements.
+ // Try to get the existing LibraryElement.
//
- DirectiveElementBuilder builder = new DirectiveElementBuilder(
- context,
- libraryElement,
- importLibraryMap,
- importSourceKindMap,
- exportLibraryMap,
- exportSourceKindMap);
- libraryUnit.accept(builder);
- // See commentary in the computation of the LIBRARY_CYCLE result
- // for details on library cycle invalidation.
- libraryElement.invalidateLibraryCycles();
+ LibraryElement element;
+ {
+ InternalAnalysisContext internalContext =
+ context as InternalAnalysisContext;
+ AnalysisCache analysisCache = internalContext.analysisCache;
+ CacheEntry cacheEntry = internalContext.getCacheEntry(target);
+ element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
+ if (element == null &&
+ internalContext.aboutToComputeResult(cacheEntry, LIBRARY_ELEMENT2)) {
+ element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
+ }
+ }
+ //
+ // Build or reuse the directive elements.
+ //
+ List<AnalysisError> errors;
+ if (element == null) {
+ DirectiveElementBuilder builder = new DirectiveElementBuilder(
+ context,
+ libraryElement,
+ importLibraryMap,
+ importSourceKindMap,
+ exportLibraryMap,
+ exportSourceKindMap);
+ libraryUnit.accept(builder);
+ // See the commentary in the computation of the LIBRARY_CYCLE result
+ // for details on library cycle invalidation.
+ libraryElement.invalidateLibraryCycles();
+ errors = builder.errors;
+ } else {
+ DirectiveResolver resolver = new DirectiveResolver();
+ libraryUnit.accept(resolver);
+ }
//
// Record outputs.
//
outputs[LIBRARY_ELEMENT2] = libraryElement;
- outputs[BUILD_DIRECTIVES_ERRORS] = builder.errors;
+ outputs[BUILD_DIRECTIVES_ERRORS] = errors;
}
/**
@@ -1383,9 +1405,7 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
libraryElement.definingCompilationUnit = definingCompilationUnitElement;
libraryElement.entryPoint = entryPoint;
libraryElement.parts = sourcedCompilationUnits;
- for (Directive directive in directivesToResolve) {
- directive.element = libraryElement;
- }
+ libraryElement.hasExtUri = _hasExtUri(definingCompilationUnit);
BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement);
// set the library documentation to the docs associated with the first
// directive in the compilation unit.
@@ -1395,6 +1415,15 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
}
}
//
+ // Resolve the relevant directives to the library element.
+ //
+ // TODO(brianwilkerson) This updates the state of the AST structures but
+ // does not associate a new result with it.
+ //
+ for (Directive directive in directivesToResolve) {
+ directive.element = libraryElement;
+ }
+ //
// Record outputs.
//
outputs[BUILD_LIBRARY_ERRORS] = errors;
@@ -1434,6 +1463,21 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
}
/**
+ * Return `true` if the given compilation [unit] contains at least one
+ * import directive with a `dart-ext:` URI.
+ */
+ bool _hasExtUri(CompilationUnit unit) {
+ for (Directive directive in unit.directives) {
+ if (directive is ImportDirective) {
+ if (DartUriResolver.isDartExtUri(directive.uriContent)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* Return a map from the names of the inputs of this kind of task to the task
* input descriptors describing those inputs for a task with the given
* [libSource].
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/declaration_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698