views:

45

answers:

1

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

+1  A: 

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.

Chris Dail
good idea thanks!! I'll give it a try - nice link also.
rochb