A Java/Groovy API to generate Groovy source files
I'm looking for a Java or Groovy library to generate Groovy classes source files. I've CodeModel and this post but they are for Java.
Basically, I'd like to generate a Groovy class programmatically knowing the class name, the class 开发者_如何学编程attributes and generate particular methods depending on the class attributes.
I know Groovy templates, but there might be other ways.
Thanks
Good question! I don't know if there is anything like CodeModel for Groovy but one thing you can do is generate pure Java classes that you intend to call from Groovy. Since it is generated code anyway, it shouldn't matter if it is a Java or Groovy class. You can use all of the features like closures using their raw Java classes. For example, this site shows how you can write a Groovy closure in pure Java.
精彩评论