@@ -73,15 +73,15 @@ mixin GetterSetterCombo on ModelElement {
7373 return original;
7474 }
7575 var target = modelBuilder.fromElement (staticElement) as Constructor ;
76- if (target. enclosingElement is ! Class ) return original ;
77- var targetClass = target. enclosingElement as Class ;
78- // TODO(jcollins-g): this logic really should be integrated into Constructor,
79- // but that's not trivial because of linkedName's usage.
80- if (targetClass .name == target.name) {
76+ var enclosingElement = target.enclosingElement ;
77+ if ( enclosingElement is ! Class ) return original ;
78+ // TODO(jcollins-g): this logic really should be integrated into
79+ // `Constructor`, but that's not trivial because of ` linkedName` 's usage.
80+ if (enclosingElement .name == target.name) {
8181 return original.replaceAll (constructorName, target.linkedName);
8282 }
83- return original.replaceAll ('${targetClass .name }.${target .name }' ,
84- '${targetClass .linkedName }.${target .linkedName }' );
83+ return original.replaceAll ('${enclosingElement .name }.${target .name }' ,
84+ '${enclosingElement .linkedName }.${target .linkedName }' );
8585 }
8686
8787 @override
@@ -110,8 +110,38 @@ mixin GetterSetterCombo on ModelElement {
110110 String get constantValueTruncated =>
111111 linkifyConstantValue (truncateString (constantValueBase, 200 ));
112112
113- late final String constantValueBase = const HtmlEscape (HtmlEscapeMode .unknown)
114- .convert (constantInitializer? .toString () ?? '' );
113+ late final String constantValueBase = () {
114+ final constantInitializer = this .constantInitializer;
115+ if (constantInitializer == null ) {
116+ return '' ;
117+ }
118+
119+ var initializerString = constantInitializer.toString ();
120+
121+ final self = this ;
122+ if (self is ! EnumField ||
123+ constantInitializer is ! InstanceCreationExpression ) {
124+ return _htmlEscape.convert (initializerString);
125+ }
126+
127+ initializerString = 'const $initializerString ' ;
128+
129+ var isImplicitConstructorCall = constantInitializer
130+ .constructorName.staticElement? .isDefaultConstructor ??
131+ false ;
132+ if (isImplicitConstructorCall) {
133+ // For an enum value with an implicit constructor call (like
134+ // `enum E { one, two; }`), `constantInitializer.toString()` does not
135+ // include the implicit enum index argument (it is something like
136+ // `const E()`). We must manually include it. See
137+ // https://github.com/dart-lang/sdk/issues/54988.
138+ initializerString =
139+ initializerString.replaceFirst ('()' , '(${self .index })' );
140+ }
141+ return _htmlEscape.convert (initializerString);
142+ }();
143+
144+ static const _htmlEscape = HtmlEscape (HtmlEscapeMode .unknown);
115145
116146 late final bool hasPublicGetter = hasGetter && getter! .isPublic;
117147
0 commit comments