@@ -25,6 +25,9 @@ import 'package:meta/meta.dart';
25
25
///
26
26
/// There is only one reference object per [Element] .
27
27
class Reference {
28
+ /// The name of the container used for duplicate declarations.
29
+ static const _defName = '@def' ;
30
+
28
31
/// The parent of this reference, or `null` if the root.
29
32
Reference ? parent;
30
33
@@ -61,7 +64,7 @@ class Reference {
61
64
/// code, the actual name is the name of the parent of the duplicates
62
65
/// container `@def` .
63
66
String get elementName {
64
- if (parent? .name == '@def' ) {
67
+ if (parent? .name == _defName ) {
65
68
return parent! .parent! .name;
66
69
}
67
70
return name;
@@ -75,6 +78,25 @@ class Reference {
75
78
76
79
bool get isSetter => parent? .name == '@setter' ;
77
80
81
+ /// The parent that is not a container like `@method` .
82
+ ///
83
+ /// Usually this is the parent of the parent.
84
+ /// @class::A::@method::foo -> @class::A
85
+ ///
86
+ /// But if this is a duplicates, we go two more levels up.
87
+ /// @class::A::@method::foo::@def::0 -> @class::A
88
+ Reference get parentNotContainer {
89
+ // Should be `@method`, `@constructor`, etc.
90
+ var containerInParent = parent! ;
91
+
92
+ // Skip the duplicates container.
93
+ if (containerInParent.name == _defName) {
94
+ containerInParent = containerInParent.parent! .parent! ;
95
+ }
96
+
97
+ return containerInParent.parent! ;
98
+ }
99
+
78
100
/// Return the child with the given name, or `null` if does not exist.
79
101
Reference ? operator [](String name) {
80
102
name = _rewriteDartUi (name);
@@ -104,12 +126,12 @@ class Reference {
104
126
return getChild (name);
105
127
}
106
128
107
- var def = existing['@def' ];
129
+ var def = existing[_defName ];
108
130
109
131
// If no duplicates container yet.
110
132
if (def == null ) {
111
133
removeChild (name); // existing
112
- def = getChild (name).getChild ('@def' );
134
+ def = getChild (name).getChild (_defName );
113
135
def._addChild ('0' , existing);
114
136
existing.parent = def;
115
137
existing.name = '0' ;
0 commit comments