In Three steps to your Java Emitter template

Creating a Java Emitter Template (JET) is no easy feat, but if you have the right infrastructure set up it’s not that difficult.
This article is based on the Java Code Generator plug-in for Eclipse.

To cook up a JET easily you need three ingredients:

  1. A class that should be produced with the template, so you can see what goes into the template
  2. A helper class that converts and/or generates/transforms data from your model into a string
  3. A Java Emitter Template template – a basic template that can generate an empty class rump

As the JET template we can use the rump.javajet file from the plugin. If you design your class to have generic methods that don’t depend on the actual model or model data you can copy a good part of your template class into the JET. Where this is not an option the helper class will help out since everything in the JET is a string.
SourceForge.net Logo

Schreibe einen Kommentar