Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 825
rochb Avatar asked Aug 21 '10 14:08

rochb


1 Answers

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.

like image 163
Chris Dail Avatar answered Nov 02 '22 08:11

Chris Dail