Skip to content

Commit 7dee49e

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Turn ElementAnnotationImpl.element into a getter.
It is not useful to copy element from AST into ElementAnnotation. It is always the same. Change-Id: Id5a2bb90571cb992669e0c4181e07cfc0ebe2c11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441985 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent ff05b45 commit 7dee49e

File tree

4 files changed

+29
-100
lines changed

4 files changed

+29
-100
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,9 +1509,6 @@ class ElementAnnotationImpl
15091509
static const String _visibleOutsideTemplateVariableName =
15101510
'visibleOutsideTemplate';
15111511

1512-
@override
1513-
Element? element;
1514-
15151512
@override
15161513
LibraryFragmentImpl libraryFragment;
15171514

@@ -1560,6 +1557,9 @@ class ElementAnnotationImpl
15601557
return additionalErrors ?? const <Diagnostic>[];
15611558
}
15621559

1560+
@override
1561+
Element? get element => annotationAst.element;
1562+
15631563
@override
15641564
@Deprecated('Use element instead')
15651565
Element? get element2 => element;

pkg/analyzer/lib/src/generated/element_resolver.dart

Lines changed: 25 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,9 @@ class ElementResolver {
109109

110110
TypeProviderImpl get _typeProvider => _resolver.typeProvider;
111111

112-
void visitClassDeclaration(ClassDeclaration node) {
113-
_resolveAnnotations(node.metadata);
114-
}
112+
void visitClassDeclaration(ClassDeclaration node) {}
115113

116-
void visitClassTypeAlias(ClassTypeAlias node) {
117-
_resolveAnnotations(node.metadata);
118-
}
114+
void visitClassTypeAlias(ClassTypeAlias node) {}
119115

120116
void visitCommentReference(CommentReference node) {
121117
_commentReferenceResolver.resolve(node);
@@ -137,7 +133,6 @@ class ElementResolver {
137133
}
138134
}
139135
}
140-
_resolveAnnotations(node.metadata);
141136
}
142137

143138
void visitConstructorName(covariant ConstructorNameImpl node) {
@@ -161,9 +156,7 @@ class ElementResolver {
161156
}
162157
}
163158

164-
void visitDeclaredIdentifier(DeclaredIdentifier node) {
165-
_resolveAnnotations(node.metadata);
166-
}
159+
void visitDeclaredIdentifier(DeclaredIdentifier node) {}
167160

168161
void visitDotShorthandConstructorInvocation(
169162
covariant DotShorthandConstructorInvocationImpl node,
@@ -197,13 +190,9 @@ class ElementResolver {
197190
);
198191
}
199192

200-
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {
201-
_resolveAnnotations(node.metadata);
202-
}
193+
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {}
203194

204-
void visitEnumDeclaration(EnumDeclaration node) {
205-
_resolveAnnotations(node.metadata);
206-
}
195+
void visitEnumDeclaration(EnumDeclaration node) {}
207196

208197
void visitExportDirective(ExportDirectiveImpl node) {
209198
var exportElement = node.libraryExport;
@@ -212,41 +201,24 @@ class ElementResolver {
212201
// TODO(brianwilkerson): Figure out whether the element can ever be
213202
// something other than an ExportElement
214203
_resolveCombinators(exportElement.exportedLibrary, node.combinators);
215-
_resolveAnnotations(node.metadata);
216204
}
217205
}
218206

219-
void visitExtensionDeclaration(ExtensionDeclaration node) {
220-
_resolveAnnotations(node.metadata);
221-
}
207+
void visitExtensionDeclaration(ExtensionDeclaration node) {}
222208

223-
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
224-
_resolveAnnotations(node.metadata);
225-
}
209+
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {}
226210

227-
void visitFieldDeclaration(FieldDeclaration node) {
228-
_resolveAnnotations(node.metadata);
229-
}
211+
void visitFieldDeclaration(FieldDeclaration node) {}
230212

231-
void visitFieldFormalParameter(FieldFormalParameter node) {
232-
_resolveMetadataForParameter(node);
233-
}
213+
void visitFieldFormalParameter(FieldFormalParameter node) {}
234214

235-
void visitFunctionDeclaration(FunctionDeclaration node) {
236-
_resolveAnnotations(node.metadata);
237-
}
215+
void visitFunctionDeclaration(FunctionDeclaration node) {}
238216

239-
void visitFunctionTypeAlias(FunctionTypeAlias node) {
240-
_resolveAnnotations(node.metadata);
241-
}
217+
void visitFunctionTypeAlias(FunctionTypeAlias node) {}
242218

243-
void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
244-
_resolveMetadataForParameter(node);
245-
}
219+
void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {}
246220

247-
void visitGenericTypeAlias(GenericTypeAlias node) {
248-
_resolveAnnotations(node.metadata);
249-
}
221+
void visitGenericTypeAlias(GenericTypeAlias node) {}
250222

