@@ -13,7 +13,9 @@ import 'package:analyzer/dart/ast/ast.dart'
1313 show
1414 AnnotatedNode,
1515 Declaration,
16+ Expression,
1617 FieldDeclaration,
18+ InstanceCreationExpression,
1719 VariableDeclaration,
1820 VariableDeclarationList;
1921import 'package:analyzer/dart/element/element.dart' ;
@@ -24,6 +26,7 @@ import 'package:analyzer/source/package_map_resolver.dart';
2426import 'package:analyzer/source/sdk_ext.dart' ;
2527// TODO(jcollins-g): Stop using internal analyzer structures somehow.
2628import 'package:analyzer/src/context/builder.dart' ;
29+ import 'package:analyzer/src/dart/element/element.dart' ;
2730import 'package:analyzer/src/dart/sdk/sdk.dart' ;
2831import 'package:analyzer/src/generated/engine.dart' ;
2932import 'package:analyzer/src/generated/java_io.dart' ;
@@ -1449,9 +1452,9 @@ class Field extends ModelElement
14491452 bool get isInherited => _isInherited;
14501453
14511454 @override
1452- String get kind => 'property' ;
1455+ String get kind => isConst ? 'constant' : 'property' ;
14531456
1454- String get typeName => "property" ;
1457+ String get typeName => kind ;
14551458
14561459 @override
14571460 List <String > get annotations {
@@ -1540,21 +1543,36 @@ abstract class GetterSetterCombo implements ModelElement {
15401543 ModelElement enclosingElement;
15411544 bool get isInherited;
15421545
1543- String _constantValueBase () {
1544- if (element.computeNode () != null ) {
1545- var v = element.computeNode ().toSource ();
1546- if (v == null ) return null ;
1547- var string = v.substring (v.indexOf ('=' ) + 1 , v.length).trim ();
1548- return const HtmlEscape (HtmlEscapeMode .UNKNOWN ).convert (string);
1546+ Expression get constantInitializer =>
1547+ (element as ConstVariableElement ).constantInitializer;
1548+
1549+ String linkifyConstantValue (String original) {
1550+ if (constantInitializer is ! InstanceCreationExpression ) return original;
1551+ String constructorName = (constantInitializer as InstanceCreationExpression )
1552+ .constructorName
1553+ .toString ();
1554+ Element staticElement =
1555+ (constantInitializer as InstanceCreationExpression ).staticElement;
1556+ Constructor target = new ModelElement .fromElement (staticElement, package);
1557+ Class targetClass = target.enclosingElement;
1558+ // TODO(jcollins-g): this logic really should be integrated into Constructor,
1559+ // but that's not trivial because of linkedName's usage.
1560+ if (targetClass.name == target.name) {
1561+ return original.replaceAll (constructorName, "${target .linkedName }" );
15491562 }
1550- return null ;
1563+ return original.replaceAll (
1564+ "${targetClass .name }.${target .name }" , "${targetClass .linkedName }.${target .linkedName }" );
15511565 }
15521566
1553- String get constantValueBase => _memoizer.memoized (_constantValueBase);
1554-
1555- String get constantValue => constantValueBase;
1567+ String _constantValueBase () {
1568+ String result = constantInitializer? .toString () ?? '' ;
1569+ return const HtmlEscape (HtmlEscapeMode .UNKNOWN ).convert (result);
1570+ }
15561571
1557- String get constantValueTruncated => truncateString (constantValueBase, 200 );
1572+ String get constantValue => linkifyConstantValue (constantValueBase);
1573+ String get constantValueTruncated =>
1574+ linkifyConstantValue (truncateString (constantValueBase, 200 ));
1575+ String get constantValueBase => _memoizer.memoized (_constantValueBase);
15581576
15591577 /// Returns true if both accessors are synthetic.
15601578 bool get hasSyntheticAccessors {
@@ -4632,7 +4650,7 @@ class TopLevelVariable extends ModelElement
46324650 }
46334651
46344652 @override
4635- String get kind => 'top-level property' ;
4653+ String get kind => isConst ? 'top-level constant' : 'top-level property' ;
46364654
46374655 @override
46384656 Set <String > get features => super .features..addAll (comboFeatures);
0 commit comments