alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (MyConstantsASTTransformation4272.groovy)

This example Groovy source code file (MyConstantsASTTransformation4272.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

acc_public, acc_public, asttransformation, classnode, groovyasttransformation, groovyasttransformation, integer, methodnode, methodnode, myconstantsasttransformation4272, opcodes, parameter, parameter, sourceunit

The Groovy MyConstantsASTTransformation4272.groovy source code

package groovy.bugs

import org.objectweb.asm.Opcodes

import org.codehaus.groovy.ast.ASTNode 
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.ClassNode 
import org.codehaus.groovy.ast.MethodNode 
import org.codehaus.groovy.ast.Parameter 
import org.codehaus.groovy.ast.builder.AstBuilder 
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit 
import org.codehaus.groovy.transform.ASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformation

@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
class MyConstantsASTTransformation4272 implements ASTTransformation, Opcodes {
    void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
        ClassNode classNode = nodes[1]

        classNode.addMethod(new MethodNode("willSucceed", ACC_PUBLIC, ClassHelper.boolean_TYPE,
                [] as Parameter[], null, new AstBuilder().buildFromCode { return new Integer("1") }[0]))
                
        classNode.addMethod(new MethodNode("willNotFail", ACC_PUBLIC, ClassHelper.int_TYPE,
                [] as Parameter[], null, new AstBuilder().buildFromCode { return 1 }[0]))

        classNode.addMethod(new MethodNode("willAlsoNotFail", ACC_PUBLIC, ClassHelper.boolean_TYPE,
                [] as Parameter[], null, new AstBuilder().buildFromString("return 1")[0]))
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy MyConstantsASTTransformation4272.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.