diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart index ecb2e4db55b..73700370836 100644 --- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart +++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart @@ -929,7 +929,7 @@ class LibraryAnalyzer { void _resolveLibraryExportDirective({ required ExportDirectiveImpl directive, - required LibraryExportElement element, + required LibraryExportElementImpl element, required LibraryExportState state, required ErrorReporter errorReporter, }) { @@ -983,7 +983,7 @@ class LibraryAnalyzer { void _resolveLibraryImportDirective({ required ImportDirectiveImpl directive, - required LibraryImportElement element, + required LibraryImportElementImpl element, required LibraryImportState state, required ErrorReporter errorReporter, }) { @@ -1013,7 +1013,7 @@ class LibraryAnalyzer { void _resolvePartDirective({ required PartDirectiveImpl directive, required PartState partState, - required PartElement partElement, + required PartElementImpl partElement, required ErrorReporter errorReporter, required LibraryIdentifier? libraryNameNode, required Set seenPartSources, diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart index b575ba97747..b4bdb311015 100644 --- a/pkg/analyzer/lib/src/dart/ast/ast.dart +++ b/pkg/analyzer/lib/src/dart/ast/ast.dart @@ -303,7 +303,7 @@ final class AnnotationImpl extends AstNodeImpl implements Annotation { /// The element annotation representing this annotation in the element model. @override - ElementAnnotation? elementAnnotation; + ElementAnnotationImpl? elementAnnotation; /// Initialize a newly created annotation. Both the [period] and the /// [constructorName] can be `null` if the annotation is not referencing a @@ -5323,7 +5323,7 @@ sealed class Directive implements AnnotatedNode { sealed class DirectiveImpl extends AnnotatedNodeImpl implements Directive { /// The element associated with this directive, or `null` if the AST structure /// has not been resolved or if this directive could not be resolved. - Element? _element; + ElementImpl? _element; /// Initialize a newly create directive. Either or both of the [comment] and /// [metadata] can be `null` if the directive does not have the corresponding @@ -5334,10 +5334,10 @@ sealed class DirectiveImpl extends AnnotatedNodeImpl implements Directive { }); @override - Element? get element => _element; + ElementImpl? get element => _element; /// Set the element associated with this directive to be the given [element]. - set element(Element? element) { + set element(ElementImpl? element) { _element = element; } } @@ -13805,8 +13805,8 @@ final class PartDirectiveImpl extends UriBasedDirectiveImpl }); @override - PartElement? get element { - return super.element as PartElement?; + PartElementImpl? get element { + return super.element as PartElementImpl?; } @override @@ -15458,7 +15458,7 @@ final class RepresentationDeclarationImpl extends AstNodeImpl final Token leftParenthesis; @override - final NodeListImpl fieldMetadata = NodeListImpl._(); + final NodeListImpl fieldMetadata = NodeListImpl._(); @override final TypeAnnotationImpl fieldType; diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index 216baed3e5b..a0cc4a2a6f7 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -173,7 +173,7 @@ abstract class AugmentedInstanceElementImpl @override // TODO(scheglov): implement metadata - List get metadata => throw UnimplementedError(); + List get metadata => throw UnimplementedError(); } abstract class AugmentedInterfaceElementImpl @@ -860,7 +860,7 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl ElementKind get kind => ElementKind.COMPILATION_UNIT; @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -1913,7 +1913,7 @@ abstract class ElementImpl implements Element { int _modifiers = 0; /// A list containing all of the metadata associated with this element. - List _metadata = const []; + List _metadata = const []; /// Cached flags denoting presence of specific annotations in [_metadata]. int _metadataFlags = 0; @@ -2162,8 +2162,7 @@ abstract class ElementImpl implements Element { final metadata = this.metadata; for (var i = 0; i < metadata.length; i++) { var annotation = metadata[i]; - if (annotation is ElementAnnotationImpl && - annotation.isPragmaVmEntryPoint) { + if (annotation.isPragmaVmEntryPoint) { return true; } } @@ -2340,11 +2339,11 @@ abstract class ElementImpl implements Element { } @override - List get metadata { + List get metadata { return _metadata; } - set metadata(List metadata) { + set metadata(List metadata) { _metadata = metadata; } @@ -2804,7 +2803,7 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl bool get isSynchronous => !isAsynchronous; @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -2942,7 +2941,7 @@ class ExtensionElementImpl extends InstanceElementImpl ElementKind get kind => ElementKind.EXTENSION; @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -3122,7 +3121,7 @@ class FieldElementImpl extends PropertyInducingElementImpl ElementKind get kind => ElementKind.FIELD; @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -3402,7 +3401,7 @@ abstract class InstanceElementImpl extends _ExistingElementImpl } @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -4326,7 +4325,7 @@ class LibraryElementImpl extends LibraryOrAugmentationElementImpl } @override - List get metadata { + List get metadata { _readLinkedData(); return super.metadata; } @@ -5635,7 +5634,9 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement { ElementLocation? get location => null; @override - List get metadata => const []; + List get metadata { + return const []; + } @override int get nameLength => 0; @@ -5843,7 +5844,7 @@ abstract class NotAugmentedInstanceElementImpl } @override - List get metadata { + List get metadata { return element.metadata; } @@ -6319,7 +6320,7 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl } @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -6727,7 +6728,7 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl ElementKind get kind => ElementKind.TOP_LEVEL_VARIABLE; @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } @@ -6834,7 +6835,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl } @override - List get metadata { + List get metadata { linkedData?.read(this); return super.metadata; } diff --git a/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart b/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart index 2a5f242a1c3..576bbaa1738 100644 --- a/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart +++ b/pkg/analyzer/lib/src/dart/element/since_sdk_version.dart @@ -52,7 +52,6 @@ class SinceSdkVersionComputer { static Version? _specifiedVersion(ElementImpl element) { Version? result; for (final annotation in element.metadata) { - annotation as ElementAnnotationImpl; if (annotation.isDartInternalSince) { final arguments = annotation.annotationAst.arguments?.arguments; final versionNode = arguments?.singleOrNull; diff --git a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart index 91f306d1c37..5a64bd84583 100644 --- a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart +++ b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart @@ -201,7 +201,9 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitAugmentationImportDirective(AugmentationImportDirective node) { + void visitAugmentationImportDirective( + covariant AugmentationImportDirectiveImpl node, + ) { final element = node.element; if (element is AugmentationImportElementImpl) { _setOrCreateMetadataElements(element, node.metadata); @@ -547,7 +549,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitExportDirective(ExportDirective node) { + void visitExportDirective(covariant ExportDirectiveImpl node) { var element = node.element; if (element is LibraryExportElementImpl) { _setOrCreateMetadataElements(element, node.metadata); @@ -938,7 +940,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitImportDirective(ImportDirective node) { + void visitImportDirective(covariant ImportDirectiveImpl node) { var element = node.element; if (element is LibraryImportElementImpl) { _setOrCreateMetadataElements(element, node.metadata); @@ -1000,7 +1002,9 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitLibraryAugmentationDirective(LibraryAugmentationDirective node) { + void visitLibraryAugmentationDirective( + covariant LibraryAugmentationDirectiveImpl node, + ) { final element = node.element; if (element is LibraryOrAugmentationElementImpl) { _setOrCreateMetadataElements(element, node.metadata); @@ -1012,7 +1016,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitLibraryDirective(LibraryDirective node) { + void visitLibraryDirective(covariant LibraryDirectiveImpl node) { ++_libraryDirectiveIndex; var element = node.element; if (element is LibraryElementImpl && _libraryDirectiveIndex == 1) { @@ -1117,7 +1121,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitPartDirective(PartDirective node) { + void visitPartDirective(covariant PartDirectiveImpl node) { var element = node.element; if (element is PartElementImpl) { _setOrCreateMetadataElements(element, node.metadata); @@ -1374,7 +1378,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitTypeParameter(TypeParameter node) { + void visitTypeParameter(covariant TypeParameterImpl node) { var element = node.declaredElement as TypeParameterElementImpl; _setOrCreateMetadataElements(element, node.metadata); @@ -1416,7 +1420,9 @@ class ResolutionVisitor extends RecursiveAstVisitor { } @override - void visitVariableDeclarationList(VariableDeclarationList node) { + void visitVariableDeclarationList( + covariant VariableDeclarationListImpl node, + ) { var parent = node.parent; if (parent is ForPartsWithDeclarations || parent is VariableDeclarationStatement && @@ -1426,10 +1432,10 @@ class ResolutionVisitor extends RecursiveAstVisitor { node.visitChildren(this); - NodeList annotations; - if (parent is FieldDeclaration) { + NodeList annotations; + if (parent is FieldDeclarationImpl) { annotations = parent.metadata; - } else if (parent is TopLevelVariableDeclaration) { + } else if (parent is TopLevelVariableDeclarationImpl) { annotations = parent.metadata; } else { // Local variable declaration @@ -1764,7 +1770,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { void _setOrCreateMetadataElements( ElementImpl element, - NodeList annotations, { + NodeList annotations, { bool visitNodes = true, }) { if (visitNodes) { @@ -1888,7 +1894,9 @@ class ResolutionVisitor extends RecursiveAstVisitor { /// Associate each of the annotation [nodes] with the corresponding /// [ElementAnnotation] in [annotations]. static void _setElementAnnotations( - List nodes, List annotations) { + List nodes, + List annotations, + ) { int nodeCount = nodes.length; if (nodeCount != annotations.length) { throw StateError( @@ -1897,7 +1905,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { ); } for (int i = 0; i < nodeCount; i++) { - (nodes[i] as AnnotationImpl).elementAnnotation = annotations[i]; + nodes[i].elementAnnotation = annotations[i]; } } } diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index c6714aadd41..4f4a462f614 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -6373,7 +6373,6 @@ class _MacroDiagnosticsReporter { static AnnotationImpl _annotationNode(ElementImpl element, int index) { var annotation = element.metadata[index]; - annotation as ElementAnnotationImpl; return annotation.annotationAst; } diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart index 957dd53b628..3089f091fda 100644 --- a/pkg/analyzer/lib/src/summary2/element_builder.dart +++ b/pkg/analyzer/lib/src/summary2/element_builder.dart @@ -58,7 +58,7 @@ class ElementBuilder extends ThrowingAstVisitor { } /// Build exports and imports, metadata into [_container]. - void buildLibraryElementChildren(CompilationUnit unit) { + void buildLibraryElementChildren(CompilationUnitImpl unit) { unit.directives.accept(this); if (_isFirstLibraryDirective) { @@ -1246,7 +1246,7 @@ class ElementBuilder extends ThrowingAstVisitor { node.mixinTypes.accept(this); } - List _buildAnnotations(List nodeList) { + List _buildAnnotations(List nodeList) { return _buildAnnotationsWithUnit(_unitElement, nodeList); } @@ -1465,16 +1465,16 @@ class ElementBuilder extends ThrowingAstVisitor { } } - static List _buildAnnotationsWithUnit( + static List _buildAnnotationsWithUnit( CompilationUnitElementImpl unitElement, List nodeList, ) { var length = nodeList.length; if (length == 0) { - return const []; + return const []; } - return List.generate(length, (index) { + return List.generate(length, (index) { var ast = nodeList[index] as AnnotationImpl; var element = ElementAnnotationImpl(unitElement); element.annotationAst = ast; diff --git a/pkg/analyzer/lib/src/summary2/macro_merge.dart b/pkg/analyzer/lib/src/summary2/macro_merge.dart index ef903827adb..11842f0770c 100644 --- a/pkg/analyzer/lib/src/summary2/macro_merge.dart +++ b/pkg/analyzer/lib/src/summary2/macro_merge.dart @@ -324,7 +324,6 @@ class MacroUpdateConstantsForOptimizedCode { void addElement(ElementImpl element) { for (var annotation in element.metadata) { - annotation as ElementAnnotationImpl; result.add((element, annotation.annotationAst)); }