Skip to content

Commit d064073

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate UseResultVerifier.
Change-Id: I7e94dac09e52d548db43dd6060a9e8f10bf2a309 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395123 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 0015935 commit d064073

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ lib/src/error/nullable_dereference_verifier.dart
117117
lib/src/error/override_verifier.dart
118118
lib/src/error/required_parameters_verifier.dart
119119
lib/src/error/unused_local_elements_verifier.dart
120-
lib/src/error/use_result_verifier.dart
121120
lib/src/generated/element_resolver.dart
122121
lib/src/generated/element_walker.dart
123122
lib/src/generated/error_detection_helpers.dart

pkg/analyzer/lib/src/error/use_result_verifier.dart

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/ast/token.dart';
6-
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
77
import 'package:analyzer/error/listener.dart';
88
import 'package:analyzer/src/dart/ast/ast.dart';
99
import 'package:analyzer/src/error/codes.g.dart';
@@ -15,7 +15,7 @@ class UseResultVerifier {
1515
UseResultVerifier(this._errorReporter);
1616

1717
void checkFunctionExpressionInvocation(FunctionExpressionInvocation node) {
18-
var element = node.staticElement;
18+
var element = node.element;
1919
if (element == null) {
2020
return;
2121
}
@@ -24,7 +24,7 @@ class UseResultVerifier {
2424
}
2525

2626
void checkInstanceCreationExpression(InstanceCreationExpression node) {
27-
var element = node.constructorName.staticElement;
27+
var element = node.constructorName.element;
2828
if (element == null) {
2929
return;
3030
}
@@ -33,7 +33,7 @@ class UseResultVerifier {
3333
}
3434

3535
void checkMethodInvocation(MethodInvocation node) {
36-
var element = node.methodName.staticElement;
36+
var element = node.methodName.element;
3737
if (element == null) {
3838
return;
3939
}
@@ -42,7 +42,7 @@ class UseResultVerifier {
4242
}
4343

4444
void checkPropertyAccess(PropertyAccess node) {
45-
var element = node.propertyName.staticElement;
45+
var element = node.propertyName.element;
4646
if (element == null) {
4747
return;
4848
}
@@ -64,15 +64,15 @@ class UseResultVerifier {
6464
return;
6565
}
6666

67-
var element = node.staticElement;
67+
var element = node.element;
6868
if (element == null) {
6969
return;
7070
}
7171

7272
_check(node, element);
7373
}
7474

75-
void _check(AstNode node, Element element) {
75+
void _check(AstNode node, Element2 element) {
7676
var parent = node.parent;
7777
if (parent is PrefixedIdentifier) {
7878
parent = parent.parent;
@@ -123,7 +123,7 @@ class UseResultVerifier {
123123
}
124124

125125
String? _getUseResultMessage(ElementAnnotation annotation) {
126-
if (annotation.element is PropertyAccessorElement) {
126+
if (annotation.element2 is GetterElement) {
127127
return null;
128128
}
129129
var constantValue = annotation.computeConstantValue();
@@ -146,13 +146,13 @@ class UseResultVerifier {
146146
}
147147

148148
var argumentList = node.argumentList as ArgumentListImpl;
149-
var parameters = argumentList.correspondingStaticParameters;
149+
var parameters = argumentList.correspondingStaticParameters2;
150150
if (parameters == null) {
151151
return false;
152152
}
153153

154154
for (var param in parameters) {
155-
var name = param?.name;
155+
var name = param?.name3;
156156
if (unlessParam == name) {
157157
return true;
158158
}
@@ -174,16 +174,31 @@ class UseResultVerifier {
174174
return node;
175175
}
176176

177-
static ElementAnnotation? _getUseResultMetadata(Element element) {
177+
static ElementAnnotation? _getUseResultMetadata(Element2 element) {
178178
// Implicit getters/setters.
179-
if (element.isSynthetic && element is PropertyAccessorElement) {
180-
var variable = element.variable2;
181-
if (variable == null) {
182-
return null;
179+
if (element.isSynthetic) {
180+
switch (element) {
181+
case GetterElement getter:
182+
if (getter.variable3 case var variable?) {
183+
element = variable;
184+
} else {
185+
return null;
186+
}
187+
case SetterElement setter:
188+
if (setter.variable3 case var variable?) {
189+
element = variable;
190+
} else {
191+
return null;
192+
}
183193
}
184-
element = variable;
185194
}
186-
return element.metadata.firstWhereOrNull((e) => e.isUseResult);
195+
196+
if (element case Annotatable annotatable) {
197+
return annotatable.metadata2.annotations
198+
.firstWhereOrNull((e) => e.isUseResult);
199+
}
200+
201+
return null;
187202
}
188203

189204
static bool _isUsed(AstNode node) {

0 commit comments

Comments
 (0)