Skip to content

Commit e0e4b41

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

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
lib/src/ast.dart
22
lib/src/extensions.dart
3-
lib/src/rules/analyzer_use_new_elements.dart
43
lib/src/rules/avoid_renaming_method_parameters.dart
54
lib/src/rules/avoid_setters_without_getters.dart
6-
lib/src/rules/avoid_types_as_parameter_names.dart
75
lib/src/rules/avoid_void_async.dart
86
lib/src/rules/deprecated_member_use_from_same_package.dart
97
lib/src/rules/invalid_runtime_check_with_js_interop_types.dart
@@ -12,7 +10,6 @@ lib/src/rules/prefer_final_fields.dart
1210
lib/src/rules/prefer_initializing_formals.dart
1311
lib/src/rules/public_member_api_docs.dart
1412
lib/src/rules/unnecessary_overrides.dart
15-
lib/src/rules/unnecessary_this.dart
1613
lib/src/rules/use_build_context_synchronously.dart
1714
lib/src/rules/use_key_in_widget_constructors.dart
1815
lib/src/rules/use_late_for_private_fields_and_variables.dart

pkg/linter/lib/src/rules/unnecessary_this.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

99
import '../analyzer.dart';
1010
import '../ast.dart';
@@ -49,11 +49,11 @@ class _Visitor extends SimpleAstVisitor<void> {
4949
void visitThisExpression(ThisExpression node) {
5050
var parent = node.parent;
5151

52-
Element? element;
52+
Element2? element;
5353
if (parent is PropertyAccess && !parent.isNullAware) {
54-
element = getWriteOrReadElement(parent.propertyName);
54+
element = getWriteOrReadElement2(parent.propertyName);
5555
} else if (parent is MethodInvocation && !parent.isNullAware) {
56-
element = parent.methodName.staticElement;
56+
element = parent.methodName.element;
5757
} else {
5858
return;
5959
}
@@ -63,25 +63,23 @@ class _Visitor extends SimpleAstVisitor<void> {
6363
}
6464
}
6565

66-
bool _canReferenceElementWithoutThisPrefix(Element? element, AstNode node) {
67-
if (element == null) {
68-
return false;
69-
}
66+
bool _canReferenceElementWithoutThisPrefix(Element2? element, AstNode node) {
67+
if (element == null) return false;
7068

7169
var id = element.displayName;
72-
var isSetter = element is PropertyAccessorElement && element.isSetter;
73-
var result = resolveNameInScope(id, node, shouldResolveSetter: isSetter);
70+
var result = resolveNameInScope(id, node,
71+
shouldResolveSetter: element is SetterElement);
7472

7573
// No result, definitely no shadowing.
7674
// The requested element is inherited, or from an extension.
77-
if (result.isNone) {
78-
return true;
79-
}
75+
if (result.isNone) return true;
76+
77+
var resultElement = result.element2;
8078

8179
// The result has the matching name, might be shadowing.
8280
// Check that the element is the same.
8381
if (result.isRequestedName) {
84-
return result.element == element;
82+
return resultElement == element;
8583
}
8684

8785
// The result has the same basename, but not the same name.
@@ -90,8 +88,8 @@ class _Visitor extends SimpleAstVisitor<void> {
9088
// - prevents us from going up to the library scope;
9189
// - the requested element must be inherited, or from an extension.
9290
if (result.isDifferentName) {
93-
var enclosing = result.element?.enclosingElement3;
94-
return enclosing is ClassElement;
91+
var enclosing = resultElement?.enclosingElement2;
92+
return enclosing is ClassElement2;
9593
}
9694

9795
// Should not happen.

0 commit comments

Comments
 (0)