@@ -13,7 +13,9 @@ import 'package:analyzer/dart/ast/ast.dart'
13
13
show
14
14
AnnotatedNode,
15
15
Declaration,
16
+ Expression,
16
17
FieldDeclaration,
18
+ InstanceCreationExpression,
17
19
VariableDeclaration,
18
20
VariableDeclarationList;
19
21
import 'package:analyzer/dart/element/element.dart' ;
@@ -24,6 +26,7 @@ import 'package:analyzer/source/package_map_resolver.dart';
24
26
import 'package:analyzer/source/sdk_ext.dart' ;
25
27
// TODO(jcollins-g): Stop using internal analyzer structures somehow.
26
28
import 'package:analyzer/src/context/builder.dart' ;
29
+ import 'package:analyzer/src/dart/element/element.dart' ;
27
30
import 'package:analyzer/src/dart/sdk/sdk.dart' ;
28
31
import 'package:analyzer/src/generated/engine.dart' ;
29
32
import 'package:analyzer/src/generated/java_io.dart' ;
@@ -1449,9 +1452,9 @@ class Field extends ModelElement
1449
1452
bool get isInherited => _isInherited;
1450
1453
1451
1454
@override
1452
- String get kind => 'property' ;
1455
+ String get kind => isConst ? 'constant' : 'property' ;
1453
1456
1454
- String get typeName => "property" ;
1457
+ String get typeName => kind ;
1455
1458
1456
1459
@override
1457
1460
List <String > get annotations {
@@ -1540,21 +1543,36 @@ abstract class GetterSetterCombo implements ModelElement {
1540
1543
ModelElement enclosingElement;
1541
1544
bool get isInherited;
1542
1545
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 }" );
1549
1562
}
1550
- return null ;
1563
+ return original.replaceAll (
1564
+ "${targetClass .name }.${target .name }" , "${targetClass .linkedName }.${target .linkedName }" );
1551
1565
}
1552
1566
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
+ }
1556
1571
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);
1558
1576
1559
1577
/// Returns true if both accessors are synthetic.
1560
1578
bool get hasSyntheticAccessors {
@@ -4632,7 +4650,7 @@ class TopLevelVariable extends ModelElement
4632
4650
}
4633
4651
4634
4652
@override
4635
- String get kind => 'top-level property' ;
4653
+ String get kind => isConst ? 'top-level constant' : 'top-level property' ;
4636
4654
4637
4655
@override
4638
4656
Set <String > get features => super .features..addAll (comboFeatures);
0 commit comments