Given a chained invocation (builder pattern):
return new ThingBuilder().withA(a).withB(b).build();
How can I use JavaParser to add another chained invocation to end up with code like this:
return new ThingBuilder().withA(a).withB(b).withC(c).build();
I'm already familiar with the ModifierVisitor
, but am unable to find a good way to add the call in the right place, i.e to the relevant MethodCallExpr
(the one where the expression is new ThingBuilder().withA(a).withB(b)
and the method is build()
).
It would be fine to add it at the top level too if that's possible:
return new ThingBuilder().withC(c).withA(a).withB(b).build();