-
Notifications
You must be signed in to change notification settings - Fork 78
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
Replacing field injection with constructor injection #557
Comments
Hi @crankydillo ; Thanks for the offer to help! Agree that this would be a nice addition, and best to start with a limited set of known cases, and reject anything else (at first) that might make it more complicated. On the known cases to reject I'd include
What we're left with then is
Anything you'd add to this list? |
RE field->constructor annotations, I was thinking we could move I might still do large constructors or maybe make that part configurable. The idea is to create an obvious code smell, which is currently hidden by 'Spring magic'. |
When is this coming? Quick fixes applied by this recipe would be very helpful in reducing the boilerplate. |
hi @punkratz312 ; we don't have a fixed schedule, but you're welcome to push up a draft PR with tests if you'd like to help out. :) |
Adding a note here that this is also necessary when you want to move away from |
We have this as a quick fix in the Spring Tools for VSCod and Eclipse: https://x.com/springtools4/status/1843922035824787896 It uses |
@crankydillo Interested in contributing some improvements to the |
@martinlippert If I can squeeze out some time. Honestly, I didn't know that class you mentioned existed. Wouldn't you say that meets at least the title of this issue? I can change the title to specify we are asking for additional things like |
Yeah, probably changing the title to something around taking We could also take a look, but if you plan to contribute this, we would not go down this path to avoid duplicate work (and vice versa). Just let us know whether you plan to work on this or not - both is totally fine. |
Also adding @BoykoAlex for awareness. |
Adding two relevant links here, as rewrite-spring for now lacks a recipe; we only have the visitor Alex provided in the past:
Both are copyrighted under Eclipse Public License; not immediately clear to me if we could adopt similar in rewrite-spring. |
The reconciler is very specific for the Spring Tools language servers reconciling mechanism and based on ASTs from JDT, so I don't see any value in this for the A recipe itself might make sense for |
The first link would be useful for the recipe implementation. Essentially it is a recipe taking two parameters: owner class fully qualified name and the name of the field in the class to convert into the constructor parameter. |
What problem are you trying to solve?
We want to convert a bunch of classes that used Spring field injection to constructor injection. We are willing to live with some caveats (e.g. only works if no constructors, select annotations, etc).
Describe the situation before applying the recipe
Describe the situation after applying the recipe
Any additional context
We could likely get value from something that didn't hit all the corner cases. However, if there are a bunch of corner cases that ultimately means an unending feature request on this, it's not like we really need this.
Are you interested in contributing this recipe to OpenRewrite?
Yes.
The text was updated successfully, but these errors were encountered: