[ 
https://issues.apache.org/jira/browse/GROOVY-11721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18016659#comment-18016659
 ] 

Bartosz Popiela commented on GROOVY-11721:
------------------------------------------

?? Could the same transform also add {{{}BeanInject{}}}???

Not necessarily, because there are many more annotations that could be placed 
on a field.

 

??If the target checking supported the presence of {{Field}} – meaning it would 
look for ElementType.FIELD not ElementType.LOCAL_VARIABLE – would that satisfy 
what you are looking for???

IntelliJ already supports explicit @Field on a field and doesn't complain. My 
point is that I could place this annotation on a class/script/base script 
instead of placing it on every field separately.

!image-2025-08-28-02-47-30-911.png!

??If there is a transform applied and the IDE does not pick up on it, that's an 
IDE issue.??

Yes, I agree. However, AST transformations are executed during runtime and IDEs 
rely on static analysis 
([PSI|https://plugins.jetbrains.com/docs/intellij/psi.html] in case of 
IntelliJ), so cannot be aware of transformations that will be applied. 
Moreover, such transformations can be injected dynamically. If this feature 
(@Field applied to {{{}java.lang.annotation.ElementType#TYPE{}}}) were natively 
supported by the Groovy compiler, it would become feasible for IDEs to infer 
the actual target (field vs local variable).

> @groovy.transform.Field to annotate a script class
> --------------------------------------------------
>
>                 Key: GROOVY-11721
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11721
>             Project: Groovy
>          Issue Type: New Feature
>    Affects Versions: 5.0.0-beta-2
>            Reporter: Bartosz Popiela
>            Priority: Major
>         Attachments: image-2025-08-27-14-08-33-523.png, 
> image-2025-08-28-02-46-42-456.png, image-2025-08-28-02-47-30-911.png
>
>
> We use undeclared Groovy Scripts together with JUnit for writing unit tests 
> because it supports sentences as method names and doesn’t impose restrictions 
> on the file name (we need the test script name to match the name of the YAML 
> file being tested). This solution works very well; the only downside is that 
> in order to use annotations on a field, such as [email protected]_, we 
> also need to use [email protected]_, since those annotations typically 
> don’t have target = LOCAL_VARIABLE. It would be convenient if _@Field_ could 
> be placed on the script class (with _@Inherited_ to support a base script) 
> and be automatically applied to all local variables in the script



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to