Skip to content

Commit

Permalink
Extend argument expressions in MethodInvocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-bnn committed Dec 20, 2024
1 parent f82ca2a commit 692362f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,9 @@ public Expression convert(MessageSend expression) {
if (this.resolveBindings) {
recordNodes(expri, arguments[i]);
}
methodInvocation.arguments().add(expri);
var elts = expri.elements();
resetElementsParent(elts);
methodInvocation.argumentElements().addAll(elts);
}
}
Expression qualifier = null;
Expand Down Expand Up @@ -2934,7 +2936,7 @@ public Expression convert(org.eclipse.jdt.internal.compiler.ast.QualifiedAllocat
final ClassInstanceCreation classInstanceCreation = new ClassInstanceCreation(this.ast);
if (allocation.enclosingInstance != null) {
Expression2 exp = convert(allocation.enclosingInstance);
resetElementsParent(classInstanceCreation.elements());
resetElementsParent(exp.elements());
classInstanceCreation.elements().addAll(exp.elements());
}
switch(this.ast.apiLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public class MethodInvocation extends Expression {
public static final ChildListPropertyDescriptor ARGUMENTS_PROPERTY =
new ChildListPropertyDescriptor(MethodInvocation.class, "arguments", Expression.class, CYCLE_RISK); //$NON-NLS-1$

/**
* @since 3.39
*/
public static final ChildListPropertyDescriptor ARGUMENT_ELEMENTS_PROPERTY =
new ChildListPropertyDescriptor(MethodInvocation.class, "argumentElements", ASTNode.class, NO_CYCLE_RISK); //$NON-NLS-1$

/**
* A list of property descriptors (element type:
* {@link StructuralPropertyDescriptor}),
Expand Down Expand Up @@ -97,6 +103,7 @@ public class MethodInvocation extends Expression {
addProperty(TYPE_ARGUMENTS_PROPERTY, properyList);
addProperty(NAME_PROPERTY, properyList);
addProperty(ARGUMENTS_PROPERTY, properyList);
addProperty(ARGUMENT_ELEMENTS_PROPERTY, properyList);
PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(properyList);
}

Expand Down Expand Up @@ -147,10 +154,16 @@ public static List propertyDescriptors(int apiLevel) {
/**
* The list of argument expressions (element type:
* {@link Expression}). Defaults to an empty list.
* @deprecated
*/
private final ASTNode.NodeList arguments =
new ASTNode.NodeList(ARGUMENTS_PROPERTY);

/**
* @since 3.39
*/
private ASTNode.NodeList argumentElements = new ASTNode.NodeList(ARGUMENT_ELEMENTS_PROPERTY);

/**
* Creates a new AST node for a method invocation expression owned by the
* given AST. By default, no expression, no type arguments,
Expand Down Expand Up @@ -195,6 +208,9 @@ final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
if (property == TYPE_ARGUMENTS_PROPERTY) {
return typeArguments();
}
if (property == ARGUMENT_ELEMENTS_PROPERTY) {
return argumentElements();
}
// allow default implementation to flag the error
return super.internalGetChildListProperty(property);
}
Expand All @@ -213,7 +229,7 @@ ASTNode clone0(AST target) {
if (this.ast.apiLevel >= AST.JLS3_INTERNAL) {
result.typeArguments().addAll(ASTNode.copySubtrees(target, typeArguments()));
}
result.arguments().addAll(ASTNode.copySubtrees(target, arguments()));
result.argumentElements().addAll(ASTNode.copySubtrees(target, argumentElements()));
return result;
}

Expand All @@ -233,7 +249,7 @@ void accept0(ASTVisitor visitor) {
acceptChildren(visitor, this.typeArguments);
}
acceptChild(visitor, getName());
acceptChildren(visitor, this.arguments);
acceptChildren(visitor, this.argumentElements);
}
visitor.endVisit(this);
}
Expand Down Expand Up @@ -354,11 +370,19 @@ public void setName(SimpleName name) {
*
* @return the live list of argument expressions
* (element type: {@link Expression})
* @deprecated
*/
public List arguments() {
return this.arguments;
}

/**
* @since 3.39
*/
public List argumentElements() {
return this.argumentElements;
}

/**
* Resolves and returns the binding for the method invoked by this
* expression.
Expand Down Expand Up @@ -388,7 +412,7 @@ int treeSize() {
+ (this.elements == null ? 0 : this.elements.listSize())
+ (this.typeArguments == null ? 0 : this.typeArguments.listSize())
+ (this.methodName == null ? 0 : getName().treeSize())
+ (this.arguments == null ? 0 : this.arguments.listSize());
+ (this.arguments == null ? 0 : this.argumentElements.listSize());
}
}

0 comments on commit 692362f

Please sign in to comment.