EMF uses JET to generate the Java code. EMF ships a default set of JET templates which are used for the code generation. However, you can create your own templates and ask EMF to use that. Creating those templates from scratch is an enormous task, the best approach is to edit the default templates.
The default templates are available inside the org.eclipse.emf.codegen.ecore plugin. To get those into your project:
- Open the Plug-ins view and Right click the org.eclipse.emf.codegen.ecore plugin
- Select Import As -> Binary Project
- Now your workspace should contain this plug-in project. Copy the templates directory and Paste it in your EMF Project. After this step, you can delete the org.eclipse.emf.codegen.ecore project and remove it from your workspace.
- Set the Dynamic Templates to true and specify the directory where your templates are stored.
Now that you have the templates in your project, let tell EMF to use these. Open your .genmodel and go to the Properties View.
You can customize these templates to suit your requirements. Say for example, you want edit the Copyright statement that is generated in every Java file. Open the templates/Header.javajetinc file and add the required content. You would have to know JET to do that, but its fairly simple. You can refer to the articles here and here for more help on JET.



1 comments: