33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:analyzer/dart/ast/token.dart' ;
6- import 'package:analyzer/dart/element/element .dart' ;
6+ import 'package:analyzer/dart/element/element2 .dart' ;
77import 'package:analyzer/error/listener.dart' ;
88import 'package:analyzer/src/dart/ast/ast.dart' ;
99import '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