55import 'package:analyzer/dart/ast/ast.dart' ;
66import 'package:analyzer/dart/ast/token.dart' ;
77import 'package:analyzer/dart/ast/visitor.dart' ;
8- import 'package:analyzer/dart/element/element .dart' ;
8+ import 'package:analyzer/dart/element/element2 .dart' ;
99// ignore: implementation_imports
1010import 'package:analyzer/src/dart/resolver/exit_detector.dart' ;
1111// ignore: implementation_imports
1212import 'package:analyzer/src/lint/constants.dart' ;
13- // ignore: implementation_imports
14- import 'package:analyzer/src/utilities/extensions/element.dart' ;
1513import 'package:collection/collection.dart' ;
1614import 'package:meta/meta.dart' ;
1715import 'package:pub_semver/pub_semver.dart' ;
@@ -58,7 +56,7 @@ class AsyncStateTracker {
5856 ///
5957 /// [reference] must be a direct child of `this` , or a sibling of `this`
6058 /// in a List of [AstNode] s.
61- AsyncState ? asyncStateFor (AstNode reference, Element mountedElement) {
59+ AsyncState ? asyncStateFor (AstNode reference, Element2 mountedElement) {
6260 _asyncStateVisitor.setReference (reference, mountedElement);
6361 var parent = reference.parent;
6462 if (parent == null ) return null ;
@@ -128,7 +126,7 @@ class AsyncStateVisitor extends SimpleAstVisitor<AsyncState> {
128126 ///
129127 /// Generally speaking, this is `State.mounted` when [_reference] refers to
130128 /// `State.context` , and this is `BuildContext.mounted` otherwise.
131- late Element _mountedElement;
129+ late Element2 _mountedElement;
132130
133131 final Map <AstNode , AsyncState ?> _stateCache = {};
134132
@@ -151,7 +149,7 @@ class AsyncStateVisitor extends SimpleAstVisitor<AsyncState> {
151149
152150 /// Sets [_reference] and [_mountedElement] , readying the visitor to accept
153151 /// nodes.
154- void setReference (AstNode reference, Element mountedElement) {
152+ void setReference (AstNode reference, Element2 mountedElement) {
155153 _reference = reference;
156154 _mountedElement = mountedElement;
157155 }
@@ -776,7 +774,7 @@ class AsyncStateVisitor extends SimpleAstVisitor<AsyncState> {
776774 /// attempted mounted check (using an unrelated element).
777775 AsyncState ? _visitIdentifier (SimpleIdentifier node) {
778776 if (node.name != mountedName) return null ;
779- if (node.staticElement ? .declaration == _mountedElement) {
777+ if (node.element ? .baseElement == _mountedElement) {
780778 return AsyncState .mountedCheck;
781779 }
782780
@@ -1016,7 +1014,7 @@ class _Visitor extends SimpleAstVisitor<void> {
10161014
10171015 _Visitor (this .rule);
10181016
1019- void check (Expression node, Element mountedElement) {
1017+ void check (Expression node, Element2 mountedElement) {
10201018 // Checks each of the statements before `child` for a `mounted` check, and
10211019 // returns whether it did not find one (and the caller should keep looking).
10221020
@@ -1112,12 +1110,12 @@ class _Visitor extends SimpleAstVisitor<void> {
11121110 var namedArguments = arguments.whereType <NamedExpression >().toList ();
11131111
11141112 var target = invocation.realTarget;
1115- var targetElement = target is Identifier ? target.staticElement : null ;
1116- if (targetElement is ClassElement ) {
1113+ var targetElement = target is Identifier ? target.element : null ;
1114+ if (targetElement is ClassElement2 ) {
11171115 // Static function called; `target` is the class.
11181116 for (var method in protectedStaticMethods) {
11191117 if (invocation.methodName.name == method.name &&
1120- targetElement.name == method.type) {
1118+ targetElement.name3 == method.type) {
11211119 checkPositionalArguments (
11221120 method.positional, positionalArguments, callback, errorNode);
11231121 checkNamedArguments (
@@ -1129,7 +1127,7 @@ class _Visitor extends SimpleAstVisitor<void> {
11291127 if (staticType == null ) return ;
11301128 for (var method in protectedInstanceMethods) {
11311129 if (invocation.methodName.name == method.name &&
1132- staticType.element ? .name == method.type) {
1130+ staticType.element3 ? .name3 == method.type) {
11331131 checkPositionalArguments (
11341132 method.positional, positionalArguments, callback, errorNode);
11351133 checkNamedArguments (
@@ -1270,7 +1268,7 @@ extension on BinaryExpression {
12701268
12711269extension on Expression {
12721270 /// The element of this expression, if it is typed as a BuildContext.
1273- Element ? get buildContextTypedElement {
1271+ Element2 ? get buildContextTypedElement {
12741272 var self = this ;
12751273 if (self is NamedExpression ) {
12761274 self = self.expression;
@@ -1280,20 +1278,20 @@ extension on Expression {
12801278 }
12811279
12821280 if (self is Identifier ) {
1283- var element = self.staticElement ;
1281+ var element = self.element ;
12841282 if (element == null ) {
12851283 return null ;
12861284 }
12871285
1288- var declaration = element.declaration ;
1286+ var declaration = element.baseElement ;
12891287 // Get the declaration to ensure checks from un-migrated libraries work.
12901288 var argType = switch (declaration) {
1291- ExecutableElement () => declaration.returnType,
1292- VariableElement () => declaration.type,
1289+ ExecutableElement2 () => declaration.returnType,
1290+ VariableElement2 () => declaration.type,
12931291 _ => null ,
12941292 };
12951293
1296- var isGetter = element is PropertyAccessorElement ;
1294+ var isGetter = element is PropertyAccessorElement2 ;
12971295 if (isBuildContext (argType, skipNullable: isGetter)) {
12981296 return declaration;
12991297 }
@@ -1332,33 +1330,32 @@ extension on Expression {
13321330}
13331331
13341332@visibleForTesting
1335- extension ElementExtension on Element {
1333+ extension ElementExtension on Element2 {
13361334 /// The `mounted` getter which is associated with `this` , if this static
13371335 /// element is `BuildContext` from Flutter.
1338- Element ? get associatedMountedGetter {
1336+ Element2 ? get associatedMountedGetter {
13391337 var self = this ;
13401338
1341- if (self is PropertyAccessorElement ) {
1342- var enclosingElement = self.enclosingElement3;
1343- if (enclosingElement is InterfaceElement &&
1344- isState (enclosingElement.asElement2)) {
1339+ if (self is PropertyAccessorElement2 ) {
1340+ var enclosingElement = self.enclosingElement2;
1341+ if (enclosingElement is InterfaceElement2 && isState (enclosingElement)) {
13451342 // The BuildContext object is the field on Flutter's State class.
13461343 // This object can only be guarded by async gaps with a mounted
13471344 // check on the State.
1348- return enclosingElement.augmented
1349- . lookUpGetter ( name: 'mounted' , library: enclosingElement.library );
1345+ return enclosingElement.lookUpGetter2 (
1346+ name: 'mounted' , library: enclosingElement.library2 );
13501347 }
13511348 }
13521349
13531350 var buildContextElement = switch (self) {
1354- ExecutableElement () => self.returnType,
1355- VariableElement () => self.type,
1351+ ExecutableElement2 () => self.returnType,
1352+ VariableElement2 () => self.type,
13561353 _ => null ,
13571354 }
1358- ? .element ;
1359- if (buildContextElement is InterfaceElement ) {
1360- return buildContextElement.augmented
1361- . lookUpGetter ( name: 'mounted' , library: buildContextElement.library );
1355+ ? .element3 ;
1356+ if (buildContextElement is InterfaceElement2 ) {
1357+ return buildContextElement.lookUpGetter2 (
1358+ name: 'mounted' , library: buildContextElement.library2 );
13621359 }
13631360
13641361 return null ;
0 commit comments