55import 'dart:math' as math;
66
77import 'package:analyzer/dart/analysis/features.dart' ;
8- import 'package:analyzer/dart/ast/ast.dart' ;
98import 'package:analyzer/dart/ast/visitor.dart' ;
10- import 'package:analyzer/dart/element/element.dart' ;
9+ import 'package:analyzer/dart/element/element2.dart' ;
10+ // ignore: implementation_imports
11+ import 'package:analyzer/src/dart/ast/ast.dart' ;
1112
1213import '../analyzer.dart' ;
1314import '../extensions.dart' ;
@@ -29,7 +30,8 @@ class AvoidRenamingMethodParameters extends LintRule {
2930 NodeLintRegistry registry, LinterContext context) {
3031 if (! context.isInLibDir) return ;
3132
32- var visitor = _Visitor (this , context.libraryElement);
33+ var visitor =
34+ _Visitor (this , context.libraryElement2, context.inheritanceManager);
3335 registry.addMethodDeclaration (this , visitor);
3436 }
3537}
@@ -38,9 +40,11 @@ class _Visitor extends SimpleAstVisitor<void> {
3840 /// Whether the `wildcard_variables` feature is enabled.
3941 final bool _wildCardVariablesEnabled;
4042
43+ final InheritanceManager3 inheritanceManager;
44+
4145 final LintRule rule;
4246
43- _Visitor (this .rule, LibraryElement ? library)
47+ _Visitor (this .rule, LibraryElement2 ? library, this .inheritanceManager )
4448 : _wildCardVariablesEnabled =
4549 library? .featureSet.isEnabled (Feature .wildcard_variables) ?? false ;
4650
@@ -52,50 +56,47 @@ class _Visitor extends SimpleAstVisitor<void> {
5256 if (node.isStatic) return ;
5357 if (node.documentationComment != null ) return ;
5458
55- var parentNode = node.parent;
56- if (parentNode is ! Declaration ) {
57- return ;
58- }
59- var parentElement = parentNode.declaredElement;
60- // Note: there are no override semantics with extension methods.
61- if (parentElement is ! InterfaceElement ) {
62- return ;
63- }
59+ var nodeParams = node.parameters;
60+ if (nodeParams == null ) return ;
6461
65- var classElement = parentElement ;
62+ late List < FormalParameterElement > parentParameters ;
6663
67- if (classElement.isPrivate) return ;
64+ var previousFragment = node.declaredFragment? .previousFragment;
65+ if (previousFragment == null ) {
66+ // If it's the first fragment, check for an inherited member.
67+ var parentNode = node.parent;
68+ if (parentNode is ! Declaration ) return ;
6869
69- var parentMethod = classElement.lookUpInheritedMethod (
70- node.name.lexeme, classElement.library);
70+ var parentElement = parentNode.declaredFragment? .element;
7171
72- // If it's not an inherited method, check for an augmentation.
73- if (parentMethod == null && node.isAugmentation) {
74- var element = node.declaredElement;
75- // Note that we only require an augmentation to conform to the previous
76- // declaration/augmentation in the chain.
77- var target = element? .augmentationTarget;
78- if (target is MethodElement ) {
79- parentMethod = target;
80- }
81- }
72+ // Note: there are no override semantics with extension methods.
73+ if (parentElement is ! InterfaceElement2 ) return ;
74+ if (parentElement.isPrivate) return ;
8275
83- if (parentMethod == null ) return ;
76+ var parentMethod = inheritanceManager.getMember4 (
77+ parentElement, Name (parentElement.library2.uri, node.name.lexeme),
78+ forSuper: true );
79+ if (parentMethod == null ) return ;
8480
85- var nodeParams = node.parameters;
86- if (nodeParams == null ) {
87- return ;
81+ parentParameters = parentMethod.formalParameters.positional;
82+ } else {
83+ if (! node.isAugmentation) return ;
84+
85+ parentParameters =
86+ previousFragment.formalParameters.map ((p) => p.element).positional;
8887 }
8988
9089 var parameters = nodeParams.parameters.where ((p) => ! p.isNamed).toList ();
91- var parentParameters =
92- parentMethod.parameters.where ((p) => ! p.isNamed).toList ();
90+
9391 var count = math.min (parameters.length, parentParameters.length);
9492 for (var i = 0 ; i < count; i++ ) {
9593 if (parentParameters.length <= i) break ;
9694
97- var parentParameterName = parentParameters[i].name;
98- if (isWildcardIdentifier (parentParameterName)) continue ;
95+ var parentParameterName = parentParameters[i].name3;
96+ if (parentParameterName == null ||
97+ isWildcardIdentifier (parentParameterName)) {
98+ continue ;
99+ }
99100
100101 var parameterName = parameters[i].name;
101102 if (parameterName == null ) continue ;
@@ -110,3 +111,8 @@ class _Visitor extends SimpleAstVisitor<void> {
110111 }
111112 }
112113}
114+
115+ extension on Iterable <FormalParameterElement > {
116+ List <FormalParameterElement > get positional =>
117+ where ((p) => ! p.isNamed).toList ();
118+ }
0 commit comments