Skip to content

Commit 7190caf

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate visit_registered_nodes
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I0772342d6e18109d3ce162048bba857f93d139b3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390261 Auto-Submit: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 1bf5482 commit 7190caf

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ lib/src/rules/avoid_function_literals_in_foreach_calls.dart
2525
lib/src/rules/avoid_implementing_value_types.dart
2626
lib/src/rules/avoid_js_rounded_ints.dart
2727
lib/src/rules/avoid_multiple_declarations_per_line.dart
28+
lib/src/rules/avoid_null_checks_in_equality_operators.dart
2829
lib/src/rules/avoid_print.dart
2930
lib/src/rules/avoid_private_typedef_functions.dart
3031
lib/src/rules/avoid_relative_lib_imports.dart
@@ -105,6 +106,7 @@ lib/src/rules/prefer_conditional_assignment.dart
105106
lib/src/rules/prefer_const_constructors.dart
106107
lib/src/rules/prefer_const_declarations.dart
107108
lib/src/rules/prefer_const_literals_to_create_immutables.dart
109+
lib/src/rules/prefer_constructors_over_static_methods.dart
108110
lib/src/rules/prefer_contains.dart
109111
lib/src/rules/prefer_double_quotes.dart
110112
lib/src/rules/prefer_equal_for_default_values.dart
@@ -132,6 +134,7 @@ lib/src/rules/pub/depend_on_referenced_packages.dart
132134
lib/src/rules/pub/package_names.dart
133135
lib/src/rules/pub/secure_pubspec_urls.dart
134136
lib/src/rules/pub/sort_pub_dependencies.dart
137+
lib/src/rules/recursive_getters.dart
135138
lib/src/rules/require_trailing_commas.dart
136139
lib/src/rules/sized_box_for_whitespace.dart
137140
lib/src/rules/sized_box_shrink_expand.dart
@@ -227,7 +230,6 @@ test/rules/avoid_implementing_value_types_test.dart
227230
test/rules/avoid_init_to_null_test.dart
228231
test/rules/avoid_js_rounded_ints_test.dart
229232
test/rules/avoid_multiple_declarations_per_line_test.dart
230-
test/rules/avoid_null_checks_in_equality_operators_test.dart
231233
test/rules/avoid_positional_boolean_parameters_test.dart
232234
test/rules/avoid_print_test.dart
233235
test/rules/avoid_private_typedef_functions_test.dart
@@ -460,6 +462,7 @@ tool/checks/check_messages_yaml.dart
460462
tool/checks/driver.dart
461463
tool/checks/rules/no_solo_tests.dart
462464
tool/checks/rules/no_trailing_spaces.dart
465+
tool/checks/rules/visit_registered_nodes.dart
463466
tool/generate_lints.dart
464467
tool/labeler/issue_config.dart
465468
tool/labeler/pr_config.dart

pkg/linter/tool/checks/rules/visit_registered_nodes.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7-
import 'package:analyzer/dart/element/element.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
88
import 'package:analyzer/dart/element/type.dart';
99
import '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

3636
class _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

7572
class _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

Comments
 (0)