251223
void visitImportDirective(covariant ImportDirectiveImpl node) {
252224
var prefixNode = node.prefix;
@@ -269,7 +241,6 @@ class ElementResolver {
269241
if (library != null) {
270242
_resolveCombinators(library, node.combinators);
271243
}
272-
_resolveAnnotations(node.metadata);
273244
}
274245
}
275246

@@ -287,13 +258,9 @@ class ElementResolver {
287258
}
288259
}
289260

290-
void visitLibraryDirective(LibraryDirective node) {
291-
_resolveAnnotations(node.metadata);
292-
}
261+
void visitLibraryDirective(LibraryDirective node) {}
293262

294-
void visitMethodDeclaration(MethodDeclaration node) {
295-
_resolveAnnotations(node.metadata);
296-
}
263+
void visitMethodDeclaration(MethodDeclaration node) {}
297264

298265
/// Resolves the method invocation, [node].
299266
///
@@ -312,29 +279,19 @@ class ElementResolver {
312279
);
313280
}
314281

315-
void visitMixinDeclaration(MixinDeclaration node) {
316-
_resolveAnnotations(node.metadata);
317-
}
282+
void visitMixinDeclaration(MixinDeclaration node) {}
318283

319-
void visitPartDirective(PartDirective node) {
320-
_resolveAnnotations(node.metadata);
321-
}
284+
void visitPartDirective(PartDirective node) {}
322285

323-
void visitPartOfDirective(PartOfDirective node) {
324-
_resolveAnnotations(node.metadata);
325-
}
286+
void visitPartOfDirective(PartOfDirective node) {}
326287

327288
void visitRecordTypeAnnotationNamedField(
328289
RecordTypeAnnotationNamedField node,
329-
) {
330-
_resolveAnnotations(node.metadata);
331-
}
290+
) {}
332291

333292
void visitRecordTypeAnnotationPositionalField(
334293
RecordTypeAnnotationPositionalField node,
335-
) {
336-
_resolveAnnotations(node.metadata);
337-
}
294+
) {}
338295

339296
void visitRedirectingConstructorInvocation(
340297
covariant RedirectingConstructorInvocationImpl node,
@@ -367,13 +324,9 @@ class ElementResolver {
367324
}
368325
}
369326

370-
void visitRepresentationDeclaration(RepresentationDeclaration node) {
371-
_resolveAnnotations(node.fieldMetadata);
372-
}
327+
void visitRepresentationDeclaration(RepresentationDeclaration node) {}
373328

374-
void visitSimpleFormalParameter(SimpleFormalParameter node) {
375-
_resolveMetadataForParameter(node);
376-
}
329+
void visitSimpleFormalParameter(SimpleFormalParameter node) {}
377330

378331
void visitSuperConstructorInvocation(
379332
covariant SuperConstructorInvocationImpl node,
@@ -466,17 +419,11 @@ class ElementResolver {
466419
}
467420
}
468421

469-
void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
470-
_resolveAnnotations(node.metadata);
471-
}
422+
void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {}
472423

473-
void visitTypeParameter(TypeParameter node) {
474-
_resolveAnnotations(node.metadata);
475-
}
424+
void visitTypeParameter(TypeParameter node) {}
476425

477-
void visitVariableDeclarationList(VariableDeclarationList node) {
478-
_resolveAnnotations(node.metadata);
479-
}
426+
void visitVariableDeclarationList(VariableDeclarationList node) {}
480427

481428
/// Given an [argumentList] and the [executableElement] that will be invoked
482429
/// using those argument, compute the list of parameters that correspond to
@@ -538,21 +485,4 @@ class ElementResolver {
538485
}
539486
}
540487
}
541-
542-
/// Given a [node] that can have annotations associated with it, resolve the
543-
/// annotations in the element model representing annotations to the node.
544-
void _resolveMetadataForParameter(NormalFormalParameter node) {
545-
_resolveAnnotations(node.metadata);
546-
}
547-
548-
/// Resolve each of the annotations in the given list of [annotations].
549-
static void _resolveAnnotations(NodeList<Annotation> annotations) {
550-
for (Annotation annotation in annotations) {
551-
var elementAnnotation =
552-
annotation.elementAnnotation as ElementAnnotationImpl?;
553-
if (elementAnnotation != null) {
554-
elementAnnotation.element = annotation.element;
555-
}
556-
}
557-
}
558488
}

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ class ResolutionReader {
18631863
currentLibraryFragment = unitElement;
18641864
var annotations = readTypedList(() {
18651865
var ast = _readRequiredNode() as AnnotationImpl;
1866-
return ElementAnnotationImpl(unitElement, ast)..element = ast.element;
1866+
return ElementAnnotationImpl(unitElement, ast);
18671867
});
18681868

18691869
return MetadataImpl(annotations);

pkg/analyzer/lib/src/summary2/metadata_resolver.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class MetadataResolver extends ThrowingAstVisitor<void> {
3535
analysisOptions,
3636
);
3737
astResolver.resolveAnnotation(node);
38-
annotationElement.element = node.element;
3938
}
4039
}
4140

0 commit comments

Comments
 (0)