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' ;
1010import '../extensions.dart' ;
@@ -38,12 +38,12 @@ abstract class _AbstractUnnecessaryOverrideVisitor
3838
3939 /// If [declaration] is an inherited member of interest, then this is set in
4040 /// [visitMethodDeclaration] .
41- late ExecutableElement _inheritedMethod;
41+ late ExecutableElement2 _inheritedMethod;
4242 late MethodDeclaration declaration;
4343
4444 _AbstractUnnecessaryOverrideVisitor (this .rule);
4545
46- ExecutableElement ? getInheritedElement (MethodDeclaration node);
46+ ExecutableElement2 ? getInheritedElement (MethodDeclaration node);
4747
4848 @override
4949 void visitBlock (Block node) {
@@ -112,11 +112,13 @@ abstract class _AbstractUnnecessaryOverrideVisitor
112112 /// Returns whether [declaration] is annotated with any metadata (other than
113113 /// `@override` or `@Override` ).
114114 bool _addsMetadata () {
115- var metadata = declaration.declaredElement ? .metadata ;
115+ var metadata = declaration.declaredFragment ? .element.metadata2 ;
116116 if (metadata != null ) {
117- for (var annotation in metadata) {
117+ for (var annotation in metadata.annotations ) {
118118 if (annotation.isOverride) continue ;
119- if (annotation.isProtected && _inheritedMethod.hasProtected) continue ;
119+ if (annotation.isProtected && _inheritedMethod.metadata2.hasProtected) {
120+ continue ;
121+ }
120122
121123 // Any other annotation implies a meaningful override.
122124 return true ;
@@ -126,22 +128,22 @@ abstract class _AbstractUnnecessaryOverrideVisitor
126128 }
127129
128130 bool _haveSameDeclaration () {
129- var declaredElement = declaration.declaredElement ;
131+ var declaredElement = declaration.declaredFragment ? .element ;
130132 if (declaredElement == null ) {
131133 return false ;
132134 }
133135 if (declaredElement.returnType != _inheritedMethod.returnType) {
134136 return false ;
135137 }
136- if (declaredElement.parameters .length !=
137- _inheritedMethod.parameters .length) {
138+ if (declaredElement.formalParameters .length !=
139+ _inheritedMethod.formalParameters .length) {
138140 return false ;
139141 }
140- for (var i = 0 ; i < _inheritedMethod.parameters .length; i++ ) {
141- var superParam = _inheritedMethod.parameters [i];
142- var param = declaredElement.parameters [i];
142+ for (var i = 0 ; i < _inheritedMethod.formalParameters .length; i++ ) {
143+ var superParam = _inheritedMethod.formalParameters [i];
144+ var param = declaredElement.formalParameters [i];
143145 if (param.type != superParam.type) return false ;
144- if (param.name != superParam.name ) return false ;
146+ if (param.name3 != superParam.name3 ) return false ;
145147 if (param.isCovariant != superParam.isCovariant) return false ;
146148 if (! _sameKind (param, superParam)) return false ;
147149 if (param.defaultValueCode != superParam.defaultValueCode) return false ;
@@ -155,15 +157,15 @@ abstract class _AbstractUnnecessaryOverrideVisitor
155157 /// This indicates that [_inheritedMethod] may have been overridden in order
156158 /// to expand its visibility.
157159 bool _makesPublicFromProtected () {
158- var declaredElement = declaration.declaredElement ;
160+ var declaredElement = declaration.declaredFragment ? .element ;
159161 if (declaredElement == null ) return false ;
160- if (declaredElement.hasProtected) {
162+ if (declaredElement.metadata2. hasProtected) {
161163 return false ;
162164 }
163- return _inheritedMethod.hasProtected;
165+ return _inheritedMethod.metadata2. hasProtected;
164166 }
165167
166- bool _sameKind (ParameterElement first, ParameterElement second) {
168+ bool _sameKind (FormalParameterElement first, FormalParameterElement second) {
167169 if (first.isRequired) {
168170 return second.isRequired;
169171 } else if (first.isOptionalPositional) {
@@ -180,22 +182,24 @@ class _UnnecessaryGetterOverrideVisitor
180182 _UnnecessaryGetterOverrideVisitor (super .rule);
181183
182184 @override
183- ExecutableElement ? getInheritedElement (MethodDeclaration node) {
184- var element = node.declaredElement ;
185+ ExecutableElement2 ? getInheritedElement (MethodDeclaration node) {
186+ var element = node.declaredFragment ? .element ;
185187 if (element == null ) return null ;
186- var enclosingElement = element.enclosingElement3;
187- if (enclosingElement is ! InterfaceElement ) return null ;
188- return enclosingElement.thisType.lookUpGetter2 (
189- element.name,
190- element.library,
188+ var enclosingElement = element.enclosingElement2;
189+ if (enclosingElement is ! InterfaceElement2 ) return null ;
190+ var getterName = element.name3;
191+ if (getterName == null ) return null ;
192+ return enclosingElement.thisType.lookUpGetter3 (
193+ getterName,
194+ element.library2,
191195 concrete: true ,
192196 inherited: true ,
193197 );
194198 }
195199
196200 @override
197201 void visitPropertyAccess (PropertyAccess node) {
198- if (node.propertyName.name == _inheritedMethod.name ) {
202+ if (node.propertyName.name == _inheritedMethod.name3 ) {
199203 node.target? .accept (this );
200204 }
201205 }
@@ -206,17 +210,16 @@ class _UnnecessaryMethodOverrideVisitor
206210 _UnnecessaryMethodOverrideVisitor (super .rule);
207211
208212 @override
209- ExecutableElement ? getInheritedElement (node) {
210- var element = node.declaredElement ;
213+ ExecutableElement2 ? getInheritedElement (node) {
214+ var element = node.declaredFragment ? .element ;
211215 if (element == null ) return null ;
212216
213- var enclosingElement = element.enclosingElement3 ;
214- if (enclosingElement is ! InterfaceElement ) return null ;
217+ var enclosingElement = element.enclosingElement2 ;
218+ if (enclosingElement is ! InterfaceElement2 ) return null ;
215219
216- var augmented = enclosingElement.augmented ;
217- return augmented .firstFragment.thisType.lookUpMethod2 (
220+ return enclosingElement.firstFragment.element.thisType.lookUpMethod3 (
218221 node.name.lexeme,
219- element.library ,
222+ element.library2 ,
220223 concrete: true ,
221224 inherited: true ,
222225 );
@@ -226,7 +229,7 @@ class _UnnecessaryMethodOverrideVisitor
226229 void visitMethodInvocation (MethodInvocation node) {
227230 var declarationParameters = declaration.parameters;
228231 if (declarationParameters != null &&
229- node.methodName.name == _inheritedMethod.name &&
232+ node.methodName.name == _inheritedMethod.name3 &&
230233 argumentsMatchParameters (
231234 node.argumentList.arguments, declarationParameters.parameters)) {
232235 node.target? .accept (this );
@@ -239,14 +242,16 @@ class _UnnecessaryOperatorOverrideVisitor
239242 _UnnecessaryOperatorOverrideVisitor (super .rule);
240243
241244 @override
242- ExecutableElement ? getInheritedElement (node) {
243- var element = node.declaredElement ;
245+ ExecutableElement2 ? getInheritedElement (node) {
246+ var element = node.declaredFragment ? .element ;
244247 if (element == null ) return null ;
245- var enclosingElement = element.enclosingElement3;
246- if (enclosingElement is ! InterfaceElement ) return null ;
247- return enclosingElement.thisType.lookUpMethod2 (
248- element.name,
249- element.library,
248+ var enclosingElement = element.enclosingElement2;
249+ if (enclosingElement is ! InterfaceElement2 ) return null ;
250+ var methodName = element.name3;
251+ if (methodName == null ) return null ;
252+ return enclosingElement.thisType.lookUpMethod3 (
253+ methodName,
254+ element.library2,
250255 concrete: true ,
251256 inherited: true ,
252257 );
@@ -258,8 +263,8 @@ class _UnnecessaryOperatorOverrideVisitor
258263 if (node.operator .type == declaration.name.type &&
259264 parameters != null &&
260265 parameters.length == 1 &&
261- parameters.first.declaredElement ==
262- node.rightOperand.canonicalElement ) {
266+ parameters.first.declaredFragment ? .element ==
267+ node.rightOperand.canonicalElement2 ) {
263268 var leftPart = node.leftOperand.unParenthesized;
264269 if (leftPart is SuperExpression ) {
265270 visitSuperExpression (leftPart);
@@ -286,14 +291,14 @@ class _UnnecessarySetterOverrideVisitor
286291 _UnnecessarySetterOverrideVisitor (super .rule);
287292
288293 @override
289- ExecutableElement ? getInheritedElement (node) {
290- var element = node.declaredElement ;
294+ ExecutableElement2 ? getInheritedElement (node) {
295+ var element = node.declaredFragment ? .element ;
291296 if (element == null ) return null ;
292- var enclosingElement = element.enclosingElement3 ;
293- if (enclosingElement is ! InterfaceElement ) return null ;
294- return enclosingElement.thisType.lookUpSetter2 (
297+ var enclosingElement = element.enclosingElement2 ;
298+ if (enclosingElement is ! InterfaceElement2 ) return null ;
299+ return enclosingElement.thisType.lookUpSetter3 (
295300 node.name.lexeme,
296- element.library ,
301+ element.library2 ,
297302 concrete: true ,
298303 inherited: true ,
299304 );
@@ -304,11 +309,11 @@ class _UnnecessarySetterOverrideVisitor
304309 var parameters = declaration.parameters? .parameters;
305310 if (parameters != null &&
306311 parameters.length == 1 &&
307- parameters.first.declaredElement ==
308- node.rightHandSide.canonicalElement ) {
312+ parameters.first.declaredFragment ? .element ==
313+ node.rightHandSide.canonicalElement2 ) {
309314 var leftPart = node.leftHandSide.unParenthesized;
310315 if (leftPart is PropertyAccess ) {
311- if (node.writeElement ? .name == _inheritedMethod.name ) {
316+ if (node.writeElement2 ? .name3 == _inheritedMethod.name3 ) {
312317 leftPart.target? .accept (this );
313318 }
314319 }
0 commit comments