groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "杨波" <>
Subject Can Local Transformer be added to Trait?
Date Mon, 03 Aug 2020 08:33:04 GMT

Is it possible to add a local transformer to the Trait like this?

@interface ApiDoc {
  String value() default ""

@GroovyASTTransformation(phase = CompilePhase.SEMANTIC_ANALYSIS)
class ApiDocTransformer extends AbstractASTTransformation {

    void visit(ASTNode[] nodes, SourceUnit source) {
        // processing Class node it should be an Interface because trait is transformed to
Interface and some helper classes
        // But The trasformer will not be triggered for Trait

@ApiDoc("My Trait")
trait MyTrait {

I have tried like this but the transformer can not be invoked for Trait.

If I add the @ApiDoc annotation to implementing class the transformer can be invoked, 
but how can I transform trait methods such as adding an annotation to getter method?


Best Regards,

Bob Yang

View raw message