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

Unified Diff: pkg/analyzer/lib/src/generated/element_resolver.dart

Issue 1668483003: Create ElementAnnotation objects prior to resolution. (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/generated/element_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart
index 5bf9630c478713255f3dd5352f2dad8381eb9f35..b5cddef5537b47c1bfcc4dbe39d3039a27bdc77b 100644
--- a/pkg/analyzer/lib/src/generated/element_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/element_resolver.dart
@@ -205,13 +205,13 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitClassDeclaration(ClassDeclaration node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@override
Object visitClassTypeAlias(ClassTypeAlias node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@@ -336,7 +336,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
}
}
- setMetadata(constructorElement, node);
+ resolveMetadata(node);
}
return null;
}
@@ -392,13 +392,13 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitDeclaredIdentifier(DeclaredIdentifier node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@override
Object visitEnumDeclaration(EnumDeclaration node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@@ -410,20 +410,20 @@ class ElementResolver extends SimpleAstVisitor<Object> {
// TODO(brianwilkerson) Figure out whether the element can ever be
// something other than an ExportElement
_resolveCombinators(exportElement.exportedLibrary, node.combinators);
- setMetadata(exportElement, node);
+ resolveMetadata(node);
}
return null;
}
@override
Object visitFieldFormalParameter(FieldFormalParameter node) {
- _setMetadataForParameter(node.element, node);
+ _resolveMetadataForParameter(node.element, node);
return super.visitFieldFormalParameter(node);
}
@override
Object visitFunctionDeclaration(FunctionDeclaration node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@@ -455,13 +455,13 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitFunctionTypeAlias(FunctionTypeAlias node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@override
Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
- _setMetadataForParameter(node.element, node);
+ _resolveMetadataForParameter(node.element, node);
return null;
}
@@ -484,7 +484,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
if (library != null) {
_resolveCombinators(library, node.combinators);
}
- setMetadata(importElement, node);
+ resolveMetadata(node);
}
return null;
}
@@ -577,13 +577,13 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitLibraryDirective(LibraryDirective node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@override
Object visitMethodDeclaration(MethodDeclaration node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@@ -821,13 +821,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitPartDirective(PartDirective node) {
- setMetadata(node.element, node);
- return null;
- }
-
- @override
- Object visitPartOfDirective(PartOfDirective node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@@ -1029,7 +1023,7 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitSimpleFormalParameter(SimpleFormalParameter node) {
- _setMetadataForParameter(node.element, node);
+ _resolveMetadataForParameter(node.element, node);
return null;
}
@@ -1183,13 +1177,13 @@ class ElementResolver extends SimpleAstVisitor<Object> {
@override
Object visitTypeParameter(TypeParameter node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@override
Object visitVariableDeclaration(VariableDeclaration node) {
- setMetadata(node.element, node);
+ resolveMetadata(node);
return null;
}
@@ -2217,6 +2211,15 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
+ * Given a [node] that can have annotations associated with it, resolve the
+ * annotations in the element model representing annotations to the node.
+ */
+ void _resolveMetadataForParameter(
+ Element element, NormalFormalParameter node) {
+ _resolveAnnotations(node.metadata);
+ }
+
+ /**
* Given that we are accessing a property of the given [targetType] with the
* given [propertyName], return the element that represents the property. The
* [target] is the target of the invocation ('e').
@@ -2433,23 +2436,6 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
- * Given a [node] that can have annotations associated with it and the
- * [element] to which that node has been resolved, create the annotations in
- * the element model representing the annotations on the node.
- */
- void _setMetadataForParameter(Element element, NormalFormalParameter node) {
- if (element is! ElementImpl) {
- return;
- }
- List<ElementAnnotationImpl> annotationList =
- new List<ElementAnnotationImpl>();
- _addAnnotations(annotationList, node.metadata);
- if (!annotationList.isEmpty) {
- (element as ElementImpl).metadata = annotationList;
- }
- }
-
- /**
* Return `true` if we should report an error as a result of looking up a
* [member] in the given [type] and not finding any member.
*/
@@ -2476,48 +2462,21 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
/**
- * Given a [node] that can have annotations associated with it and the
- * [element] to which that node has been resolved, create the annotations in
- * the element model representing the annotations on the node.
+ * Given a [node] that can have annotations associated with it, resolve the
+ * annotations in the element model representing the annotations on the node.
*/
- static void setMetadata(Element element, AnnotatedNode node) {
- if (element is! ElementImpl) {
- return;
- }
- List<ElementAnnotationImpl> annotationList = <ElementAnnotationImpl>[];
- _addAnnotations(annotationList, node.metadata);
+ static void resolveMetadata(AnnotatedNode node) {
+ _resolveAnnotations(node.metadata);
if (node is VariableDeclaration && node.parent is VariableDeclarationList) {
VariableDeclarationList list = node.parent as VariableDeclarationList;
- _addAnnotations(annotationList, list.metadata);
+ _resolveAnnotations(list.metadata);
if (list.parent is FieldDeclaration) {
FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration;
- _addAnnotations(annotationList, fieldDeclaration.metadata);
+ _resolveAnnotations(fieldDeclaration.metadata);
} else if (list.parent is TopLevelVariableDeclaration) {
TopLevelVariableDeclaration variableDeclaration =
list.parent as TopLevelVariableDeclaration;
- _addAnnotations(annotationList, variableDeclaration.metadata);
- }
- }
- if (!annotationList.isEmpty) {
- (element as ElementImpl).metadata = annotationList;
- }
- }
-
- /**
- * Generate annotation elements for each of the annotations in the
- * [annotationList] and add them to the given list of [annotations].
- */
- static void _addAnnotations(List<ElementAnnotationImpl> annotationList,
- NodeList<Annotation> annotations) {
- int annotationCount = annotations.length;
- for (int i = 0; i < annotationCount; i++) {
- Annotation annotation = annotations[i];
- Element resolvedElement = annotation.element;
- if (resolvedElement != null) {
- ElementAnnotationImpl elementAnnotation =
- new ElementAnnotationImpl(resolvedElement);
- annotation.elementAnnotation = elementAnnotation;
- annotationList.add(elementAnnotation);
+ _resolveAnnotations(variableDeclaration.metadata);
}
}
}
@@ -2568,6 +2527,16 @@ class ElementResolver extends SimpleAstVisitor<Object> {
}
return false;
}
+
+ /**
+ * Resolve each of the annotations in the given list of [annotations].
+ */
+ static void _resolveAnnotations(NodeList<Annotation> annotations) {
+ for (Annotation annotation in annotations) {
+ ElementAnnotationImpl elementAnnotation = annotation.elementAnnotation;
+ elementAnnotation.element = annotation.element;
+ }
+ }
}
/**
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/lib/src/generated/incremental_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698