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/dart/element/type.dart' ;
99import 'package:linter/src/analyzer.dart' ;
1010
@@ -28,44 +28,41 @@ class VisitRegisteredNodes extends LintRule {
2828 @override
2929 void registerNodeProcessors (
3030 NodeLintRegistry registry, LinterContext context) {
31- var visitor = _Visitor (this );
31+ var visitor = _Visitor (this , context.inheritanceManager );
3232 registry.addMethodDeclaration (this , visitor);
3333 }
3434}
3535
3636class _BodyVisitor extends RecursiveAstVisitor <void > {
3737 final LintRule rule;
38- _BodyVisitor (this .rule);
38+ final InheritanceManager3 inheritanceManager;
39+ _BodyVisitor (this .rule, this .inheritanceManager);
3940
40- bool implements (ClassElement visitor, String methodName) {
41- if (visitor.getMethod (methodName) != null ) {
42- return true ;
43- }
44-
45- var method =
46- visitor.lookUpInheritedConcreteMethod (methodName, visitor.library);
41+ bool implements (ClassElement2 visitor, String methodName) {
42+ var member = inheritanceManager.getMember4 (visitor, Name (null , methodName),
43+ concrete: true );
4744 // In general lint visitors should only inherit from SimpleAstVisitors
4845 // (and the method implementations inherited from there are only stubs).
4946 // (We might consider enforcing this since it's harder to ensure that
5047 // Unifying and Generalizing visitors are doing the right thing.)
5148 // For now we flag methods inherited from SimpleAstVisitor since they
5249 // surely don't do anything.
53- return method ? .enclosingElement3 .name != 'SimpleAstVisitor' ;
50+ return member ? .enclosingElement2 ? .name != 'SimpleAstVisitor' ;
5451 }
5552
5653 @override
5754 void visitMethodInvocation (MethodInvocation node) {
5855 var targetType = node.target? .staticType;
5956 if (targetType is ! InterfaceType ) return ;
60- if (targetType.element .name != 'NodeLintRegistry' ) return ;
57+ if (targetType.element3 .name != 'NodeLintRegistry' ) return ;
6158 var methodName = node.methodName.name;
6259 if (! methodName.startsWith ('add' )) return ;
6360 var nodeType = methodName.substring (3 );
6461 var args = node.argumentList.arguments;
6562 var argType = args[1 ].staticType;
6663 if (argType is ! InterfaceType ) return ;
67- var visitor = argType.element ;
68- if (visitor is ! ClassElement ) return ;
64+ var visitor = argType.element3 ;
65+ if (visitor is ! ClassElement2 ) return ;
6966 if (implements (visitor, 'visit$nodeType ' )) return ;
7067
7168 rule.reportLint (node.methodName);
@@ -74,13 +71,14 @@ class _BodyVisitor extends RecursiveAstVisitor<void> {
7471
7572class _Visitor extends SimpleAstVisitor <void > {
7673 final LintRule rule;
74+ final InheritanceManager3 inheritanceManager;
7775
78- _Visitor (this .rule);
76+ _Visitor (this .rule, this .inheritanceManager );
7977
8078 @override
8179 void visitMethodDeclaration (MethodDeclaration node) {
8280 if (node.name.lexeme == 'registerNodeProcessors' ) {
83- node.body.accept (_BodyVisitor (rule));
81+ node.body.accept (_BodyVisitor (rule, inheritanceManager ));
8482 }
8583 }
8684}
0 commit comments