Skip to content

Instantly share code, notes, and snippets.

@melix
Created July 22, 2014 12:47
Show Gist options
  • Save melix/628b2f04f83f7f9721b8 to your computer and use it in GitHub Desktop.
Save melix/628b2f04f83f7f9721b8 to your computer and use it in GitHub Desktop.
Dump AST transformations
import groovy.transform.ASTTest
import groovy.transform.CompileStatic
import groovy.transform.Immutable
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.control.CompilePhase
@ASTTest(phase=CompilePhase.INSTRUCTION_SELECTION,value={
ClassNode cn = node
def config = cn.compileUnit.config
def cu = cn.compileUnit.classLoader.createCompilationUnit(config, null)
System.err.println "Global AST xforms: ${cu.getASTTransformationsContext().globalTransformNames}"
CompilePhase.values().each {
def transforms = cn.getTransforms(it)
if (transforms) {
System.err.println "Ast xforms for phase $it:"
transforms.each { map ->
System.err.println(map)
}
}
}
})
@CompileStatic
@Immutable
class Foo {
}
@melix
Copy link
Author

melix commented Jul 22, 2014

Example of output:

Global AST xforms: [groovy.grape.GrabAnnotationTransformation, org.codehaus.groovy.ast.builder.AstBuilderTransformation]
Ast xforms for phase SEMANTIC_ANALYSIS:
class org.codehaus.groovy.transform.ASTTestTransformation=[org.codehaus.groovy.ast.AnnotationNode@4520ebad]
Ast xforms for phase CANONICALIZATION:
class org.codehaus.groovy.transform.ImmutableASTTransformation=[org.codehaus.groovy.ast.AnnotationNode@20e2cbe0]
Ast xforms for phase INSTRUCTION_SELECTION:
class org.codehaus.groovy.transform.sc.StaticCompileTransformation=[org.codehaus.groovy.ast.AnnotationNode@1753acfe]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment