groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From polbotinka <>
Subject AST transformation in CLASS_GENERATION phase
Date Thu, 03 Mar 2016 08:26:50 GMT

I'm working on a custom AST transformation that needs a static type data.
Basically want i want to do is to add an assignment expression that takes
the closure inferred return type and set it to some field:

I'm getting a closure return type using:

But the problem is that it's populated with return type during
INSTRUCTION_SELECTION phase. Therefore I'm applying my AST during next phase
which is CLASS_GENERATION. I'm adding the ExpressionStatement but it doesn't
seem to work. If I change the CompilePhase to SEMANTIC_ANALYSIS the
assignment expression works but I don't have
StaticTypesMarker.INFERRED_RETURN_TYPE populated for closure.

The questions are:
1. I would like to know if it is possible to add expression statements to
the AST during CLASS_GENERATION phase? I doesn't seem to work for me.
Documentation is not clear here: 

2. If it is not possible to modify AST during CLASS_GENERATION  then is it
legal to use StaticTypeCheckingVisitor.visitClosure to get closure inferred
return type during SEMANTIC_ANALYSIS phase?
3. Are there any other options I might have missed?

View this message in context:
Sent from the Groovy Users mailing list archive at

View raw message