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

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

Issue 1659523003: Make a DirectiveElementBuilder class for use by BuildDirectiveElementsTask. (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/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index 2c99cd2dbf85646c7566e87018391d02ab4f8fde..7bd74d8cab36b1e2a6948e9df9c3f77402ea1752 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -983,7 +983,6 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
@override
void internalPerform() {
- List<AnalysisError> errors = <AnalysisError>[];
//
// Prepare inputs.
//
@@ -997,114 +996,17 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME);
Map<Source, SourceKind> exportSourceKindMap =
getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME);
- Source librarySource = libraryElement.source;
- //
- // Resolve directives.
- //
- HashMap<String, PrefixElementImpl> nameToPrefixMap =
- new HashMap<String, PrefixElementImpl>();
- List<ImportElement> imports = <ImportElement>[];
- List<ExportElement> exports = <ExportElement>[];
- bool explicitlyImportsCore = false;
- for (Directive directive in libraryUnit.directives) {
- if (directive is ImportDirective) {
- ImportDirective importDirective = directive;
- String uriContent = importDirective.uriContent;
- if (DartUriResolver.isDartExtUri(uriContent)) {
- libraryElement.hasExtUri = true;
- }
- Source importedSource = importDirective.source;
- if (importedSource != null && context.exists(importedSource)) {
- // The imported source will be null if the URI in the import
- // directive was invalid.
- LibraryElement importedLibrary = importLibraryMap[importedSource];
- if (importedLibrary != null) {
- if (importedLibrary.isDartCore) {
- explicitlyImportsCore = true;
- }
- ImportElementImpl importElement =
- new ImportElementImpl(directive.offset);
- StringLiteral uriLiteral = importDirective.uri;
- if (uriLiteral != null) {
- importElement.uriOffset = uriLiteral.offset;
- importElement.uriEnd = uriLiteral.end;
- }
- importElement.uri = uriContent;
- importElement.deferred = importDirective.deferredKeyword != null;
- importElement.combinators = _buildCombinators(importDirective);
- importElement.importedLibrary = importedLibrary;
- _setDoc(importElement, importDirective);
- SimpleIdentifier prefixNode = directive.prefix;
- if (prefixNode != null) {
- importElement.prefixOffset = prefixNode.offset;
- String prefixName = prefixNode.name;
- PrefixElementImpl prefix = nameToPrefixMap[prefixName];
- if (prefix == null) {
- prefix = new PrefixElementImpl.forNode(prefixNode);
- nameToPrefixMap[prefixName] = prefix;
- }
- importElement.prefix = prefix;
- prefixNode.staticElement = prefix;
- }
- directive.element = importElement;
- imports.add(importElement);
- if (importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
- ErrorCode errorCode = (importElement.isDeferred
- ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
- : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
- errors.add(new AnalysisError(importedSource, uriLiteral.offset,
- uriLiteral.length, errorCode, [uriLiteral.toSource()]));
- }
- }
- }
- } else if (directive is ExportDirective) {
- ExportDirective exportDirective = directive;
- Source exportedSource = exportDirective.source;
- if (exportedSource != null && context.exists(exportedSource)) {
- // The exported source will be null if the URI in the export
- // directive was invalid.
- LibraryElement exportedLibrary = exportLibraryMap[exportedSource];
- if (exportedLibrary != null) {
- ExportElementImpl exportElement =
- new ExportElementImpl(directive.offset);
- StringLiteral uriLiteral = exportDirective.uri;
- if (uriLiteral != null) {
- exportElement.uriOffset = uriLiteral.offset;
- exportElement.uriEnd = uriLiteral.end;
- }
- exportElement.uri = exportDirective.uriContent;
- exportElement.combinators = _buildCombinators(exportDirective);
- exportElement.exportedLibrary = exportedLibrary;
- _setDoc(exportElement, exportDirective);
- directive.element = exportElement;
- exports.add(exportElement);
- if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
- errors.add(new AnalysisError(
- exportedSource,
- uriLiteral.offset,
- uriLiteral.length,
- CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
- [uriLiteral.toSource()]));
- }
- }
- }
- }
- }
//
- // Ensure "dart:core" import.
+ // Build elements.
//
- Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
- if (!explicitlyImportsCore && coreLibrarySource != librarySource) {
- ImportElementImpl importElement = new ImportElementImpl(-1);
- importElement.importedLibrary = importLibraryMap[coreLibrarySource];
- importElement.synthetic = true;
- imports.add(importElement);
- }
- //
- // Populate the library element.
- //
- libraryElement.imports = imports;
- libraryElement.exports = exports;
+ 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();
@@ -1112,20 +1014,7 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
// Record outputs.
//
outputs[LIBRARY_ELEMENT2] = libraryElement;
- outputs[BUILD_DIRECTIVES_ERRORS] = errors;
- }
-
- /**
- * If the given [node] has a documentation comment, remember its content
- * and range into the given [element].
- */
- void _setDoc(ElementImpl element, AnnotatedNode node) {
- Comment comment = node.documentationComment;
- if (comment != null && comment.isDocumentation) {
- element.documentationComment =
- comment.tokens.map((Token t) => t.lexeme).join('\n');
- element.setDocRange(comment.offset, comment.length);
- }
+ outputs[BUILD_DIRECTIVES_ERRORS] = builder.errors;
}
/**
@@ -1158,36 +1047,6 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
AnalysisContext context, AnalysisTarget target) {
return new BuildDirectiveElementsTask(context, target);
}
-
- /**
- * Build the element model representing the combinators declared by
- * the given [directive].
- */
- static List<NamespaceCombinator> _buildCombinators(
- NamespaceDirective directive) {
- List<NamespaceCombinator> combinators = <NamespaceCombinator>[];
- for (Combinator combinator in directive.combinators) {
- if (combinator is ShowCombinator) {
- ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
- show.offset = combinator.offset;
- show.end = combinator.end;
- show.shownNames = _getIdentifiers(combinator.shownNames);
- combinators.add(show);
- } else if (combinator is HideCombinator) {
- HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
- hide.hiddenNames = _getIdentifiers(combinator.hiddenNames);
- combinators.add(hide);
- }
- }
- return combinators;
- }
-
- /**
- * Return the lexical identifiers associated with the given [identifiers].
- */
- static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
- return identifiers.map((identifier) => identifier.name).toList();
- }
}
/**
« pkg/analyzer/lib/src/generated/resolver.dart ('K') | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698