Skip to content

Commit e1d8b25

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use FormalParameterElementMixin in impl elements, remove a few TypeImpl casts.
Change-Id: I4001175016b92b07a294e3e6f8461a3727b6d1d0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412141 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 683be87 commit e1d8b25

File tree

5 files changed

+45
-62
lines changed

5 files changed

+45
-62
lines changed

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

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,11 +1647,11 @@ class ConstructorElementImpl extends ExecutableElementImpl
16471647

16481648
class ConstructorElementImpl2 extends ExecutableElementImpl2
16491649
with
1650-
FragmentedExecutableElementMixin<ConstructorFragment>,
1651-
FragmentedFunctionTypedElementMixin<ConstructorFragment>,
1652-
FragmentedTypeParameterizedElementMixin<ConstructorFragment>,
1653-
FragmentedAnnotatableElementMixin<ConstructorFragment>,
1654-
FragmentedElementMixin<ConstructorFragment>,
1650+
FragmentedExecutableElementMixin<ConstructorElementImpl>,
1651+
FragmentedFunctionTypedElementMixin<ConstructorElementImpl>,
1652+
FragmentedTypeParameterizedElementMixin<ConstructorElementImpl>,
1653+
FragmentedAnnotatableElementMixin<ConstructorElementImpl>,
1654+
FragmentedElementMixin<ConstructorElementImpl>,
16551655
ConstructorElementMixin2,
16561656
_HasSinceSdkVersionMixin
16571657
implements ConstructorElement2 {
@@ -3769,6 +3769,9 @@ class EnumElementImpl2 extends InterfaceElementImpl2
37693769
/// Common base class for all analyzer-internal classes that implement
37703770
/// `ExecutableElement2`.
37713771
abstract class ExecutableElement2OrMember implements ExecutableElement2 {
3772+
@override
3773+
List<FormalParameterElementMixin> get formalParameters;
3774+
37723775
@override
37733776
TypeImpl get returnType;
37743777

@@ -5189,11 +5192,11 @@ mixin FragmentedElementMixin<E extends Fragment> implements _Fragmented<E> {
51895192
}
51905193
}
51915194

5192-
mixin FragmentedExecutableElementMixin<E extends ExecutableFragment>
5195+
mixin FragmentedExecutableElementMixin<E extends ExecutableElementImpl>
51935196
implements FragmentedElementMixin<E> {
5194-
List<FormalParameterElement> get formalParameters {
5197+
List<FormalParameterElementMixin> get formalParameters {
51955198
return firstFragment.formalParameters
5196-
.map((fragment) => fragment.element)
5199+
.map((fragment) => fragment.asElement2)
51975200
.toList();
51985201
}
51995202

@@ -5235,15 +5238,13 @@ mixin FragmentedFunctionTypedElementMixin<E extends ExecutableFragment>
52355238
// TODO(augmentations): This might be wrong. The parameters need to be a
52365239
// merge of the parameters of all of the fragments, but this probably doesn't
52375240
// account for missing data (such as the parameter types).
5238-
List<FormalParameterElement> get formalParameters {
5241+
List<FormalParameterElementMixin> get formalParameters {
52395242
var fragment = firstFragment;
52405243
return switch (fragment) {
5241-
FunctionTypedElementImpl(:var parameters) => parameters
5242-
.map((fragment) => (fragment as FormalParameterFragment).element)
5243-
.toList(),
5244-
ExecutableElementImpl(:var parameters) => parameters
5245-
.map((fragment) => (fragment as FormalParameterFragment).element)
5246-
.toList(),
5244+
FunctionTypedElementImpl(:var parameters) =>
5245+
parameters.map((fragment) => fragment.asElement2).toList(),
5246+
ExecutableElementImpl(:var parameters) =>
5247+
parameters.map((fragment) => fragment.asElement2).toList(),
52475248
_ => throw UnsupportedError(
52485249
'Cannot get formal parameters for ${fragment.runtimeType}'),
52495250
};
@@ -5451,8 +5452,7 @@ class GenericFunctionTypeElementImpl extends _ExistingElementImpl
54515452
Fragment? get enclosingFragment => enclosingElement3 as Fragment;
54525453

54535454
@override
5454-
List<FormalParameterFragment> get formalParameters =>
5455-
parameters.cast<FormalParameterFragment>();
5455+
List<ParameterElementImpl> get formalParameters => parameters;
54565456

54575457
@override
54585458
String get identifier => '-';
@@ -5607,11 +5607,11 @@ abstract class GetterElement2OrMember
56075607

56085608
class GetterElementImpl extends PropertyAccessorElementImpl2
56095609
with
5610-
FragmentedExecutableElementMixin<GetterFragment>,
5611-
FragmentedFunctionTypedElementMixin<GetterFragment>,
5612-
FragmentedTypeParameterizedElementMixin<GetterFragment>,
5613-
FragmentedAnnotatableElementMixin<GetterFragment>,
5614-
FragmentedElementMixin<GetterFragment>,
5610+
FragmentedExecutableElementMixin<PropertyAccessorElementImpl>,
5611+
FragmentedFunctionTypedElementMixin<PropertyAccessorElementImpl>,
5612+
FragmentedTypeParameterizedElementMixin<PropertyAccessorElementImpl>,
5613+
FragmentedAnnotatableElementMixin<PropertyAccessorElementImpl>,
5614+
FragmentedElementMixin<PropertyAccessorElementImpl>,
56155615
_HasSinceSdkVersionMixin
56165616
implements GetterElement2OrMember {
56175617
@override
@@ -7879,7 +7879,7 @@ class LocalFunctionElementImpl extends ExecutableElementImpl2
78797879
FunctionElementImpl get firstFragment => _wrappedElement;
78807880

78817881
@override
7882-
List<FormalParameterElement> get formalParameters =>
7882+
List<FormalParameterElementMixin> get formalParameters =>
78837883
_wrappedElement.formalParameters
78847884
.map((fragment) => fragment.element)
78857885
.toList();
@@ -8550,11 +8550,11 @@ class MethodElementImpl extends ExecutableElementImpl
85508550

85518551
class MethodElementImpl2 extends ExecutableElementImpl2
85528552
with
8553-
FragmentedExecutableElementMixin<MethodFragment>,
8554-
FragmentedFunctionTypedElementMixin<MethodFragment>,
8555-
FragmentedTypeParameterizedElementMixin<MethodFragment>,
8556-
FragmentedAnnotatableElementMixin<MethodFragment>,
8557-
FragmentedElementMixin<MethodFragment>,
8553+
FragmentedExecutableElementMixin<MethodElementImpl>,
8554+
FragmentedFunctionTypedElementMixin<MethodElementImpl>,
8555+
FragmentedTypeParameterizedElementMixin<MethodElementImpl>,
8556+
FragmentedAnnotatableElementMixin<MethodElementImpl>,
8557+
FragmentedElementMixin<MethodElementImpl>,
85588558
_HasSinceSdkVersionMixin
85598559
implements MethodElement2OrMember {
85608560
@override
@@ -10703,11 +10703,11 @@ abstract class SetterElement2OrMember
1070310703

1070410704
class SetterElementImpl extends PropertyAccessorElementImpl2
1070510705
with
10706-
FragmentedExecutableElementMixin<SetterFragment>,
10707-
FragmentedFunctionTypedElementMixin<SetterFragment>,
10708-
FragmentedTypeParameterizedElementMixin<SetterFragment>,
10709-
FragmentedAnnotatableElementMixin<SetterFragment>,
10710-
FragmentedElementMixin<SetterFragment>,
10706+
FragmentedExecutableElementMixin<PropertyAccessorElementImpl>,
10707+
FragmentedFunctionTypedElementMixin<PropertyAccessorElementImpl>,
10708+
FragmentedTypeParameterizedElementMixin<PropertyAccessorElementImpl>,
10709+
FragmentedAnnotatableElementMixin<PropertyAccessorElementImpl>,
10710+
FragmentedElementMixin<PropertyAccessorElementImpl>,
1071110711
_HasSinceSdkVersionMixin
1071210712
implements SetterElement2OrMember {
1071310713
@override
@@ -10909,11 +10909,11 @@ class SuperFormalParameterElementImpl2 extends FormalParameterElementImpl
1090910909

1091010910
class TopLevelFunctionElementImpl extends ExecutableElementImpl2
1091110911
with
10912-
FragmentedExecutableElementMixin<TopLevelFunctionFragment>,
10913-
FragmentedFunctionTypedElementMixin<TopLevelFunctionFragment>,
10914-
FragmentedTypeParameterizedElementMixin<TopLevelFunctionFragment>,
10915-
FragmentedAnnotatableElementMixin<TopLevelFunctionFragment>,
10916-
FragmentedElementMixin<TopLevelFunctionFragment>,
10912+
FragmentedExecutableElementMixin<FunctionElementImpl>,
10913+
FragmentedFunctionTypedElementMixin<FunctionElementImpl>,
10914+
FragmentedTypeParameterizedElementMixin<FunctionElementImpl>,
10915+
FragmentedAnnotatableElementMixin<FunctionElementImpl>,
10916+
FragmentedElementMixin<FunctionElementImpl>,
1091710917
_HasSinceSdkVersionMixin
1091810918
implements TopLevelFunctionElement {
1091910919
@override

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ extension ExecutableElement2OrMemberQuestionExtension
202202
TypeImpl? get firstParameterType {
203203
var self = this;
204204
if (self is MethodElement2OrMember) {
205-
// TODO(paulberry): eliminate this cast by changing this extension to
206-
// apply to `ExecutableElementOrMember?`.
207-
return self.formalParameters.firstOrNull?.type as TypeImpl?;
205+
return self.formalParameters.firstOrNull?.type;
208206
}
209207
return null;
210208
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ abstract class ExecutableMember extends Member
265265
Element2? get enclosingElement2 => _element2.enclosingElement2;
266266

267267
@override
268-
List<FormalParameterElement> get formalParameters =>
268+
List<FormalParameterElementMixin> get formalParameters =>
269269
parameters.map((fragment) => fragment.asElement2).toList();
270270

271271
@override

pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,7 @@ class AssignmentExpressionResolver {
197197
var parameters = method.formalParameters;
198198
if (parameters.isNotEmpty) {
199199
return _typeSystem.refineNumericInvocationContext2(
200-
leftType,
201-
method,
202-
leftType,
203-
// TODO(paulberry): eliminate this cast by changing the type of
204-
// `MethodElementOrMember.parameters` to
205-
// `List<ParameterElementMixin>`.
206-
parameters[0].type as TypeImpl);
200+
leftType, method, leftType, parameters[0].type);
207201
}
208202
}
209203
return UnknownInferredType.instance;

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,20 +1713,14 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
17131713
if (node is AugmentedExpression) {
17141714
if (element is SetterElement2OrMember) {
17151715
if (element.formalParameters case [var valueParameter]) {
1716-
// TODO(paulberry): eliminate this cast by changing the type of
1717-
// `PropertyAccessorElementOrMember.parameters` to
1718-
// `List<ParameterElementMixin>`.
1719-
writeType = valueParameter.type as TypeImpl;
1716+
writeType = valueParameter.type;
17201717
}
17211718
}
17221719
} else if (node is IndexExpression) {
1723-
if (element is MethodElement2) {
1720+
if (element is MethodElement2OrMember) {
17241721
var parameters = element.formalParameters;
17251722
if (parameters.length == 2) {
1726-
// TODO(paulberry): eliminate this cast by changing the type of
1727-
// `PropertyAccessorElementOrMember.parameters` to
1728-
// `List<ParameterElementMixin>`.
1729-
writeType = parameters[1].type as TypeImpl;
1723+
writeType = parameters[1].type;
17301724
}
17311725
}
17321726
} else if (node is PrefixedIdentifier ||
@@ -1741,10 +1735,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
17411735
} else {
17421736
var parameters = element.formalParameters;
17431737
if (parameters.length == 1) {
1744-
// TODO(paulberry): eliminate this cast by changing the type of
1745-
// `PropertyAccessorElementOrMember.parameters` to
1746-
// `List<ParameterElementMixin>`.
1747-
writeType = parameters[0].type as TypeImpl;
1738+
writeType = parameters[0].type;
17481739
}
17491740
}
17501741
} else if (element is VariableElement2OrMember) {

0 commit comments

Comments
 (0)