[
https://issues.apache.org/jira/browse/GROOVY-11231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17794860#comment-17794860
]
Eric Milles commented on GROOVY-11231:
--------------------------------------
When this is expanded, how much of this is what you are after?
{code:groovy}
class MyService implements GroovyObject {
@Qualifier('d')
private Dependency myDependency
@Generated
@Qualifier('d')
Dependency getMyDependency() {
return myDependency
}
@Generated
void setMyDependency(@Qualifier('d') Dependency d) {
myDependency = d
}
@Generated
MyService(@Qualifier('d') Dependency d) {
myDependency = d
}
}
{code}
The first possibility is as you have described, if the annotation is only for
PARAMETER target, move it to the generated parameter. It is less clear what to
do if the tag supports multiple targets.
Another possibility is to add an attribute to {{TupleConstructor}} like:
{code:groovy}
@TupleConstructor(defaults=false, annotations=[Qualifier])
class MyService {
@Qualifier('d')
Dependency myDependency
}
{code}
And it may be possible to indicate the annotation belongs on the ctor param:
{code:groovy}
@TupleConstructor(defaults=false)
class MyService {
@ToParameter(Qualifier('d'))
Dependency myDependency
}
{code}
Not sure how far automation can get here before running into a lot of corner
cases. Is writing the constructor explicitly a very lengthy artifact? I
assume your scenario has more properties and annotations than just the one.
> TupleConstructor could copy annotations to constructor
> ------------------------------------------------------
>
> Key: GROOVY-11231
> URL: https://issues.apache.org/jira/browse/GROOVY-11231
> Project: Groovy
> Issue Type: Improvement
> Components: Compiler
> Affects Versions: 4.0.15
> Reporter: Christopher Smith
> Priority: Major
> Labels: annotations
>
> There are a number of use cases where it is necessary or helpful to annotate
> constructor arguments; two that I use frequently are injection qualifiers and
> {{@JsonProperty}}.
> When {{@TupleConstructor}} creates a constructor for a property that carries
> an annotation that also has a target of {{PARAMETER}}, I propose that it
> should copy that annotation to the generated constructor parameter.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)