INRIA / INRIA/spoon

Add missing addXAt(int, CtElement<?>)-like methods for ordered collections to public API

Open
#3,884 17 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

In the diff minimization project currently headed by @algomaster99, we have a need to make insertions at specific indices in list-like collections. Many Spoon metamodel elements support this through the `addX(int, CtELement)` methods (such as `CtStatementList.addStatement(int, CtStatement)`), but `CtInvocation` curiously only has a `addArgument(CtExpression)`.

I propose adding `CtAbstractInvocation.addArgument(int, CtExpression)` to the public API, because it a) makes for a more consistent experience in using Spoon, and b) this functionality is already implemented in all implementations of `CtAbstractInvocation`, so the extra work is minimal.

Currently, the only precise workaround that we have is this ugly beast that draws on implementation details of Spoon, and is thus undesirable to me:

```java
List arguments = invocation.getArguments();

if (arguments.isEmpty()) {
// empty model lists may be `EmptyClearableList` instances, which we can't add to
invocation.addArgument(argument);
} else {
// non-empty model lists are always `ModelList` instances, which update the metamodel on mutation
arguments.add(index, argument);
}
```

### Progress

- [x] `CtAbstractInvocation.addArgumentAt(int, CtExpression)`
- [x] `CtFormalTypeDeclarer.addFormalCtTypeParameterAt(int, CtFormalTypeParameter)` (#3894) - @slarse
- [x] `CtExecutable.addParameterAt(int, CtParameter)` (#3895) - @algomaster99

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.