Search code examples
javapluginsgroovycode-translation

Is there a way to convert Groovy to Java automatically?


I have inherited significant amounts of Groovy code, and I have found it difficult to maintain for several reasons:

  1. Very often it's hard to tell what's the type of a variable.
  2. Corollary: it's easy to modify a variable with a different type, and not being aware of it.
  3. Many errors will be discovered until run-time (which is scary if your unit testing doesn't cover pretty much everything).
  4. The type of the parameters is basically ignored.
  5. The IDE I'm using (STS Pro) is useful, but far behind from Java. For instance, refactoring is just not available.
  6. Suggestions are available some times, others, not.

Although I appreciate the compactness of the language, maintenance has been difficult and cumbersome.

I have tried to manually convert some pieces to Java, it's been a pain. Are you aware of any tools or plugins that help with this conversion?


Solution

  • I found and alternate solution, using Groovy++. It has almost all the advantages of Groovy, but with performance and strong typing from Java. Furthermore, it is based on Groovy, so apparently you only need to add one jar file, and the "@Typed" annotation at the top of the code.

    Furthermore, it adds a new features, such as "GrUnit", and allows mixing dynamic and static types, which I hope will allow for the creation of DSL's. So it allow mixing with existing Groovy code, and use with Grails.

    The project seems go be young, but truly promising. I am already testing the waters, and checking how far can I take it.

    So, this answer actually doesn't say how convert Groovy to Java, but you can get something even better: the benefits of both worlds plus and optional third world --no pun intended :-) -- static typing and performance.