rochb
rochb

Reputation: 2236

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

Upvotes: 6

Views: 2031

Answers (1)

Chris Dail
Chris Dail

Reputation: 26029

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.

Upvotes: 1

Related Questions