[
https://issues.apache.org/jira/browse/GROOVY-11721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18016832#comment-18016832
]
Eric Milles commented on GROOVY-11721:
--------------------------------------
Using a global transform to add an annotation in phase Semantic Analysis or
later will not have that annotation scanned by {{ASTTransformationVisitor}},
which also runs in the Semantic Analysis phase. I tried a transform that adds
the {{Field}} transform during Conversion phase and it was picked up by the
transform visitor and the {{FieldASTTransformation}} was run appropriately.
Using an {{AnnotationCollector}} annotation seems to work as well, since the
{{AnnotationCollectorTransform}} runs during Semantic Analysis before the
{{ASTTransformationVisitor}}.
It is also possible to add the necessary transform during your scanning using
{{compilationUnit.addPhaseOperation}} to mimic what
{{ASTTransformationVisitor}} would do when it sees the {{Field}} annotation.
All of these should be cross-compatible if your IDE is processing your source
through at least the Semantic Analysis phase.
> @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-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)