Skip to content

Commit 106489a

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Add reference for enum, extension, extension type elements.
Change-Id: I1b204a256bf8845959ccde1de5a755994b3ff105 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392101 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent bc58f69 commit 106489a

File tree

53 files changed

+1699
-1520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1699
-1520
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ import 'package:meta/meta.dart';
9898
// TODO(scheglov): Clean up the list of implicitly analyzed files.
9999
class AnalysisDriver {
100100
/// The version of data format, should be incremented on every format change.
101-
static const int DATA_VERSION = 404;
101+
static const int DATA_VERSION = 405;
102102

103103
/// The number of exception contexts allowed to write. Once this field is
104104
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,44 @@ class AugmentedClassElementImpl extends AugmentedInterfaceElementImpl
122122

123123
class AugmentedEnumElementImpl extends AugmentedInterfaceElementImpl
124124
with MaybeAugmentedEnumElementMixin {
125+
@override
126+
final Reference reference;
127+
125128
@override
126129
final EnumElementImpl declaration;
127130

128-
AugmentedEnumElementImpl(this.declaration);
131+
AugmentedEnumElementImpl(this.reference, this.declaration) {
132+
reference.element2 = this;
133+
declaration.augmentedInternal = this;
134+
}
129135
}
130136

131137
class AugmentedExtensionElementImpl extends AugmentedInstanceElementImpl
132138
with MaybeAugmentedExtensionElementMixin {
139+
@override
140+
final Reference reference;
141+
133142
@override
134143
final ExtensionElementImpl declaration;
135144

136-
AugmentedExtensionElementImpl(this.declaration);
145+
AugmentedExtensionElementImpl(this.reference, this.declaration) {
146+
reference.element2 = this;
147+
declaration.augmentedInternal = this;
148+
}
137149
}
138150

139151
class AugmentedExtensionTypeElementImpl extends AugmentedInterfaceElementImpl
140152
with MaybeAugmentedExtensionTypeElementMixin {
153+
@override
154+
final Reference reference;
155+
141156
@override
142157
final ExtensionTypeElementImpl declaration;
143158

144-
AugmentedExtensionTypeElementImpl(this.declaration);
159+
AugmentedExtensionTypeElementImpl(this.reference, this.declaration) {
160+
reference.element2 = this;
161+
declaration.augmentedInternal = this;
162+
}
145163
}
146164

147165
abstract class AugmentedInstanceElementImpl
@@ -286,8 +304,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl
286304

287305
@override
288306
MaybeAugmentedClassElementMixin get augmented {
289-
linkedData?.read(this);
290-
return augmentedInternal;
307+
return element;
291308
}
292309

293310
AugmentedClassElementImpl? get augmentedIfReally {
@@ -312,7 +329,8 @@ class ClassElementImpl extends ClassOrMixinElementImpl
312329

313330
@override
314331
MaybeAugmentedClassElementMixin get element {
315-
return augmented;
332+
linkedData?.read(this);
333+
return augmentedInternal;
316334
}
317335

318336
@override
@@ -3368,23 +3386,15 @@ class ElementLocationImpl implements ElementLocation {
33683386
class EnumElementImpl extends InterfaceElementImpl
33693387
with AugmentableElement<EnumElementImpl>
33703388
implements EnumElement, EnumFragment {
3371-
late MaybeAugmentedEnumElementMixin augmentedInternal =
3372-
NotAugmentedEnumElementImpl(this);
3389+
late MaybeAugmentedEnumElementMixin augmentedInternal;
33733390

33743391
/// Initialize a newly created class element to have the given [name] at the
33753392
/// given [offset] in the file that contains the declaration of this element.
33763393
EnumElementImpl(super.name, super.offset);
33773394

33783395
@override
33793396
MaybeAugmentedEnumElementMixin get augmented {
3380-
if (isAugmentation) {
3381-
if (augmentationTarget case var augmentationTarget?) {
3382-
return augmentationTarget.augmented;
3383-
}
3384-
}
3385-
3386-
linkedData?.read(this);
3387-
return augmentedInternal;
3397+
return element;
33883398
}
33893399

33903400
AugmentedEnumElementImpl? get augmentedIfReally {
@@ -3409,7 +3419,10 @@ class EnumElementImpl extends InterfaceElementImpl
34093419
List<FieldElement2> get constants2 => constants.cast<FieldElement2>();
34103420

34113421
@override
3412-
EnumElement2 get element => super.element as EnumElement2;
3422+
MaybeAugmentedEnumElementMixin get element {
3423+
linkedData?.read(this);
3424+
return augmentedInternal;
3425+
}
34133426

34143427
@override
34153428
ElementKind get kind => ElementKind.ENUM;
@@ -3640,8 +3653,7 @@ abstract class ExecutableElementImpl2 extends FunctionTypedElementImpl2
36403653
class ExtensionElementImpl extends InstanceElementImpl
36413654
with AugmentableElement<ExtensionElementImpl>
36423655
implements ExtensionElement, ExtensionFragment {
3643-
late MaybeAugmentedExtensionElementMixin augmentedInternal =
3644-
NotAugmentedExtensionElementImpl(this);
3656+
late MaybeAugmentedExtensionElementMixin augmentedInternal;
36453657

36463658
/// Initialize a newly created extension element to have the given [name] at
36473659
/// the given [offset] in the file that contains the declaration of this
@@ -3650,14 +3662,7 @@ class ExtensionElementImpl extends InstanceElementImpl
36503662

36513663
@override
36523664
MaybeAugmentedExtensionElementMixin get augmented {
3653-
if (isAugmentation) {
3654-
if (augmentationTarget case var augmentationTarget?) {
3655-
return augmentationTarget.augmented;
3656-
}
3657-
}
3658-
3659-
linkedData?.read(this);
3660-
return augmentedInternal;
3665+
return element;
36613666
}
36623667

36633668
AugmentedExtensionElementImpl? get augmentedIfReally {
@@ -3687,7 +3692,10 @@ class ExtensionElementImpl extends InstanceElementImpl
36873692
String get displayName => name ?? '';
36883693

36893694
@override
3690-
ExtensionElement2 get element => super.element as ExtensionElement2;
3695+
MaybeAugmentedExtensionElementMixin get element {
3696+
linkedData?.read(this);
3697+
return augmentedInternal;
3698+
}
36913699

36923700
@override
36933701
DartType get extendedType {
@@ -3769,8 +3777,7 @@ class ExtensionElementImpl extends InstanceElementImpl
37693777
class ExtensionTypeElementImpl extends InterfaceElementImpl
37703778
with AugmentableElement<ExtensionTypeElementImpl>
37713779
implements ExtensionTypeElement, ExtensionTypeFragment {
3772-
late MaybeAugmentedExtensionTypeElementMixin augmentedInternal =
3773-
NotAugmentedExtensionTypeElementImpl(this);
3780+
late MaybeAugmentedExtensionTypeElementMixin augmentedInternal;
37743781

37753782
/// Whether the element has direct or indirect reference to itself,
37763783
/// in representation.
@@ -3784,14 +3791,7 @@ class ExtensionTypeElementImpl extends InterfaceElementImpl
37843791

37853792
@override
37863793
MaybeAugmentedExtensionTypeElementMixin get augmented {
3787-
if (isAugmentation) {
3788-
if (augmentationTarget case var augmentationTarget?) {
3789-
return augmentationTarget.augmented;
3790-
}
3791-
}
3792-
3793-
linkedData?.read(this);
3794-
return augmentedInternal;
3794+
return element;
37953795
}
37963796

37973797
AugmentedExtensionTypeElementImpl? get augmentedIfReally {
@@ -3809,7 +3809,10 @@ class ExtensionTypeElementImpl extends InterfaceElementImpl
38093809
}
38103810

38113811
@override
3812-
ExtensionTypeElement2 get element => super.element as ExtensionTypeElement2;
3812+
MaybeAugmentedExtensionTypeElementMixin get element {
3813+
linkedData?.read(this);
3814+
return augmentedInternal;
3815+
}
38133816

38143817
@override
38153818
ElementKind get kind {
@@ -6748,6 +6751,9 @@ mixin MaybeAugmentedEnumElementMixin on MaybeAugmentedInterfaceElementMixin
67486751
@override
67496752
EnumFragment get firstFragment => declaration;
67506753

6754+
/// See [ElementImpl2.reference].
6755+
Reference get reference;
6756+
67516757
@override
67526758
T? accept2<T>(ElementVisitor2<T> visitor) {
67536759
return visitor.visitEnumElement(this);
@@ -6765,6 +6771,9 @@ mixin MaybeAugmentedExtensionElementMixin on MaybeAugmentedInstanceElementMixin
67656771
@override
67666772
ExtensionElementImpl get firstFragment => declaration;
67676773

6774+
/// See [ElementImpl2.reference].
6775+
Reference get reference;
6776+
67686777
@override
67696778
DartType get thisType => extendedType;
67706779

@@ -6795,6 +6804,9 @@ mixin MaybeAugmentedExtensionTypeElementMixin
67956804
@override
67966805
ConstructorElement2 get primaryConstructor2 => primaryConstructor.element;
67976806

6807+
/// See [ElementImpl2.reference].
6808+
Reference get reference;
6809+
67986810
@override
67996811
FieldElement2 get representation2 =>
68006812
representation.asElement2 as FieldElement2;
@@ -7754,8 +7766,7 @@ class MixinElementImpl extends ClassOrMixinElementImpl
77547766

77557767
@override
77567768
MaybeAugmentedMixinElementMixin get augmented {
7757-
linkedData?.read(this);
7758-
return augmentedInternal;
7769+
return element;
77597770
}
77607771

77617772
AugmentedMixinElementImpl? get augmentedIfReally {
@@ -7773,7 +7784,10 @@ class MixinElementImpl extends ClassOrMixinElementImpl
77737784
}
77747785

77757786
@override
7776-
MaybeAugmentedMixinElementMixin get element => augmented;
7787+
MaybeAugmentedMixinElementMixin get element {
7788+
linkedData?.read(this);
7789+
return augmentedInternal;
7790+
}
77777791

77787792
@override
77797793
bool get isBase {
@@ -8349,35 +8363,47 @@ class NotAugmentedClassElementImpl extends NotAugmentedInterfaceElementImpl
83498363

83508364
class NotAugmentedEnumElementImpl extends NotAugmentedInterfaceElementImpl
83518365
with MaybeAugmentedEnumElementMixin {
8366+
@override
8367+
final Reference reference;
8368+
83528369
@override
83538370
final EnumElementImpl element;
83548371

8355-
NotAugmentedEnumElementImpl(this.element);
8372+
NotAugmentedEnumElementImpl(this.reference, this.element) {
8373+
reference.element2 = this;
8374+
element.augmentedInternal = this;
8375+
}
83568376

83578377
@override
83588378
EnumElementImpl get declaration => element;
83598379

83608380
@override
83618381
AugmentedEnumElementImpl toAugmented() {
8362-
var augmented = AugmentedEnumElementImpl(declaration);
8382+
var augmented = AugmentedEnumElementImpl(reference, declaration);
83638383
declaration.augmentedInternal = augmented;
83648384
return augmented;
83658385
}
83668386
}
83678387

83688388
class NotAugmentedExtensionElementImpl extends NotAugmentedInstanceElementImpl
83698389
with MaybeAugmentedExtensionElementMixin {
8390+
@override
8391+
final Reference reference;
8392+
83708393
@override
83718394
final ExtensionElementImpl element;
83728395

8373-
NotAugmentedExtensionElementImpl(this.element);
8396+
NotAugmentedExtensionElementImpl(this.reference, this.element) {
8397+
reference.element2 = this;
8398+
declaration.augmentedInternal = this;
8399+
}
83748400

83758401
@override
83768402
ExtensionElementImpl get declaration => element;
83778403

83788404
@override
83798405
AugmentedExtensionElementImpl toAugmented() {
8380-
var augmented = AugmentedExtensionElementImpl(declaration);
8406+
var augmented = AugmentedExtensionElementImpl(reference, declaration);
83818407
augmented.extendedType = extendedType;
83828408
declaration.augmentedInternal = augmented;
83838409
return augmented;
@@ -8387,17 +8413,23 @@ class NotAugmentedExtensionElementImpl extends NotAugmentedInstanceElementImpl
83878413
class NotAugmentedExtensionTypeElementImpl
83888414
extends NotAugmentedInterfaceElementImpl
83898415
with MaybeAugmentedExtensionTypeElementMixin {
8416+
@override
8417+
final Reference reference;
8418+
83908419
@override
83918420
final ExtensionTypeElementImpl element;
83928421

8393-
NotAugmentedExtensionTypeElementImpl(this.element);
8422+
NotAugmentedExtensionTypeElementImpl(this.reference, this.element) {
8423+
reference.element2 = this;
8424+
declaration.augmentedInternal = this;
8425+
}
83948426

83958427
@override
83968428
ExtensionTypeElementImpl get declaration => element;
83978429

83988430
@override
83998431
AugmentedExtensionTypeElementImpl toAugmented() {
8400-
var augmented = AugmentedExtensionTypeElementImpl(declaration);
8432+
var augmented = AugmentedExtensionTypeElementImpl(reference, declaration);
84018433
augmented.primaryConstructor = primaryConstructor;
84028434
augmented.representation = representation;
84038435
declaration.augmentedInternal = augmented;

0 commit comments

Comments
 (0)