Skip to content

Commit

Permalink
Elements. Update ExecutableElementImpl.parameters to return List<Para…
Browse files Browse the repository at this point in the history
…meterElementImpl>.

Change-Id: I6d54810bc9b7c66bf9573d8e5748f132e57dee63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403800
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Jan 9, 2025
1 parent 1eee8ba commit 66624da
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
16 changes: 8 additions & 8 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,11 @@ class ClassElementImpl extends ClassOrMixinElementImpl
var hasMixinWithInstanceVariables = mixins.any(typeHasInstanceVariables);
implicitConstructor.isConst =
superclassConstructor.isConst && !hasMixinWithInstanceVariables;
List<ParameterElement> superParameters = superclassConstructor.parameters;
var superParameters = superclassConstructor.parameters;
int count = superParameters.length;
var argumentsForSuperInvocation = <ExpressionImpl>[];
if (count > 0) {
var implicitParameters = <ParameterElement>[];
var implicitParameters = <ParameterElementImpl>[];
for (int i = 0; i < count; i++) {
ParameterElement superParameter = superParameters[i];
ParameterElementImpl implicitParameter;
Expand Down Expand Up @@ -3649,7 +3649,7 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
implements ExecutableElement, ExecutableFragment {
/// A list containing all of the parameters defined by this executable
/// element.
List<ParameterElement> _parameters = const [];
List<ParameterElementImpl> _parameters = const [];

/// The inferred return type of this executable element.
DartType? _returnType;
Expand Down Expand Up @@ -3772,16 +3772,16 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
}

@override
List<ParameterElement> get parameters {
List<ParameterElementImpl> get parameters {
linkedData?.read(this);
return _parameters;
}

/// Set the parameters defined by this executable element to the given
/// [parameters].
set parameters(List<ParameterElement> parameters) {
for (ParameterElement parameter in parameters) {
(parameter as ParameterElementImpl).enclosingElement3 = this;
set parameters(List<ParameterElementImpl> parameters) {
for (var parameter in parameters) {
parameter.enclosingElement3 = this;
}
_parameters = parameters;
}
Expand Down Expand Up @@ -9844,7 +9844,7 @@ class PropertyAccessorElementImpl_ImplicitSetter
Element get nonSynthetic => variable2;

@override
List<ParameterElement> get parameters {
List<ParameterElementImpl> get parameters {
if (_parameters.isNotEmpty) {
return _parameters;
}
Expand Down
21 changes: 18 additions & 3 deletions pkg/analyzer/lib/src/dart/element/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,18 @@ extension LibraryExtension2 on LibraryElement2? {
this?.featureSet.isEnabled(Feature.wildcard_variables) ?? false;
}

extension ParameterElementExtensions on ParameterElement {
extension ListOfParameterElementExtension on List<ParameterElement> {
/// Returns `this` as `List<ParameterElementImpl>`, converting if it isn't
/// one already.
List<ParameterElementImpl> toImpl() {
return switch (this) {
List<ParameterElementImpl> already => already,
_ => [for (var p in this) p.toImpl()],
};
}
}

extension ParameterElementExtension on ParameterElement {
/// Return [ParameterElement] with the specified properties replaced.
ParameterElementImpl copyWith({
DartType? type,
Expand All @@ -220,8 +231,12 @@ extension ParameterElementExtensions on ParameterElement {

/// Returns `this`, converted to a [ParameterElementImpl] if it isn't one
/// already.
ParameterElementImpl toImpl() =>
switch (this) { ParameterElementImpl p => p, _ => copyWith() };
ParameterElementImpl toImpl() {
return switch (this) {
ParameterElementImpl p => p,
_ => copyWith(),
};
}
}

extension RecordTypeExtension on RecordType {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ class InheritanceManager3 {
result.name2 = fragmentName;
result.typeParameters = resultType.typeFormals;
result.returnType = resultType.returnType;
result.parameters = resultType.parameters;
result.parameters = resultType.parameters.toImpl();
result.element = MethodElementImpl2(
Reference.root(), // TODO(scheglov): wrong
firstMethod.name,
Expand All @@ -1158,7 +1158,7 @@ class InheritanceManager3 {
result.isGetter = firstAccessor.isGetter;
result.isSetter = firstAccessor.isSetter;
result.returnType = resultType.returnType;
result.parameters = resultType.parameters;
result.parameters = resultType.parameters.toImpl();

var field = FieldElementImpl(variableName, -1);
field.enclosingElement3 = targetClass;
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/generated/testing/element_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class ElementFactory {
ClassElement enclosingElement,
String methodName,
DartType returnType,
List<ParameterElement> parameters) {
List<ParameterElementImpl> parameters) {
MethodElementImpl method = MethodElementImpl(methodName, 0);
method.enclosingElement3 = enclosingElement;
method.parameters = parameters;
Expand Down Expand Up @@ -338,7 +338,7 @@ class ElementFactory {
setter.isSetter = true;
setter.isSynthetic = true;
setter.variable2 = field;
setter.parameters = <ParameterElement>[parameter];
setter.parameters = [parameter];
setter.returnType = VoidTypeImpl.instance;
setter.isStatic = isStatic;
field.setter = setter;
Expand Down
6 changes: 3 additions & 3 deletions pkg/analyzer/lib/src/summary2/instance_member_inferrer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class InstanceMemberInferrer {
if (parameters.isEmpty) {
return;
}
var parameter = parameters[0] as ParameterElementImpl;
var parameter = parameters[0];

if (overriddenSetters.any(_isCovariantSetter)) {
parameter.inheritsCovariant = true;
Expand Down Expand Up @@ -227,7 +227,7 @@ class InstanceMemberInferrer {
if (field != null) {
if (field.setter != null) {
if (overriddenSetters.any(_isCovariantSetter)) {
var parameter = field.setter!.parameters[0] as ParameterElementImpl;
var parameter = field.setter!.parameters[0];
parameter.inheritsCovariant = true;
}
}
Expand Down Expand Up @@ -579,7 +579,7 @@ class InstanceMemberInferrer {
return;
}

var parameter = parameters[0] as ParameterElementImpl;
var parameter = parameters[0];
if (!parameter.hasImplicitType) {
element.isOperatorEqualWithParameterTypeFromObject = false;
return;
Expand Down
12 changes: 6 additions & 6 deletions pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class _MockSdkElementsBuilder {
String name = '',
bool isConst = false,
bool isFactory = false,
List<ParameterElement> parameters = const [],
List<ParameterElementImpl> parameters = const [],
}) {
var element = ConstructorElementImpl(name, 0);
element.name2 = name.ifNotEmptyOrElse('new');
Expand All @@ -1014,7 +1014,7 @@ class _MockSdkElementsBuilder {
String name,
DartType returnType, {
List<TypeParameterElement> typeFormals = const [],
List<ParameterElement> parameters = const [],
List<ParameterElementImpl> parameters = const [],
}) {
return FunctionElementImpl(name, 0)
..parameters = parameters
Expand Down Expand Up @@ -1071,15 +1071,15 @@ class _MockSdkElementsBuilder {
String name,
DartType returnType, {
List<TypeParameterElement> typeFormals = const [],
List<ParameterElement> parameters = const [],
List<ParameterElementImpl> parameters = const [],
}) {
return MethodElementImpl(name, 0)
..parameters = parameters
..returnType = returnType
..typeParameters = typeFormals;
}

ParameterElement _namedParameter(String name, DartType type,
ParameterElementImpl _namedParameter(String name, DartType type,
{String? initializerCode}) {
var parameter = DefaultParameterElementImpl(
name: name,
Expand Down Expand Up @@ -1155,7 +1155,7 @@ class _MockSdkElementsBuilder {
];
}

ParameterElement _positionalParameter(String name, DartType type) {
ParameterElementImpl _positionalParameter(String name, DartType type) {
var parameter = ParameterElementImpl(
name: name,
nameOffset: 0,
Expand All @@ -1165,7 +1165,7 @@ class _MockSdkElementsBuilder {
return parameter;
}

ParameterElement _requiredParameter(String name, DartType type) {
ParameterElementImpl _requiredParameter(String name, DartType type) {
var parameter = ParameterElementImpl(
name: name,
nameOffset: 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/test/generated/elements_types_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ mixin ElementsTypesMixin {
DartType returnType, {
bool isStatic = false,
List<TypeParameterElement> typeFormals = const [],
List<ParameterElement> parameters = const [],
List<ParameterElementImpl> parameters = const [],
}) {
return MethodElementImpl(name, 0)
..isStatic = isStatic
Expand Down

0 comments on commit 66624da

Please sign in to comment.