@@ -62,8 +62,8 @@ import 'package:pub_semver/pub_semver.dart';
6262
6363// TODO(fshcheglov): Remove after third_party/pkg/dartdoc stops using it.
6464// https://github.com/dart-lang/dartdoc/issues/4066
65- @Deprecated ('Use ConstVariableFragment instead' )
66- typedef ConstVariableElement = ConstVariableFragment ;
65+ @Deprecated ('Use VariableFragmentImpl instead' )
66+ typedef ConstVariableElement = VariableFragmentImpl ;
6767
6868abstract class AnnotatableElementImpl implements ElementImpl , Annotatable {
6969 @override
@@ -727,8 +727,7 @@ class ConstantInitializerImpl implements ConstantInitializer {
727727
728728/// A `LocalVariableElement` for a local 'const' variable that has an
729729/// initializer.
730- class ConstLocalVariableFragmentImpl extends LocalVariableFragmentImpl
731- with ConstVariableFragment {
730+ class ConstLocalVariableFragmentImpl extends LocalVariableFragmentImpl {
732731 /// Initialize a newly created local variable element to have the given [name]
733732 /// and [offset] .
734733 ConstLocalVariableFragmentImpl ({
@@ -1132,62 +1131,6 @@ class ConstructorFragmentImpl extends ExecutableFragmentImpl
11321131 }
11331132}
11341133
1135- /// Mixin used by elements that represent constant variables and have
1136- /// initializers.
1137- ///
1138- /// Note that in correct Dart code, all constant variables must have
1139- /// initializers. However, analyzer also needs to handle incorrect Dart code,
1140- /// in which case there might be some constant variables that lack initializers.
1141- /// This interface is only used for constant variables that have initializers.
1142- ///
1143- /// This class is not intended to be part of the public API for analyzer.
1144- mixin ConstVariableFragment implements FragmentImpl , ConstantEvaluationTarget {
1145- /// If this element represents a constant variable, and it has an initializer,
1146- /// a copy of the initializer for the constant. Otherwise `null` .
1147- ///
1148- /// Note that in correct Dart code, all constant variables must have
1149- /// initializers. However, analyzer also needs to handle incorrect Dart code,
1150- /// in which case there might be some constant variables that lack
1151- /// initializers.
1152- ExpressionImpl ? constantInitializer;
1153-
1154- Constant ? _evaluationResult;
1155-
1156- Constant ? get evaluationResult => _evaluationResult;
1157-
1158- set evaluationResult (Constant ? evaluationResult) {
1159- _evaluationResult = evaluationResult;
1160- }
1161-
1162- @override
1163- bool get isConstantEvaluated => _evaluationResult != null ;
1164-
1165- /// Return a representation of the value of this variable, forcing the value
1166- /// to be computed if it had not previously been computed, or `null` if either
1167- /// this variable was not declared with the 'const' modifier or if the value
1168- /// of this variable could not be computed because of errors.
1169- DartObject ? computeConstantValue () {
1170- if (evaluationResult == null ) {
1171- var library = this .library;
1172- // TODO(scheglov): https://github.com/dart-lang/sdk/issues/47915
1173- if (library == null ) {
1174- return null ;
1175- }
1176- computeConstants (
1177- declaredVariables: context.declaredVariables,
1178- constants: [this ],
1179- featureSet: library.featureSet,
1180- configuration: ConstantEvaluationConfiguration (),
1181- );
1182- }
1183-
1184- if (evaluationResult case DartObjectImpl result) {
1185- return result;
1186- }
1187- return null ;
1188- }
1189- }
1190-
11911134/// This mixin is used to set up loading class members from summaries only when
11921135/// they are requested. The summary reader uses [deferReadMembers] , and
11931136/// getters invoke [ensureReadMembers] .
@@ -2897,7 +2840,6 @@ class FieldFormalParameterFragmentImpl extends FormalParameterFragmentImpl
28972840}
28982841
28992842class FieldFragmentImpl extends PropertyInducingFragmentImpl
2900- with ConstVariableFragment
29012843 implements FieldFragment {
29022844 /// True if this field inherits from a covariant parameter. This happens
29032845 /// when it overrides a field in a supertype that is covariant.
@@ -8871,9 +8813,6 @@ abstract class PropertyInducingFragmentImpl
88718813 return ! isFinal;
88728814 }
88738815
8874- @override
8875- bool get isConstantEvaluated => true ;
8876-
88778816 @override
88788817 bool get isLate {
88798818 return hasModifier (Modifier .LATE );
@@ -9491,7 +9430,6 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl
94919430}
94929431
94939432class TopLevelVariableFragmentImpl extends PropertyInducingFragmentImpl
9494- with ConstVariableFragment
94959433 implements TopLevelVariableFragment {
94969434 @override
94979435 late TopLevelVariableElementImpl element;
@@ -10329,14 +10267,29 @@ abstract class VariableElementOrMember
1032910267}
1033010268
1033110269abstract class VariableFragmentImpl extends FragmentImpl
10332- with ConstVariableFragment
1033310270 implements
1033410271 VariableElementOrMember ,
1033510272 AnnotatableFragmentImpl ,
10273+ ConstantEvaluationTarget ,
1033610274 VariableFragment {
1033710275 /// The type of this variable.
1033810276 TypeImpl ? _type;
1033910277
10278+ /// If this element represents a constant variable, and it has an initializer,
10279+ /// a copy of the initializer for the constant. Otherwise `null` .
10280+ ///
10281+ /// Note that in correct Dart code, all constant variables must have
10282+ /// initializers. However, analyzer also needs to handle incorrect Dart code,
10283+ /// in which case there might be some constant variables that lack
10284+ /// initializers.
10285+ ExpressionImpl ? constantInitializer;
10286+
10287+ /// The result of evaluating [constantInitializer] .
10288+ ///
10289+ /// Is `null` if [constantInitializer] is `null` , or if the value could not
10290+ /// be computed because of errors.
10291+ Constant ? evaluationResult;
10292+
1034010293 /// Initialize a newly created variable element to have the given [name] and
1034110294 /// [offset] .
1034210295 VariableFragmentImpl ({required super .nameOffset});
@@ -10380,6 +10333,9 @@ abstract class VariableFragmentImpl extends FragmentImpl
1038010333 setModifier (Modifier .CONST , isConst);
1038110334 }
1038210335
10336+ @override
10337+ bool get isConstantEvaluated => evaluationResult != null ;
10338+
1038310339 /// Set whether this variable is external.
1038410340 set isExternal (bool isExternal) {
1038510341 setModifier (Modifier .EXTERNAL , isExternal);
@@ -10421,6 +10377,32 @@ abstract class VariableFragmentImpl extends FragmentImpl
1042110377 void appendTo (ElementDisplayStringBuilder builder) {
1042210378 builder.writeVariableElement (this );
1042310379 }
10380+
10381+ /// Return a representation of the value of this variable, forcing the value
10382+ /// to be computed if it had not previously been computed, or `null` if either
10383+ /// this variable was not declared with the 'const' modifier or if the value
10384+ /// of this variable could not be computed because of errors.
10385+ @override
10386+ DartObject ? computeConstantValue () {
10387+ if (evaluationResult == null ) {
10388+ var library = this .library;
10389+ // TODO(scheglov): https://github.com/dart-lang/sdk/issues/47915
10390+ if (library == null ) {
10391+ return null ;
10392+ }
10393+ computeConstants (
10394+ declaredVariables: context.declaredVariables,
10395+ constants: [this ],
10396+ featureSet: library.featureSet,
10397+ configuration: ConstantEvaluationConfiguration (),
10398+ );
10399+ }
10400+
10401+ if (evaluationResult case DartObjectImpl result) {
10402+ return result;
10403+ }
10404+ return null ;
10405+ }
1042410406}
1042510407
1042610408mixin WrappedElementMixin implements ElementImpl {
0 commit comments