Skip to content

Commit efd357f

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Return XyzImpl from 'declaration'.
Change-Id: I29ae5383aa583f18d31eabb827e6b1aedd43b430 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411520 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 62dd31e commit efd357f

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ class ConstructorElementImpl extends ExecutableElementImpl
14681468
}
14691469

14701470
@override
1471-
ConstructorElement get declaration => this;
1471+
ConstructorElementImpl get declaration => this;
14721472

14731473
@override
14741474
String get displayName {
@@ -1769,6 +1769,9 @@ class ConstructorElementImpl2 extends ExecutableElementImpl2
17691769
/// Common implementation for methods defined in [ConstructorElement].
17701770
mixin ConstructorElementMixin
17711771
implements ConstructorElement, ExecutableElementOrMember {
1772+
@override
1773+
ConstructorElementImpl get declaration;
1774+
17721775
@override
17731776
bool get isDefaultConstructor {
17741777
// unnamed
@@ -2649,7 +2652,7 @@ abstract class ElementImpl implements Element, Element2 {
26492652
}
26502653

26512654
@override
2652-
Element get declaration => this;
2655+
ElementImpl get declaration => this;
26532656

26542657
@override
26552658
String get displayName => _name ?? '';
@@ -3790,6 +3793,9 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
37903793
...parameters,
37913794
];
37923795

3796+
@override
3797+
ExecutableElementImpl get declaration => this;
3798+
37933799
@override
37943800
ExecutableElementImpl2 get element;
37953801

@@ -4336,7 +4342,7 @@ class FieldElementImpl extends PropertyInducingElementImpl
43364342
}
43374343

43384344
@override
4339-
FieldElement get declaration => this;
4345+
FieldElementImpl get declaration => this;
43404346

43414347
@override
43424348
FieldElementImpl2 get element {
@@ -5304,7 +5310,7 @@ class FunctionElementImpl extends ExecutableElementImpl
53045310
}
53055311

53065312
@override
5307-
ExecutableElement get declaration => this;
5313+
ExecutableElementImpl get declaration => this;
53085314

53095315
@override
53105316
Fragment? get enclosingFragment {
@@ -8464,7 +8470,7 @@ class MethodElementImpl extends ExecutableElementImpl
84648470
}
84658471

84668472
@override
8467-
MethodElement get declaration => this;
8473+
MethodElementImpl get declaration => this;
84688474

84698475
@override
84708476
String get displayName {
@@ -8893,7 +8899,7 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement {
88938899
}
88948900

88958901
@override
8896-
Element? get declaration => null;
8902+
ElementImpl? get declaration => null;
88978903

88988904
@override
88998905
String get displayName => name;
@@ -9511,7 +9517,7 @@ class ParameterElementImpl extends VariableElementImpl
95119517
List<Fragment> get children3 => const [];
95129518

95139519
@override
9514-
ParameterElement get declaration => this;
9520+
ParameterElementImpl get declaration => this;
95159521

95169522
@override
95179523
FormalParameterElementImpl get element {
@@ -9696,6 +9702,9 @@ class ParameterElementImpl_ofImplicitSetter extends ParameterElementImpl {
96969702
/// [ParameterElement].
96979703
mixin ParameterElementMixin
96989704
implements ParameterElement, VariableElementOrMember {
9705+
@override
9706+
ParameterElementImpl get declaration;
9707+
96999708
@override
97009709
FormalParameterElementImpl get element;
97019710

@@ -10151,7 +10160,7 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
1015110160
correspondingSetter as SetterFragment?;
1015210161

1015310162
@override
10154-
PropertyAccessorElement get declaration => this;
10163+
PropertyAccessorElementImpl get declaration => this;
1015510164

1015610165
@override
1015710166
PropertyAccessorElementImpl2 get element {
@@ -10964,7 +10973,7 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl
1096410973
}
1096510974

1096610975
@override
10967-
TopLevelVariableElement get declaration => this;
10976+
TopLevelVariableElementImpl get declaration => this;
1096810977

1096910978
@override
1097010979
bool get isExternal {
@@ -11484,7 +11493,7 @@ class TypeParameterElementImpl extends ElementImpl
1148411493
List<Fragment> get children3 => const [];
1148511494

1148611495
@override
11487-
TypeParameterElement get declaration => this;
11496+
TypeParameterElementImpl get declaration => this;
1148811497

1148911498
@override
1149011499
String get displayName => name;
@@ -11828,7 +11837,7 @@ abstract class VariableElementImpl extends ElementImpl
1182811837
ExpressionImpl? get constantInitializer => null;
1182911838

1183011839
@override
11831-
VariableElement get declaration => this;
11840+
VariableElementImpl get declaration => this;
1183211841

1183311842
@override
1183411843
String get displayName => name;

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class ConstructorMember extends ExecutableMember
4848
ConstructorElement2 get baseElement => _element2;
4949

5050
@override
51-
ConstructorElement get declaration => super.declaration as ConstructorElement;
51+
ConstructorElementImpl get declaration =>
52+
_declaration as ConstructorElementImpl;
5253

5354
@override
5455
String get displayName => declaration.displayName;
@@ -254,7 +255,8 @@ abstract class ExecutableMember extends Member
254255
children.map((fragment) => fragment.asElement2).nonNulls.toList();
255256

256257
@override
257-
ExecutableElement get declaration => super.declaration as ExecutableElement;
258+
ExecutableElementImpl get declaration =>
259+
_declaration as ExecutableElementImpl;
258260

259261
@override
260262
String get displayName => declaration.displayName;
@@ -327,11 +329,11 @@ abstract class ExecutableMember extends Member
327329
@override
328330
List<ParameterElement> get parameters {
329331
return declaration.parameters.map<ParameterElement>((p) {
330-
if (p is FieldFormalParameterElement) {
332+
if (p is FieldFormalParameterElementImpl) {
331333
return FieldFormalParameterMember(
332334
p, augmentationSubstitution, _substitution);
333335
}
334-
if (p is SuperFormalParameterElement) {
336+
if (p is SuperFormalParameterElementImpl) {
335337
return SuperFormalParameterMember(
336338
p, augmentationSubstitution, _substitution);
337339
}
@@ -344,9 +346,7 @@ abstract class ExecutableMember extends Member
344346
var result = declaration.returnType;
345347
result = augmentationSubstitution.substituteType(result);
346348
result = _substitution.substituteType(result);
347-
// TODO(paulberry): eliminate this cast by changing the type of
348-
// `declaration`.
349-
return result as TypeImpl;
349+
return result;
350350
}
351351

352352
@override
@@ -562,7 +562,7 @@ class FieldMember extends VariableMember
562562
}
563563

564564
@override
565-
FieldElement get declaration => super.declaration as FieldElement;
565+
FieldElementImpl get declaration => _declaration as FieldElementImpl;
566566

567567
@override
568568
String get displayName => declaration.displayName;
@@ -838,7 +838,7 @@ abstract class Member implements Element {
838838
AnalysisContext get context => _declaration.context;
839839

840840
@override
841-
Element get declaration => _declaration;
841+
ElementImpl get declaration => _declaration as ElementImpl;
842842

843843
@override
844844
String get displayName => _declaration.displayName;
@@ -1094,7 +1094,7 @@ class MethodMember extends ExecutableMember
10941094
MethodElement2 get baseElement => _element2;
10951095

10961096
@override
1097-
MethodElement get declaration => super.declaration as MethodElement;
1097+
MethodElementImpl get declaration => _declaration as MethodElementImpl;
10981098

10991099
@override
11001100
Element get enclosingElement3 => declaration.enclosingElement3;
@@ -1227,8 +1227,7 @@ class ParameterMember extends VariableMember
12271227
}
12281228

12291229
@override
1230-
ParameterElementImpl get declaration =>
1231-
super.declaration as ParameterElementImpl;
1230+
ParameterElementImpl get declaration => _declaration as ParameterElementImpl;
12321231

12331232
@override
12341233
String? get defaultValueCode => declaration.defaultValueCode;
@@ -1457,7 +1456,7 @@ abstract class PropertyAccessorMember extends ExecutableMember
14571456

14581457
@override
14591458
PropertyAccessorElementImpl get declaration =>
1460-
super.declaration as PropertyAccessorElementImpl;
1459+
_declaration as PropertyAccessorElementImpl;
14611460

14621461
@override
14631462
Element2 get enclosingElement2 {
@@ -1660,8 +1659,8 @@ class TopLevelVariableMember extends VariableMember
16601659
}
16611660

16621661
@override
1663-
TopLevelVariableElement get declaration =>
1664-
_declaration as TopLevelVariableElement;
1662+
TopLevelVariableElementImpl get declaration =>
1663+
_declaration as TopLevelVariableElementImpl;
16651664

16661665
@override
16671666
String get displayName => declaration.displayName;
@@ -1731,7 +1730,7 @@ abstract class VariableMember extends Member
17311730
);
17321731

17331732
@override
1734-
VariableElement get declaration => super.declaration as VariableElement;
1733+
VariableElementImpl get declaration => _declaration as VariableElementImpl;
17351734

17361735
@override
17371736
bool get hasImplicitType => declaration.hasImplicitType;
@@ -1758,9 +1757,7 @@ abstract class VariableMember extends Member
17581757
var result = declaration.type;
17591758
result = augmentationSubstitution.substituteType(result);
17601759
result = _substitution.substituteType(result);
1761-
// TODO(paulberry): remove this cast by changing the type of `declaration`
1762-
// and the return type of `substituteType`
1763-
return _type = result as TypeImpl;
1760+
return _type = result;
17641761
}
17651762

17661763
@override

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ extension MethodElementExtension on MethodElement {
565565
}
566566
}
567567

568+
extension MethodElementImplExtension on MethodElementImpl {
569+
MethodElementImpl2 get asElement2 {
570+
return element;
571+
}
572+
}
573+
568574
extension MethodElementOrMemberExtension on MethodElementOrMember {
569575
MethodElement2OrMember get asElement2 {
570576
return switch (this) {

0 commit comments

Comments
 (0)