I'm currently trying to implement some AST transformations after a Groovy transform, but I ran into a problem:
How to specify AST conversion for assignment operator in a field? that is, the AST conversion should convert the following code:
class MyClass {
@MyTransformation
String myField
public void init() {
}
}
into something like
class MyClass {
String myField
public void init() {
this.myField = "initialized!"
}
}
I tried this with this AST call:
def ast = new AstBuilder().buildFromSpec {
expression{
declaration {
variable "myField"
token "="
constant "initialized!"
}
}
}
But after inserting the resulting statement into the "init" method of the declaration class, instead of it, a variable assignment was added instead, as in
java.lang.Object myField = "initialized!"
, Ast Builder TestCase, , . fieldNode . INSTRUCTION_SELECTION; , .
? , AstBuilder#buildFromSpec, , .