Skip to content

Commit 8ea4215

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ConstantFinder (tweaks).
Change-Id: I2dd82490fd5439f0dfaea6d2047969526197fb09 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415383 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 892ea15 commit 8ea4215

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

pkg/analyzer/lib/src/dart/constant/utilities.dart

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:collection';
66

77
import 'package:analyzer/dart/ast/visitor.dart';
8-
import 'package:analyzer/dart/element/element2.dart';
98
import 'package:analyzer/src/dart/ast/ast.dart';
109
import 'package:analyzer/src/dart/constant/evaluation.dart';
1110
import 'package:analyzer/src/dart/element/element.dart';
@@ -173,7 +172,8 @@ class ConstantFinder extends RecursiveAstVisitor<void> {
173172

174173
@override
175174
void visitEnumConstantDeclaration(
176-
covariant EnumConstantDeclarationImpl node) {
175+
covariant EnumConstantDeclarationImpl node,
176+
) {
177177
super.visitEnumConstantDeclaration(node);
178178

179179
var element = node.declaredFragment!;
@@ -222,11 +222,13 @@ class ReferenceFinder extends RecursiveAstVisitor<void> {
222222
ReferenceFinder(this._callback);
223223

224224
@override
225-
void visitInstanceCreationExpression(InstanceCreationExpression node) {
225+
void visitInstanceCreationExpression(
226+
covariant InstanceCreationExpressionImpl node,
227+
) {
226228
if (node.isConst) {
227229
var constructor = node.constructorName.element?.baseElement;
228230
if (constructor != null && constructor.isConst) {
229-
_callback(constructor.firstFragment as ConstructorElementImpl);
231+
_callback(constructor.firstFragment);
230232
}
231233
}
232234
super.visitInstanceCreationExpression(node);
@@ -243,33 +245,35 @@ class ReferenceFinder extends RecursiveAstVisitor<void> {
243245

244246
@override
245247
void visitRedirectingConstructorInvocation(
246-
RedirectingConstructorInvocation node) {
248+
covariant RedirectingConstructorInvocationImpl node,
249+
) {
247250
super.visitRedirectingConstructorInvocation(node);
248251
var target = node.element?.baseElement;
249252
if (target != null) {
250-
_callback(target.firstFragment as ConstructorElementImpl);
253+
_callback(target.firstFragment);
251254
}
252255
}
253256

254257
@override
255258
void visitSimpleIdentifier(SimpleIdentifier node) {
256-
var staticElement = node.element;
257-
var element = staticElement is GetterElement
258-
? staticElement.variable3
259-
: staticElement is SetterElement
260-
? staticElement.variable3
261-
: staticElement;
262-
if (element is VariableElement2 && element.isConst) {
259+
var element = node.element;
260+
if (element is GetterElementImpl) {
261+
element = element.variable3;
262+
}
263+
264+
if (element is VariableElementImpl2 && element.isConst) {
263265
_callback(element.firstFragment as VariableElementImpl);
264266
}
265267
}
266268

267269
@override
268-
void visitSuperConstructorInvocation(SuperConstructorInvocation node) {
270+
void visitSuperConstructorInvocation(
271+
covariant SuperConstructorInvocationImpl node,
272+
) {
269273
super.visitSuperConstructorInvocation(node);
270274
var constructor = node.element?.baseElement;
271275
if (constructor != null) {
272-
_callback(constructor.firstFragment as ConstructorElementImpl);
276+
_callback(constructor.firstFragment);
273277
}
274278
}
275279
}

pkg/analyzer/lib/src/utilities/extensions/element.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ extension ConstructorElementExtension on ConstructorElement {
117117
}
118118

119119
extension ConstructorElementImpl2Extension on ConstructorElementImpl2 {
120-
ConstructorElementMixin get asElement {
121-
if (this case ConstructorMember member) {
122-
return member;
123-
}
120+
ConstructorElementImpl get asElement {
124121
return lastFragment;
125122
}
126123
}

0 commit comments

Comments
 (0)