Skip to content

Commit 1dec944

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Augment. Use constant for '@def'.
Change-Id: I1020e8d39ff344e0588b3f0bd08205a570e2af19 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329421 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 96bd779 commit 1dec944

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

pkg/analyzer/lib/src/summary2/linked_element_factory.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,11 @@ class LinkedElementFactory {
194194
return createLibraryElementForReading(uri);
195195
}
196196

197-
// Should be `@method`, `@constructor`, etc.
198-
// If a duplicates container, skip it up.
199-
var containerInClass = reference.parent!;
200-
if (containerInClass.name == '@def') {
201-
containerInClass = containerInClass.parent!.parent!;
202-
}
197+
final parentRef = reference.parentNotContainer;
198+
final parentElement = elementOfReference(parentRef);
203199

204200
// Only classes delay creating children.
205-
final classRef = containerInClass.parent!;
206-
final parentElement = elementOfReference(classRef);
207-
208-
if (parentElement is InstanceElementImpl) {
201+
if (parentElement is ClassElementImpl) {
209202
parentElement.linkedData?.readMembers(parentElement);
210203
}
211204

pkg/analyzer/lib/src/summary2/reference.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import 'package:meta/meta.dart';
2525
///
2626
/// There is only one reference object per [Element].
2727
class Reference {
28+
/// The name of the container used for duplicate declarations.
29+
static const _defName = '@def';
30+
2831
/// The parent of this reference, or `null` if the root.
2932
Reference? parent;
3033

@@ -61,7 +64,7 @@ class Reference {
6164
/// code, the actual name is the name of the parent of the duplicates
6265
/// container `@def`.
6366
String get elementName {
64-
if (parent?.name == '@def') {
67+
if (parent?.name == _defName) {
6568
return parent!.parent!.name;
6669
}
6770
return name;
@@ -75,6 +78,25 @@ class Reference {
7578

7679
bool get isSetter => parent?.name == '@setter';
7780

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+
78100
/// Return the child with the given name, or `null` if does not exist.
79101
Reference? operator [](String name) {
80102
name = _rewriteDartUi(name);
@@ -104,12 +126,12 @@ class Reference {
104126
return getChild(name);
105127
}
106128

107-
var def = existing['@def'];
129+
var def = existing[_defName];
108130

109131
// If no duplicates container yet.
110132
if (def == null) {
111133
removeChild(name); // existing
112-
def = getChild(name).getChild('@def');
134+
def = getChild(name).getChild(_defName);
113135
def._addChild('0', existing);
114136
existing.parent = def;
115137
existing.name = '0';

0 commit comments

Comments
 (0)