Deprecated: this webpage is preserved for archival purposes. Please consider visiting the new Reo webpage.

How to write code generators

Create a new plug-in project (see for instance PDE Does Plug-ins). Open the Manifest file or the plugin.xml and go to the Dependencies tab. Add org.ect.codgen to the dependencies. If you want to write a code generator for Reo connectors / networks also add org.ect.reo and org.ect.reo.diagram. Analogously for extensible automata.

Switch to the Extensions tab. Click on Add, select the org.ect.codegen.codeGenerators and press the Finish button. If it doesn't exist yet, create a new codeGenerator using the context menu. Now fill out the form on the right-hand side. In the end it should look like in the following screenshot (except that the namespace is org.ect and not cwi).

Now create the code generator class you specified above. This class has to implement the interface org.ect.codegenICodeGenerator. You can use extend org.ect.codegen.Abstract Code Generator? or org.ect.codegen.Java Code Generator?. These have already some helper methods built-in. Here are some examples:

You can further specify properties for your code generator, which will appear in the wizard. You can access them from the org.ect.codegen.IGenModel. You can also add extra pages to the wizard.

Java Emitter Templates (JET)

JET is a simple template language that you can use for generating code. To be able to use JET, make sure you have the require plug-ins installed. In the update manager, open the Ganymede update site and open the category Models and Model Development. Install the Java Emitter Templates (JET) SDK and the Jet Editor. Now you are all setup.

You should read one or two tutorials to get started with JET. But it is actually very simple. You can read this tutorial:

We have only worked with JET 1 so far, which seems a bit easier. So, unless you now how JET 2 works, I recommend to use JET 1. You can specify this in the preferences.

It seems there is no direct way to turn an existing project into a JET project. So if you have already created a code generator project as described above, you can use the following little hack to get it work.

  • Open the .project file in an external editor and add the following build-command in front of the other commands:
    <buildCommand>
        <name>org.eclipse.emf.codegen.JETBuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
    
  • Add also the JET project nature to the project description:
       <nature>org.eclipse.emf.codegen.jet.IJETNature</nature>
    
  • Create the file .jetproperties in the project root with this content:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <jet-settings>
        <template-container>templates</template-container>
        <source-container>src</source-container>
    </jet-settings>
    

Save everything, select the project in the project explorer and press F5 to do a refresh. Now put your templates into the folder templates. The corresponding Java classes should be generated and updated automatically.