44
55import 'package:analyzer/dart/ast/ast.dart' ;
66import 'package:analyzer/dart/ast/visitor.dart' ;
7- import 'package:analyzer/dart/element/element .dart' ;
7+ import 'package:analyzer/dart/element/element2 .dart' ;
88
99import '../analyzer.dart' ;
1010
@@ -18,7 +18,7 @@ bool _isFormalParameterReassigned(
1818 FormalParameter parameter, AssignmentExpression assignment) {
1919 var leftHandSide = assignment.leftHandSide;
2020 return leftHandSide is SimpleIdentifier &&
21- leftHandSide.staticElement == parameter.declaredElement ;
21+ leftHandSide.element == parameter.declaredFragment ? .element ;
2222}
2323
2424class ParameterAssignments extends LintRule {
@@ -51,7 +51,7 @@ class _DeclarationVisitor extends RecursiveAstVisitor<void> {
5151 {required this .paramIsNotNullByDefault,
5252 required this .paramDefaultsToNull});
5353
54- Element ? get parameterElement => parameter.declaredElement ;
54+ Element2 ? get parameterElement => parameter.declaredFragment ? .element ;
5555
5656 void checkPatternElements (DartPattern node) {
5757 NodeList <PatternField >? fields;
@@ -112,8 +112,7 @@ class _DeclarationVisitor extends RecursiveAstVisitor<void> {
112112 visitPostfixExpression (PostfixExpression node) {
113113 if (paramIsNotNullByDefault) {
114114 var operand = node.operand;
115- if (operand is SimpleIdentifier &&
116- operand.staticElement == parameterElement) {
115+ if (operand is SimpleIdentifier && operand.element == parameterElement) {
117116 reportLint (node);
118117 }
119118 }
@@ -125,8 +124,7 @@ class _DeclarationVisitor extends RecursiveAstVisitor<void> {
125124 visitPrefixExpression (PrefixExpression node) {
126125 if (paramIsNotNullByDefault) {
127126 var operand = node.operand;
128- if (operand is SimpleIdentifier &&
129- operand.staticElement == parameterElement) {
127+ if (operand is SimpleIdentifier && operand.element == parameterElement) {
130128 reportLint (node);
131129 }
132130 }
@@ -155,9 +153,9 @@ class _Visitor extends SimpleAstVisitor<void> {
155153 if (parameterList == null ) return ;
156154
157155 for (var parameter in parameterList.parameters) {
158- var declaredElement = parameter.declaredElement ;
156+ var declaredElement = parameter.declaredFragment ? .element ;
159157 if (declaredElement != null &&
160- body.isPotentiallyMutatedInScope (declaredElement)) {
158+ body.isPotentiallyMutatedInScope2 (declaredElement)) {
161159 var paramIsNotNullByDefault = parameter is SimpleFormalParameter ||
162160 _isDefaultFormalParameterWithDefaultValue (parameter);
163161 var paramDefaultsToNull = parameter is DefaultFormalParameter &&
@@ -173,9 +171,8 @@ class _Visitor extends SimpleAstVisitor<void> {
173171}
174172
175173extension on AstNode {
176- Element ? get element {
177- var self = this ;
178- if (self is AssignedVariablePattern ) return self.element;
179- return null ;
180- }
174+ Element2 ? get element => switch (this ) {
175+ AssignedVariablePattern (: var element2) => element2,
176+ _ => null ,
177+ };
181178}
0 commit comments