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' ;
88import 'package:analyzer/error/listener.dart' ;
99import 'package:analyzer/src/dart/element/inheritance_manager3.dart' ;
1010import 'package:analyzer/src/error/codes.dart' ;
@@ -16,22 +16,17 @@ class RedeclareVerifier extends RecursiveAstVisitor<void> {
1616 /// The inheritance manager used to find redeclared members.
1717 final InheritanceManager3 _inheritance;
1818
19- /// The URI of the library being verified.
20- final Uri _libraryUri;
21-
2219 /// The error reporter used to report errors.
2320 final ErrorReporter _errorReporter;
2421
2522 /// The current extension type.
26- InterfaceElement ? _currentExtensionType;
23+ InterfaceElement2 ? _currentExtensionType;
2724
28- RedeclareVerifier (
29- this ._inheritance, LibraryElement library, this ._errorReporter)
30- : _libraryUri = library.source.uri;
25+ RedeclareVerifier (this ._inheritance, this ._errorReporter);
3126
3227 @override
3328 void visitExtensionTypeDeclaration (ExtensionTypeDeclaration node) {
34- _currentExtensionType = node.declaredElement ;
29+ _currentExtensionType = node.declaredFragment ! .element ;
3530 super .visitExtensionTypeDeclaration (node);
3631 _currentExtensionType = null ;
3732 }
@@ -41,49 +36,48 @@ class RedeclareVerifier extends RecursiveAstVisitor<void> {
4136 // Only check if we're in an extension type declaration.
4237 if (_currentExtensionType == null ) return ;
4338
44- var element = node.declaredElement ! ;
39+ var element = node.declaredFragment ! .element ;
4540
4641 // Static members can't redeclare.
4742 if (element.isStatic) return ;
4843
49- if (element.hasRedeclare && ! _redeclaresMember (element)) {
50- if (element is MethodElement ) {
51- _errorReporter. atToken (
52- node.name,
53- WarningCode . REDECLARE_ON_NON_REDECLARING_MEMBER ,
54- arguments : [
55- 'method' ,
56- ] ,
57- );
58- } else if (element is PropertyAccessorElement ) {
59- if (element.isGetter) {
44+ if (element.metadata2. hasRedeclare && ! _redeclaresMember (element)) {
45+ switch (element) {
46+ case MethodElement2 () :
47+ _errorReporter. atToken (
48+ node.name ,
49+ WarningCode . REDECLARE_ON_NON_REDECLARING_MEMBER ,
50+ arguments : [
51+ 'method' ,
52+ ],
53+ );
54+ case GetterElement () :
6055 _errorReporter.atToken (
6156 node.name,
6257 WarningCode .REDECLARE_ON_NON_REDECLARING_MEMBER ,
6358 arguments: [
6459 'getter' ,
6560 ],
6661 );
67- } else {
62+ case SetterElement () :
6863 _errorReporter.atToken (
6964 node.name,
7065 WarningCode .REDECLARE_ON_NON_REDECLARING_MEMBER ,
7166 arguments: [
7267 'setter' ,
7368 ],
7469 );
75- }
7670 }
7771 }
7872 }
7973
8074 /// Return `true` if the [member] redeclares a member from a superinterface.
81- bool _redeclaresMember (ExecutableElement member) {
75+ bool _redeclaresMember (ExecutableElement2 member) {
8276 var currentType = _currentExtensionType;
8377 if (currentType != null ) {
84- var interface = _inheritance.getInterface (currentType);
85- var redeclared = interface .redeclared ;
86- var name = Name (_libraryUri, member.name );
78+ var interface = _inheritance.getInterface2 (currentType);
79+ var redeclared = interface .redeclared2 ;
80+ var name = Name . forElement ( member);
8781 return redeclared.containsKey (name);
8882 }
8983
0 commit comments