-
Notifications
You must be signed in to change notification settings - Fork 278
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
Expand getCoordinates of newClass to access arguments #4089
Comments
Thanks for the suggestion @timo-abele ; I imagine this to be very similar to how we handle J.MethodInvocation, which I think should make for a nice addition. rewrite/rewrite-java/src/main/java/org/openrewrite/java/tree/CoordinateBuilder.java Lines 232 to 247 in 9bcac5a
Which would then need to be returned instead of rewrite/rewrite-java/src/main/java/org/openrewrite/java/tree/J.java Lines 4454 to 4456 in 516c70b
|
What problem are you trying to solve?
I would like to switch one constructor call for an other with JavaTemplate. E.g. if a class
A
offers two constructorsA(int foo)
,A(int foo, double ba)
I would like to be able to insert a new argument after, or replace the list of arguments altogether.Describe the solution you'd like
API offers suitable methods through getCoordinates.
Have you considered any alternatives or workarounds?
Replacing the entire constructor call should work in theory.
withArguments()
works as well, but JavaTemplates seem to be the way to go.Additional context
Currently a constructor call can be replaced entirely, but it would be nice to be able to operate it without putting "new A" into the template, which requires me to find out the class name at runtime.
J.MethodInvocation
already hasgetCoordinates().replaceArguments()
, that could just be implemented innewClass
as well.Are you interested in contributing this feature to OpenRewrite?
probably won't find the time
The text was updated successfully, but these errors were encountered: