Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Texo/Template Overriding"

(Template overriding)
(Template Tips)
Line 42: Line 42:
 
== Template Tips ==
 
== Template Tips ==
  
* '''Generating additional files''': by overriding a template you can easily generate additional files. For example by overriding/copying the entity.xpt template and adding an XPand «FILE ..... java-» in the overridden template you can generate additional files.
+
* '''Generating additional files''': the addition.xpt is ment to be overridden to facilitate generating additional files.  
 
* '''Organize imports''': Texo takes care of organizing imports and safely resolving fully qualified names. This means that in your template you should use fully qualified names.
 
* '''Organize imports''': Texo takes care of organizing imports and safely resolving fully qualified names. This means that in your template you should use fully qualified names.
* '''Merging support''': Texo also incorporates your additional files in the EMF-like merge process. This means that you can easily implement the same merge-support in your files (just place the @generated tag in the javadoc of classes, methods, members).
+
* '''Merging support''': Texo also incorporates your additional files in the EMF-like merge process. This means that you can easily implement the same EMF-like-merge-support in your files (just place the @generated tag in the javadoc of classes, methods, members).
 
* '''Clean up''': to prevent orphaned files Texo removes files which are not regenerated. So be aware that generation should only be done in packages/directories which contain files which are always generated together.
 
* '''Clean up''': to prevent orphaned files Texo removes files which are not regenerated. So be aware that generation should only be done in packages/directories which contain files which are always generated together.

Revision as of 00:10, 8 March 2010

Introduction

Texo uses different templates for generating different parts of the model code. The templates can be found in the org.eclipse.emf.texo.modelgenerator.templates package in the org.eclipse.emf.texo.modelgenerator plugin. You can find this plugin in CVS or in your eclipse plugins folder (after installing).

Template overriding

When generating model code, Texo checks the project properties to see if a template folder has been set in the Texo project properties. If this is the case, first this folder is checked for templates before using the standard Texo templates.

Note, Texo checks the project properties of the project which contains the model file. So if your model files are in different projects then each project needs such a templates folder set in the project properties. Currently (March 2010) the templates folder must be in the same project as the model file, in future versions it will probably be possible to select a workspace or filesystem folder outside of the project.

Templates to override

The templates can be found in cvs.

There are a few templates which are particularly interesting to override:

  • addition.xpt: this is template is intended to be overridden to generate additional files. It is called for each EPackage, EClass and EEnum in the model.
  • advice.xpt: it can be used to define XTend advices (for more information on XPand/Xtend aspect oriented support see here). For Texo it is empty, it is intended to be copied and overridden.
  • model.xpt: is the main template which calls the other templates to generate all the code. By overriding this you can control the complete generation for an EPackage.

Here is a short description of some of the other templates:

  • ecorefile.xpt: this template takes care of saving the ecore file in the same package as the entity classes.
  • entity.xpt: an important template, takes care of generating the entity classes
  • interface.xpt: handles the EClasses which are interfaces
  • featuregroup.xpt, modelfeaturemap.xpt: involved in generating code for support of featuremaps
  • modelfactory.xpt: generates the ModelFactory class
  • modelobject.xpt: takes care of generating the model api (inner-classes in the ModelFactory)
  • modelpackage.xpt: responsible for generating the ModelPackage.

Overriding a template

To override one of the template you have to do the following:

  • create a folder in the same project as the model file
  • create a directory structure inside this folder corresponding to the Texo templates package: org/eclipse/emf/texo/modelgenerator/templates
  • create your template file inside the org/eclipse/emf/texo/modelgenerator/templates folder with the exact same name as the template file used by Texo. For example to override the generation of the main model classes you need to create an entity.xpt file (probably copy the original one and adapt it).


Org.eclipse.emf.texo.override.template.png


Template Tips

  • Generating additional files: the addition.xpt is ment to be overridden to facilitate generating additional files.
  • Organize imports: Texo takes care of organizing imports and safely resolving fully qualified names. This means that in your template you should use fully qualified names.
  • Merging support: Texo also incorporates your additional files in the EMF-like merge process. This means that you can easily implement the same EMF-like-merge-support in your files (just place the @generated tag in the javadoc of classes, methods, members).
  • Clean up: to prevent orphaned files Texo removes files which are not regenerated. So be aware that generation should only be done in packages/directories which contain files which are always generated together.

Back to the top