Skip to content

Commit d2a32e5

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

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

pkg/linter/lib/src/rules/diagnostic_describe_all_properties.dart

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/token.dart';
77
import 'package:analyzer/dart/ast/visitor.dart';
8-
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:analyzer/dart/element/element2.dart';
99
import 'package:analyzer/dart/element/type.dart';
1010

1111
import '../analyzer.dart';
@@ -27,7 +27,7 @@ class DiagnosticDescribeAllProperties extends LintRule {
2727
@override
2828
void registerNodeProcessors(
2929
NodeLintRegistry registry, LinterContext context) {
30-
var visitor = _Visitor(this, context);
30+
var visitor = _Visitor(this, context.inheritanceManager);
3131
registry.addClassDeclaration(this, visitor);
3232
}
3333
}
@@ -60,39 +60,37 @@ class _IdentifierVisitor extends RecursiveAstVisitor<void> {
6060

6161
class _Visitor extends SimpleAstVisitor<void> {
6262
final LintRule rule;
63-
final LinterContext context;
63+
final InheritanceManager3 inheritanceManager;
6464

65-
_Visitor(this.rule, this.context);
65+
_Visitor(this.rule, this.inheritanceManager);
6666

6767
void removeReferences(MethodDeclaration? method, List<Token> properties) {
6868
method?.body.accept(_IdentifierVisitor(properties));
6969
}
7070

71-
bool skipForDiagnostic({Element? element, DartType? type, Token? name}) =>
71+
bool skipForDiagnostic({Element2? element, DartType? type, Token? name}) =>
7272
name.isPrivate || _isOverridingMember(element) || isWidgetProperty(type);
7373

7474
@override
7575
void visitClassDeclaration(ClassDeclaration node) {
7676
// We only care about Diagnosticables.
7777
var type = node.declaredElement?.thisType;
78-
if (!type.implementsInterface('Diagnosticable', '')) {
79-
return;
80-
}
78+
if (!type.implementsInterface('Diagnosticable', '')) return;
8179

8280
var properties = <Token>[];
8381
for (var member in node.members) {
8482
if (member is MethodDeclaration && member.isGetter) {
8583
if (!member.isStatic &&
8684
!skipForDiagnostic(
87-
element: member.declaredElement,
85+
element: member.declaredFragment?.element,
8886
name: member.name,
8987
type: member.returnType?.type,
9088
)) {
9189
properties.add(member.name);
9290
}
9391
} else if (member is FieldDeclaration) {
9492
for (var v in member.fields.variables) {
95-
var declaredElement = v.declaredElement;
93+
var declaredElement = v.declaredFragment?.element;
9694
if (declaredElement != null &&
9795
!declaredElement.isStatic &&
9896
!skipForDiagnostic(
@@ -106,9 +104,7 @@ class _Visitor extends SimpleAstVisitor<void> {
106104
}
107105
}
108106

109-
if (properties.isEmpty) {
110-
return;
111-
}
107+
if (properties.isEmpty) return;
112108

113109
var debugFillProperties = node.members.getMethod('debugFillProperties');
114110
var debugDescribeChildren = node.members.getMethod('debugDescribeChildren');
@@ -123,23 +119,16 @@ class _Visitor extends SimpleAstVisitor<void> {
123119
properties.forEach(rule.reportLintForToken);
124120
}
125121

126-
bool _isOverridingMember(Element? member) {
127-
if (member == null) {
128-
return false;
129-
}
122+
bool _isOverridingMember(Element2? member) {
123+
if (member == null) return false;
124+
125+
var classElement = member.thisOrAncestorOfType2<InterfaceElement2>();
126+
if (classElement == null) return false;
130127

131-
var classElement = member.thisOrAncestorOfType<ClassElement>();
132-
if (classElement == null) {
133-
return false;
134-
}
135128
var name = member.name;
136-
if (name == null) {
137-
return false;
138-
}
129+
if (name == null) return false;
139130

140-
var libraryUri = classElement.library.source.uri;
141-
return context.inheritanceManager
142-
.getInherited(classElement.thisType, Name(libraryUri, name)) !=
131+
return inheritanceManager.getInherited4(classElement, Name(null, name)) !=
143132
null;
144133
}
145134
}

0 commit comments

Comments
 (0)