22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // ignore_for_file: analyzer_use_new_elements
6-
75import 'dart:collection' ;
86
97import 'package:_fe_analyzer_shared/src/exhaustiveness/dart_template_buffer.dart' ;
@@ -14,7 +12,7 @@ import 'package:analyzer/dart/analysis/features.dart';
1412import 'package:analyzer/dart/ast/token.dart' ;
1513import 'package:analyzer/dart/ast/visitor.dart' ;
1614import 'package:analyzer/dart/constant/value.dart' ;
17- import 'package:analyzer/dart/element/element .dart' ;
15+ import 'package:analyzer/dart/element/element2 .dart' ;
1816import 'package:analyzer/dart/element/nullability_suffix.dart' ;
1917import 'package:analyzer/dart/element/type.dart' ;
2018import 'package:analyzer/error/error.dart' ;
@@ -105,8 +103,8 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
105103 void visitAnnotation (Annotation node) {
106104 super .visitAnnotation (node);
107105 // check annotation creation
108- var element = node.element ;
109- if (element is ConstructorElement ) {
106+ var element = node.element2 ;
107+ if (element is ConstructorElement2 ) {
110108 // should be 'const' constructor
111109 if (! element.isConst) {
112110 _errorReporter.atNode (
@@ -170,7 +168,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
170168 // Check and report cycles.
171169 // Factory cycles are reported in elsewhere in
172170 // [ErrorVerifier._checkForRecursiveFactoryRedirect].
173- var element = node.declaredElement ;
171+ var element = node.declaredFragment ;
174172 if (element is ConstructorElementImpl &&
175173 ! element.isCycleFree &&
176174 ! element.isFactory) {
@@ -211,7 +209,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
211209 _validateConstantArguments (argumentList);
212210 }
213211
214- var element = node.declaredElement as ConstFieldElementImpl ;
212+ var element = node.declaredFragment as ConstFieldElementImpl ;
215213 var result = element.evaluationResult;
216214 if (result is InvalidConstant ) {
217215 _reportError (result, null );
@@ -480,11 +478,11 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
480478 super .visitVariableDeclaration (node);
481479 var initializer = node.initializer;
482480 if (initializer != null && (node.isConst || node.isFinal)) {
483- var element = node.declaredElement as VariableElementImpl ;
484- if (element is FieldElement && ! element.isStatic) {
485- var enclosingElement = element.enclosingElement3 ;
486- if (enclosingElement is ClassElementImpl &&
487- ! enclosingElement .hasGenerativeConstConstructor) {
481+ var element = node.declaredFragment as VariableElementImpl ;
482+ if (element is FieldElementImpl && ! element.isStatic) {
483+ var enclosingFragment = element.enclosingFragment ;
484+ if (enclosingFragment is ClassElementImpl &&
485+ ! enclosingFragment .hasGenerativeConstConstructor) {
488486 // TODO(kallentu): Evaluate if we need to do this check for inline
489487 // classes.
490488 //
@@ -529,7 +527,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
529527 ).eliminateToGreatest (valueType);
530528 return _typeSystem.isSubtypeOf (constantType, valueTypeGreatest);
531529 } else if (valueType is TypeParameterTypeImpl ) {
532- var bound = valueType.promotedBound ?? valueType.element .bound;
530+ var bound = valueType.promotedBound ?? valueType.element3 .bound;
533531 if (bound != null && ! hasTypeParameterReference (bound)) {
534532 var lowestBound =
535533 valueType.nullabilitySuffix == NullabilitySuffix .question
@@ -556,12 +554,12 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
556554 /// See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS] .
557555 void _checkForConstWithTypeParameters (
558556 TypeAnnotation type, ErrorCode errorCode,
559- {Set <TypeParameterElement >? allowedTypeParameters}) {
557+ {Set <TypeParameterElement2 >? allowedTypeParameters}) {
560558 allowedTypeParameters = {...? allowedTypeParameters};
561559 if (type is NamedType ) {
562560 // Should not be a type parameter.
563- if (type.element is TypeParameterElement &&
564- ! allowedTypeParameters.contains (type.element )) {
561+ if (type.element2 is TypeParameterElement2 &&
562+ ! allowedTypeParameters.contains (type.element2 )) {
565563 _errorReporter.atNode (
566564 type,
567565 errorCode,
@@ -580,7 +578,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
580578 var typeParameters = type.typeParameters;
581579 if (typeParameters != null ) {
582580 allowedTypeParameters.addAll (typeParameters.typeParameters
583- .map ((tp) => tp.declaredElement )
581+ .map ((tp) => tp.declaredFragment ! .element )
584582 .nonNulls);
585583 for (var typeParameter in typeParameters.typeParameters) {
586584 var bound = typeParameter.bound;
@@ -833,8 +831,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
833831 result = _evaluateAndReportError (
834832 defaultValue, CompileTimeErrorCode .NON_CONSTANT_DEFAULT_VALUE );
835833 }
836- VariableElementImpl element =
837- parameter.declaredElement as VariableElementImpl ;
834+ var element = parameter.declaredFragment as VariableElementImpl ;
838835 element.evaluationResult = result;
839836 }
840837 }
@@ -1512,7 +1509,7 @@ extension on Expression {
15121509 ! declarationListParent.isStatic) {
15131510 var container = declarationListParent.parent;
15141511 if (container is ClassDeclaration ) {
1515- var enclosingClass = container.declaredElement ;
1512+ var enclosingClass = container.declaredFragment ;
15161513 if (enclosingClass is ClassElementImpl ) {
15171514 // A field initializer of a class with at least one generative
15181515 // const constructor does not constitute a constant context, but
0 commit comments