I am writing an ASTTransformation (in JAVA) in my Grails-project.
Because I want to transform the annotated class based on another class, I need to load the other class and also analyze it’s AST.
But I have no success with loading the other class:
Class.forName("OtherClass") -> ClassNotFoundException
Class.forName("OtherClass", false, classNode.getClassLoader()) -> ClassNotFoundException
OtherClass.class -> ClassNotFoundException
It think because the AST is per se executed at compile-time, the other class is just not available yet.
Maybe it is possible to get the source of the other class in my ASTTransformation and then build the AST of it with
new AstBuilder().buildFromCode { ... }
or something like that.
But how to load the resource/code?
I found the solution now:
creates a new
ClassNodewith all informations about fields, methods, properties and so on.