[
https://issues.apache.org/jira/browse/GROOVY-11973?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-11973:
-------------------------------
Description:
ASTTransformationCustomizer currently throws "AST transformation customizer
doesn't support AST transforms with multiple classes" when given an annotation
whose @GroovyASTTransformationClass lists more than one transform (e.g.
@Sealed, @RecordBase). It also rejects @AnnotationCollector aliases such as
@AutoExternalize with "Provided class doesn't look like an AST @interface",
since those annotations carry @AnnotationCollector rather than
@GroovyASTTransformationClass.
This enhancement adds a static factory method,
ASTTransformationCustomizer.forAnnotation(...), that returns a list of
customizer instances - one per resolved transform class - so each runs at its
own declared compile phase. The factory also recognises @AnnotationCollector
and recursively expands it to the underlying annotations, flattening nested
collectors.
Typical usage:
{code:groovy}
config.addCompilationCustomizers(*ASTTransformationCustomizer.forAnnotation(Sealed))
config.addCompilationCustomizers(*ASTTransformationCustomizer.forAnnotation(AutoExternalize))
{code}
Overloads accept an optional annotation-parameters map and a custom
ClassLoader, mirroring the existing constructors. The legacy single-class
constructors are unchanged for backward compatibility; their error message now
points users at forAnnotation.
A small companion fix in SealedCompletionASTTransformation makes it usable from
the customizer: it now uses the AnnotationNode passed in via nodes[0] rather
than re-fetching it from the class node (which the customizer does not attach),
and skips emitting an empty permittedSubclasses member when no subclasses are
detected.
was:
ASTTransformationCustomizer currently throws "AST transformation customizer
doesn't support AST transforms with multiple classes" when given an annotation
whose @GroovyASTTransformationClass lists more than one transform (e.g.
@Sealed, @RecordBase, @Final). It also rejects @AnnotationCollector aliases
such as @AutoExternalize with "Provided class doesn't look like an AST
@interface", since those annotations carry @AnnotationCollector rather than
@GroovyASTTransformationClass.
This enhancement adds a static factory method,
ASTTransformationCustomizer.forAnnotation(...), that returns a list of
customizer instances - one per resolved transform class - so each runs at its
own declared compile phase. The factory also recognises @AnnotationCollector
and recursively expands it to the underlying annotations, flattening nested
collectors.
Typical usage:
{code:groovy}
config.addCompilationCustomizers(*ASTTransformationCustomizer.forAnnotation(Sealed))
config.addCompilationCustomizers(*ASTTransformationCustomizer.forAnnotation(AutoExternalize))
{code}
Overloads accept an optional annotation-parameters map and a custom
ClassLoader, mirroring the existing constructors. The legacy single-class
constructors are unchanged for backward compatibility; their error message now
points users at forAnnotation.
A small companion fix in SealedCompletionASTTransformation makes it usable from
the customizer: it now uses the AnnotationNode passed in via nodes[0] rather
than re-fetching it from the class node (which the customizer does not attach),
and skips emitting an empty permittedSubclasses member when no subclasses are
detected.
> Allow ASTTransformationCustomizer to support annotations with multiple AST
> transforms (e.g. @Sealed, @RecordBase) and @AnnotationCollector aliases (e.g.
> @AutoExternalize) via a new forAnnotation factory method
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-11973
> URL: https://issues.apache.org/jira/browse/GROOVY-11973
> Project: Groovy
> Issue Type: New Feature
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> ASTTransformationCustomizer currently throws "AST transformation customizer
> doesn't support AST transforms with multiple classes" when given an
> annotation whose @GroovyASTTransformationClass lists more than one transform
> (e.g. @Sealed, @RecordBase). It also rejects @AnnotationCollector aliases
> such as @AutoExternalize with "Provided class doesn't look like an AST
> @interface", since those annotations carry @AnnotationCollector rather than
> @GroovyASTTransformationClass.
> This enhancement adds a static factory method,
> ASTTransformationCustomizer.forAnnotation(...), that returns a list of
> customizer instances - one per resolved transform class - so each runs at its
> own declared compile phase. The factory also recognises @AnnotationCollector
> and recursively expands it to the underlying annotations, flattening nested
> collectors.
> Typical usage:
> {code:groovy}
> config.addCompilationCustomizers(*ASTTransformationCustomizer.forAnnotation(Sealed))
> config.addCompilationCustomizers(*ASTTransformationCustomizer.forAnnotation(AutoExternalize))
> {code}
> Overloads accept an optional annotation-parameters map and a custom
> ClassLoader, mirroring the existing constructors. The legacy single-class
> constructors are unchanged for backward compatibility; their error message
> now points users at forAnnotation.
> A small companion fix in SealedCompletionASTTransformation makes it usable
> from the customizer: it now uses the AnnotationNode passed in via nodes[0]
> rather than re-fetching it from the class node (which the customizer does not
> attach), and skips emitting an empty permittedSubclasses member when no
> subclasses are detected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)