6

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

Community
  • 1
  • 1
rochb
  • 2,249
  • 18
  • 26

1 Answers1

1

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
  • 25,715
  • 9
  • 65
  • 74
  • The link you posted is broken. Do you remember the source? – hc_dev Feb 12 '21 at 21:18
  • Might have been an entry of former [Cedric Champeau's Weblog](https://web.archive.org/web/20170705235058/http://www.jroller.com/melix/) on _webarchive_ ? – hc_dev Feb 12 '21 at 21:24