Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Texo/Code Generation Details

< Texo
Revision as of 05:31, 14 May 2010 by Mtaal.springsite.com (Talk | contribs) (Introduction)

Introduction

The Texo code generation is controlled by annotations on the model. These annotations control the class names, names of methods and java package names. When Teneo generates code it will automatically create these annotations (in-memory) for each model element (EClass, EStructuralFeature). However, it is also possible to define these annotations in a so-called Annotations Model. This gives you the possibility to override the choices made by the Texo code generator. Texo will use these manual annotations and add its own annotations to have a complete annotated model.

This document describes how the annotations model works and how you can generate/define the annotations model.

Note: annotations model can only be used for ecore models stored in .ecore files so not for xsd's. You can easily create an ecore model from an xsd by right-clicking a xsd and then do Texo > Create Ecore Model.

What is an Annotations Model

An annotations model is very similar to the ecore model. An annotations model has references to the original ecore model and adds extra information to store directives for code generation. The screenshot below shows an example of an annotations model.


Org.eclipse.emf.texo.annotations.model.png


The above screenshot shows an annotations model. The model follows the same structure as the original ecore model (the rental.ecore in this example). So there is a node for the EPackage, there are nodes for each EClass/EDataType and for each EStructuralFeature.

Within each node you can see the annotation. The nodes starting with 'Model Gen', in this case the annotations are for generating model code (the entities). For example the node 'Annotated EPackage: org.eclipse.emf.texo.test.model.samples.rental' has a child node 'Model Gen Annotation rental' which contains the properties used to generate java entities.

The screenshot selects a model gen annotation for the EAttribute RentalBicycle.type. In the properties view you can see the properties which are used by the code generation. For example the name of the generated getter and setter java methods.

How to create an Annotations Model

The first step in creating an annotations model. You can create a first annotations model by right clicking an ecore file and selecting the menu option 'Texo', then three menu options are shown to you (menu titles may slightly vary):

  • Create Initial Empty Annotations Model: this will create an annotations model with only nodes for the EPackages, the annotations model does not contain any annotations. These can be added individually (see below).


Org.eclipse.emf.texo.initial.annotations.model.png


  • Create/Update Annotations Model Structure: this will create an annotations model with nodes for all model elements of the original model. This means that there are nodes created for all EPackages, EClasses, EDataTypes and EStructuralFeatures. But no annotations are created, these can be added manually (see below).


Org.eclipse.emf.texo.complete.structure.annotations.model.png


  • Create/Update Completely Annotated Model: this will create a fully annotated model with an annotation for all model elements and all model elements of the original model are present.


Org.eclipse.emf.texo.fully.annotated.annotations.model.png

Manually adding annotations, Editing annotations

Annotations can be added manually by right clicking on a model node in the Annotations Model and then choose New Child. The available annotations which can be added are listed as children. In the screenshot below a Model Gen Annotation can be added. This type of annotation is used to control the generation of java entities.


Org.eclipse.emf.texo.complete.manually.adding.annotation.png


After adding an annotation you can edit the annotation properties in the properties view:


Org.eclipse.emf.texo.annotation.properties.png

How Texo uses the Annotations Model

The annotations model needs to be located in the same folder as the ecore model it applies to. The name of the file should be equal to the ecore model file name, only the file extension is different, instead of .ecore it should end on .annotationsmodel.

When code is generated for an EPackage or when an EPackage is referenced then Texo will automatically read the annotations model file. Texo will preserve all the annotations in the file and only add annotations or set features which have not been set manually.

Partially Annotating a Model

You only need to specify annotations for the parts of the code generation you want to override. So an annotations model with only a few annotations is fine. Texo will automatically add/generate annotations without overriding the manually created annotations. Even the properties/features of an annotation only need to be partially specified, Texo will automatically set the non-set properties/features of an annotation.

Code Generation Properties (annotations)

This section gives a detailed description of the properties/features in the annotations model used for code generation.

EPackage Model Gen Features

EClass Model Gen Features

EReference Model Gen Features

EDataType Model Gen Features

EEnum Model Gen Features

Back to the top