52-technologies-in-2016 icon indicating copy to clipboard operation
52-technologies-in-2016 copied to clipboard

Week 32: Groovy AST Transformations By Example

Open shekhargulati opened this issue 9 years ago • 1 comments
trafficstars

Please provide your feedback by posting a comment against this issue.

shekhargulati avatar Aug 07 '16 18:08 shekhargulati

This was from a while ago, so I'll post some code snippets to refresh your memory. I've been wrestling with a problem trying to get a Transform to utilize the default value for the annotation parameters when empty.

`import playground.Hash

    @Hash
    class Foo{
        String msg`

where in Hash: String algorithm() default "SHA1"; the AnnotationNode will have null for .getMember("algorithm") In ToHashAdderAstTransformation you get around this by checking for null and providing the default value again: List<ASTNode> astNodes = new AstBuilder() .buildFromString(String.format(hashString, classNode.getName(), hashProvider != null ? hashProvider.getValue() : "SHA1"));

Is there a way to use the actual default value set in the Annotation class? What is the point of supplying it if it is not available to the Transform class? Thanks for any help you can provide.

sdp0et avatar Apr 19 '17 23:04 sdp0et