groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paolo Di Tommaso <paolo.ditomm...@gmail.com>
Subject Clousure expression transformation
Date Mon, 24 Sep 2018 17:34:58 GMT
Dear all,


I'm trying to write a global transformation for my DSL to apply a custom
logic on binary expression. For example:

@GroovyASTTransformation(phase = CompilePhase.CONVERSION)
class FooXformImpl implements ASTTransformation {

    SourceUnit unit

    @Override
    void visit(ASTNode[] nodes, SourceUnit source) {
        this.unit = unit
        createVisitor().visitClass((ClassNode)nodes[1])
    }

    protected ClassCodeExpressionTransformer createVisitor() {

        new ClassCodeExpressionTransformer() {

            protected SourceUnit getSourceUnit() { unit }

            Expression transform(Expression expr) {
                if( expr.class == BinaryExpression ) {
                    return .. // my replacement where
                }
                super.transform(expr)
            }
        }
    }
}


The transformation is correctly applied, however it turns out the
expressions nested in a closure definition are *not* visited. Therefore the
above transformation is not applied to binary expressions inside a closure.

Is that expected? How to manage this use case ?


Cheers,
Paolo

Mime
View raw message