[STS-1529] Provide quickfix to quickly create @Autowired constructor for class with final fields Created: 30/Jan/11 Updated: 03/May/12 Resolved: 25/Apr/12 |
|
Status: |
Resolved |
Project: |
|
Component/s: |
|
Affects Version/s: |
|
Fix Version/s: |
Type: |
Improvement |
Priority: |
Minor |
Reporter: |
Assignee: |
||
Resolution: |
Complete |
Votes: |
0 |
Y5M8, autowired, quickfix |
|||
Remaining Estimate: |
Not Specified |
||
Time Spent: |
Not Specified |
||
Original Estimate: |
Not Specified |
Description |
|
Comments |
|
Comment by Kaitlin Duck Sherwood [ 19/Apr/12 ] |
To be clear, am I correct that you are wanting a quick fix to transform the above into the below? public class MyService { private final MyFooRepo fooRepo; private final MyBarRepo barRepo; @Autowired MyService(MyFooRepo autogenFooRepo, MyBarRepo autogenBarRepo) { this.fooRepo = autogenFooRepo; this.barRepo = autogenBarRepo; } } |
Comment by Oliver Gierke [ 19/Apr/12 ] |
Exactly, (with the minor change that the constructor shall be public) is there a chance we can have the generated code inside a template? I usually add an Assert.notNull(parameter); for each of the parameters but fear that might be a bit too much for people wanting to avoid the dependency to Spring API. |
Comment by Kaitlin Duck Sherwood [ 19/Apr/12 ] |
Hmmm. I don't see how you could profitably use templates: I don't see any way to expand a list in a template, which is what you would need to do in order to do an assignment and an Assert.notNull(parameter) for each of the parameters. |
Comment by Oliver Gierke [ 19/Apr/12 ] |
That's what I was thinking as well just thinking I mentioned the idea as you're probably much deeper into the internals. Anyway, just go ahead with this one (including the public constructor), I am perfectly fine with this solution. |
Comment by Kaitlin Duck Sherwood [ 20/Apr/12 ] |
Are you aware that there is an existing way to generate
constructors from fields in Eclipse? When you were mentioning the Spring API dependency, were you concerned about the Assert? |
Comment by Kaitlin Duck Sherwood [ 25/Apr/12 ] |
Okay, I have checked in. The quickfix generates the @Autowired constructor with the final fields but does not do the null check. If you really want the null check, please open another bug for that. |
Comment by Oliver Gierke [ 26/Apr/12 ] |
Comment by Kaitlin Duck Sherwood [ 03/May/12 ] |
Opened a bug STS-2616 to not put the @Autowired if it is a non-Spring project. |
Generated at Wed Oct 06 06:48:55 UTC 2021 using Jira 8.5.11#805011-sha1:102a195bf8687d9dd541cc7f5503132d0561ea57.
Tags: constructor, autowired, create, [sts1529], provide, quickfix, quickly