groovy-users mailing list archives

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

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

```groovy
@Retention(RetentionPolicy.RUNTIME)
@GroovyASTTransformationClass(["swagger.grails4.compiler.ApiDocTransformer"])
@interface ApiDoc {
  String value() default ""
}

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

    @Override
    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?

Thanks.



Best Regards,

Bob Yang

Mime
View raw message