views:

70

answers:

4

I'm helping a friend develop a Java application. They are a non-MS shop.
I was tasked to write some repetitive code, so naturally as a .NET dev I thought of using T4.

But I'm stuck on Java/Eclipse (and no C# is allowed) so what are my options?
What do Java people use for code generation? Build tasks?

+1  A: 

Take a peek at Velocity's Texen engine, connected to an Ant task.

samkass
+1  A: 

Within Eclipse you might find templates useful. You can create new templates in the Preferences dialog via Java>Editor>Templates.

More targeted templates are configurable at Java>CodeStyle>Code Templates.

There's an introduction to templates in Eclipse in "Effective Eclipse: Custom Templates", which covers both Java>Editor>Templates and Web and XML -> XML Files -> Templates. (I have not used the latter.)

Andy Thomas-Cramer
A: 

If you want to use something more "independent", check AtomWeaver. This is basically a template engine like T4. However, it's independent from any platform or IDE, and while it lets you build simple templates to generate pieces of code, it can also be used to develop complete systems. The paradigm it follows is ABSE.

Rui Curado
A: 

You might also want to take a look at XText[1] and AndroMDA[2], both different from T4, but well suited to problems involving lots of repetitive-code.

[1] http://www.eclipse.org/Xtext/
[2] http://www.andromda.org/index.php

ddimitrov