|
Groovy example source code file (CompiledAtASTTransformation.groovy)
The Groovy CompiledAtASTTransformation.groovy source codepackage transforms.global import org.codehaus.groovy.ast.* import org.codehaus.groovy.transform.* import org.codehaus.groovy.control.* import org.codehaus.groovy.ast.expr.* import org.codehaus.groovy.ast.stmt.* import java.lang.annotation.* import org.codehaus.groovy.ast.builder.AstBuilder /** * This ASTTransformation adds a static getCompiledTime() : String method to every class. * * @author Hamlet D'Arcy */ @GroovyASTTransformation(phase=CompilePhase.CONVERSION) public class CompiledAtASTTransformation implements ASTTransformation { private final static compileTime = new Date().toString() public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { List classes = sourceUnit.ast?.classes classes?.each { ClassNode clazz -> clazz.addMethod(makeMethod()) } } /** * OpCodes should normally be referenced, but in a standalone example I don't want to have to include * the jar at compile time. */ MethodNode makeMethod() { def ast = new AstBuilder().buildFromSpec { method('getCompiledTime', /*OpCodes.ACC_PUBLIC*/1 | /*OpCodes.ACC_STATIC*/8, String) { parameters {} exceptions {} block { returnStatement { constant(compileTime) } } annotations {} } } ast[0] } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy CompiledAtASTTransformation.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.