For C#, I have often used CodeSmith and lately the T4 generator which is part of Visual Studio.
I'm looking for something similar for Java, in particular an Eclipse add-in since I do all my Java development using the Eclipse IDE.
You can create a generator model with the YAKINDU Statechart generator model wizard by selecting File → New → Code generator model. The code generation is performed automatically whenever the statechart or the generator file is modified. See also chapter Running a generator for more information.
Template Method is a behavioral design pattern that allows you to defines a skeleton of an algorithm in a base class and let subclasses override the steps without changing the overall algorithm's structure.
FreeMarker is a Java-based template engine which can be used in stand-alone or servlet-based Java programs. In FreeMarker you define templates, which are text files that contain the desired output, except that they contain placeholders like ${name} , and even some logic like conditionals, loops, etc.
Apache FreeMarker™ is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data.
I've found that freemarker does a pretty good job for generating any type of code. From the website:
FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.
It is used by struts2 a lot. The website has a long list of other products that use freemarker.
I have worked with both Velocity and StringTemplate. Velocity is a bit more conventional (think JSP/ASP concepts), while StringTemplate seems a bit cleaner. in a sense described in this Artima interview. Both are pure templating engines, and will require you to write some code around them, if you want to do full-blown code generation from a model.
StringTemplate is used internally by ANTLR, which may be useful to your effort.
As an alternative approach, you could go with Eclipse, using EMF and JET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With