Search in sources :

Example 1 with ASTTransformationsContext

use of org.codehaus.groovy.control.ASTTransformationsContext in project groovy by apache.

the class ASTTransformationVisitor method addPhaseOperations.

public static void addPhaseOperations(final CompilationUnit compilationUnit) {
    ASTTransformationsContext context = compilationUnit.getASTTransformationsContext();
    addGlobalTransforms(context);
    compilationUnit.addPhaseOperation((final SourceUnit source, final GeneratorContext ignore, final ClassNode classNode) -> {
        GroovyClassVisitor visitor = new ASTTransformationCollectorCodeVisitor(source, compilationUnit.getTransformLoader());
        visitor.visitClass(classNode);
    }, Phases.SEMANTIC_ANALYSIS);
    for (CompilePhase phase : CompilePhase.values()) {
        switch(phase) {
            case INITIALIZATION:
            case PARSING:
            case CONVERSION:
                // with transform detection alone these phases are inaccessible, so don't add it
                break;
            default:
                compilationUnit.addPhaseOperation((final SourceUnit source, final GeneratorContext ignore, final ClassNode classNode) -> {
                    ASTTransformationVisitor visitor = new ASTTransformationVisitor(phase, context);
                    visitor.source = source;
                    visitor.visitClass(classNode);
                }, phase.getPhaseNumber());
                break;
        }
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ASTTransformationsContext(org.codehaus.groovy.control.ASTTransformationsContext) CompilePhase(org.codehaus.groovy.control.CompilePhase) GroovyClassVisitor(org.codehaus.groovy.ast.GroovyClassVisitor) SourceUnit(org.codehaus.groovy.control.SourceUnit) GeneratorContext(org.codehaus.groovy.classgen.GeneratorContext)

Aggregations

ClassNode (org.codehaus.groovy.ast.ClassNode)1 GroovyClassVisitor (org.codehaus.groovy.ast.GroovyClassVisitor)1 GeneratorContext (org.codehaus.groovy.classgen.GeneratorContext)1 ASTTransformationsContext (org.codehaus.groovy.control.ASTTransformationsContext)1 CompilePhase (org.codehaus.groovy.control.CompilePhase)1 SourceUnit (org.codehaus.groovy.control.SourceUnit)1