@@ -33,7 +33,6 @@ import 'package:analyzer/src/error/codes.dart';
3333import 'package:analyzer/src/generated/engine.dart' ;
3434import 'package:analyzer/src/generated/java_core.dart' ;
3535import 'package:analyzer/src/utilities/extensions/collection.dart' ;
36- import 'package:analyzer/src/utilities/extensions/element.dart' ;
3736import 'package:analyzer/src/utilities/extensions/object.dart' ;
3837
3938class ConstantEvaluationConfiguration {
@@ -92,8 +91,8 @@ class ConstantEvaluationEngine {
9291 }
9392
9493 var library = constant.library as LibraryElementImpl ;
95- if (constant is FormalParameterFragmentImpl ) {
96- var defaultValue = constant.constantInitializer ;
94+ if (constant is FormalParameterElementImpl ) {
95+ var defaultValue = constant.constantInitializer2 ? .expression ;
9796 if (defaultValue != null ) {
9897 var diagnosticListener = RecordingDiagnosticListener ();
9998 var diagnosticReporter = DiagnosticReporter (
@@ -110,8 +109,8 @@ class ConstantEvaluationEngine {
110109 } else {
111110 constant.evaluationResult = _nullObject (library);
112111 }
113- } else if (constant is VariableFragmentImpl ) {
114- var constantInitializer = constant.constantInitializer ;
112+ } else if (constant is VariableElementImpl ) {
113+ var constantInitializer = constant.constantInitializer2 ? .expression ;
115114 if (constantInitializer != null ) {
116115 var diagnosticReporter = DiagnosticReporter (
117116 RecordingDiagnosticListener (),
@@ -154,10 +153,7 @@ class ConstantEvaluationEngine {
154153 }
155154
156155 // Associate with the variable.
157- dartConstant = DartObjectImpl .forVariable (
158- dartConstant,
159- constant.element,
160- );
156+ dartConstant = DartObjectImpl .forVariable (dartConstant, constant);
161157 }
162158
163159 var enumConstant = _enumConstant (constant);
@@ -185,10 +181,9 @@ class ConstantEvaluationEngine {
185181 if (element is PropertyAccessorElement ) {
186182 // The annotation is a reference to a compile-time constant variable.
187183 // Just copy the evaluation result.
188- var variableElement = element.variable3? .baseElement;
189- var firstFragment =
190- variableElement? .firstFragment as VariableFragmentImpl ? ;
191- var evaluationResult = firstFragment? .evaluationResult;
184+ var variableElement =
185+ element.variable3? .baseElement as VariableElementImpl ? ;
186+ var evaluationResult = variableElement? .evaluationResult;
192187 if (evaluationResult != null ) {
193188 constant.evaluationResult = evaluationResult;
194189 } else {
@@ -250,13 +245,13 @@ class ConstantEvaluationEngine {
250245 ConstantEvaluationTarget constant,
251246 ReferenceFinderCallback callback,
252247 ) {
253- if (constant is FieldFragmentImpl && constant.isEnumConstant) {
254- var enclosing = constant.enclosingElement3 ;
255- if (enclosing is EnumFragmentImpl ) {
256- if (enclosing.name2 == 'values' ) {
248+ if (constant is FieldElementImpl && constant.isEnumConstant) {
249+ var enclosing = constant.enclosingElement ;
250+ if (enclosing is EnumElementImpl ) {
251+ if (enclosing.name3 == 'values' ) {
257252 return ;
258253 }
259- if (constant.name2 == enclosing.name2 ) {
254+ if (constant.name3 == enclosing.name3 ) {
260255 return ;
261256 }
262257 }
@@ -267,9 +262,9 @@ class ConstantEvaluationEngine {
267262 constant = constructor.baseElement;
268263 }
269264
270- if (constant is VariableElementOrMember ) {
271- var declaration = constant.declaration ;
272- var initializer = declaration.constantInitializer ;
265+ if (constant is VariableElementImpl ) {
266+ var declaration = constant;
267+ var initializer = declaration.constantInitializer2 ? .expression ;
273268 if (initializer != null ) {
274269 initializer.accept (referenceFinder);
275270 }
@@ -318,11 +313,11 @@ class ConstantEvaluationEngine {
318313 if ((field.isFinal || field.isConst) &&
319314 ! field.isStatic &&
320315 field.hasInitializer) {
321- callback (field.firstFragment );
316+ callback (field);
322317 }
323318 }
324319 for (var parameterElement in constant.formalParameters) {
325- callback (parameterElement.firstFragment as ParameterElementMixin );
320+ callback (parameterElement.baseElement );
326321 }
327322 }
328323 } else if (constant is ElementAnnotationImpl ) {
@@ -333,7 +328,7 @@ class ConstantEvaluationEngine {
333328 // so it depends on the variable.
334329 if (element.variable3 case var variable? ) {
335330 var baseElement = variable.baseElement as VariableElementImpl ;
336- callback (baseElement.firstFragment as VariableFragmentImpl );
331+ callback (baseElement);
337332 }
338333 } else if (element is ConstructorElement ) {
339334 // The annotation is a constructor invocation, so it depends on the
@@ -443,7 +438,7 @@ class ConstantEvaluationEngine {
443438 Iterable <ConstantEvaluationTarget > cycle,
444439 ConstantEvaluationTarget constant,
445440 ) {
446- if (constant is VariableFragmentImpl ) {
441+ if (constant is VariableElementImpl ) {
447442 DiagnosticReporter diagnosticReporter = DiagnosticReporter (
448443 RecordingDiagnosticListener (),
449444 constant.source! ,
@@ -452,11 +447,11 @@ class ConstantEvaluationEngine {
452447 // information from the 'cycle' argument to provide the user with a
453448 // description of the cycle.
454449 diagnosticReporter.atElement2 (
455- constant.asElement2 ! ,
450+ constant,
456451 CompileTimeErrorCode .RECURSIVE_COMPILE_TIME_CONSTANT ,
457452 );
458453 constant.evaluationResult = InvalidConstant .forElement (
459- element: constant.asElement2 ! ,
454+ element: constant,
460455 diagnosticCode: CompileTimeErrorCode .RECURSIVE_COMPILE_TIME_CONSTANT ,
461456 );
462457 } else if (constant is ConstructorElementImpl ) {
@@ -507,13 +502,13 @@ class ConstantEvaluationEngine {
507502 return redirectedConstructor;
508503 }
509504
510- static _EnumConstant ? _enumConstant (VariableFragmentImpl element) {
511- if (element is FieldFragmentImpl && element.isEnumConstant) {
512- var enum_ = element.enclosingElement3 ;
513- if (enum_ is EnumFragmentImpl ) {
514- var index = enum_.constants .indexOf (element);
505+ static _EnumConstant ? _enumConstant (VariableElementImpl element) {
506+ if (element is FieldElementImpl && element.isEnumConstant) {
507+ var enum_ = element.enclosingElement ;
508+ if (enum_ is EnumElementImpl ) {
509+ var index = enum_.constants2 .indexOf (element);
515510 assert (index >= 0 );
516- return _EnumConstant (index: index, name: element.name2 ?? '' );
511+ return _EnumConstant (index: index, name: element.name3 ?? '' );
517512 }
518513 }
519514 return null ;
@@ -1969,8 +1964,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19691964 // and errors for other constant expressions. In either case we have
19701965 // already computed values of all dependencies first (or detect a cycle),
19711966 // so the value has already been computed and we can just return it.
1972- var firstFragment = variableElement.firstFragment as VariableFragmentImpl ;
1973- var evaluationResult = firstFragment.evaluationResult;
1967+ var evaluationResult = variableElement.evaluationResult;
19741968 if (variableElement.isConst) {
19751969 switch (evaluationResult) {
19761970 case null :
@@ -3062,7 +3056,7 @@ class _InstanceCreationEvaluator {
30623056 var fields = _constructor.baseElement.enclosingElement.fields;
30633057 for (var field in fields) {
30643058 if ((field.isFinal || field.isConst) && ! field.isStatic) {
3065- var fieldValue = field.firstFragment. evaluationResult;
3059+ var fieldValue = field.evaluationResult;
30663060
30673061 // It is possible that the evaluation result is null.
30683062 // This happens for example when we have duplicate fields.
@@ -3379,7 +3373,7 @@ class _InstanceCreationEvaluator {
33793373 if (argumentValue == null && baseParameter.isOptional) {
33803374 // The parameter is an optional positional parameter for which no value
33813375 // was provided, so use the default value.
3382- var evaluationResult = baseParameter.firstFragment. evaluationResult;
3376+ var evaluationResult = baseParameter.evaluationResult;
33833377 if (evaluationResult == null ) {
33843378 // No default was provided, so the default value is null.
33853379 argumentValue = ConstantEvaluationEngine ._nullObject (_library);
0 commit comments