Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: better collection-based properties of Spoon model (non-derived getters) #1633

Closed
pvojtechovsky opened this issue Oct 21, 2017 · 1 comment

Comments

@pvojtechovsky
Copy link
Collaborator

Example of problem: Use case: Client needs to add argument at the beginning of CtInvocation#arguments list.
Actually the only solution is

List<CtExpression<?>> args = new ArrayList<>(invocation.getArguments());
args.add(0, newArgument);
invocation.setArguments(args);

Solutions?

S1) to have method CtInvocation#addArgument(int, CtExpression)
S2) to have method CtInvocation#addFirstArgument(int, CtExpression)

it is the way how Spoon handles it actually. Each element implements (or does not implement (... yet?)) own set of collection manipulation methods. May be we might generate all possible add/addList/remove/contains methods of Set and List interface with appropriate attribute name suffix automatically.
It would be compatible with current model, but

  • it would mean a lot of methods in spoon API - more complicated for clients
  • it avoids usage of generic helper methods, which are able to do operations on List and Set

S3) to have method List CtInvocation#getArguments(), which would return modifiable implementation of List.

We cannot of course return internal list and let client to modify it.
The idea is to return a List/Set wrapper which would handle all the List/Set method calls. It would

  • generate appropriate model change events
  • handle consistency of model (change parent, ...)

It would be not backward compatible, but the code of spoon and code of client's would be simpler and spoon API would be more friendly to clients who needs model modifications.

S4) to use generic List modifiableList = invocation.getValueByRoleAsList(CtRole.ARGUMENT)

This is already partially implemented in #1582.

@monperrus monperrus changed the title Unified work with collection attributes of Spoon model feature: better collection-based properties of Spoon model Mar 16, 2018
@monperrus monperrus changed the title feature: better collection-based properties of Spoon model feature: better collection-based properties of Spoon model (non-derived getters) Mar 16, 2018
@monperrus
Copy link
Collaborator

closed per #1582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants