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/Direct Java Annotations

Introduction

Texo supports a straight forward method to copy java annotations defined in your model into the generated code. Texo's merge logic will preserve java annotations for methods/members/types which have set the javadoc term @generatedNOT.

Java annotations can be specified for the EClass and the EStructuralFeatures in a model. You can control where Texo places the java annotation: in the type (the java Class), the getter, setter or the java member.

This document describes a way for working with manual java annotations. Other Texo logic will (in the future) support automatic generation of java annotations.

Specifying Java Annotations in the model

Java annotations are defined in the model as EAnnotations. The EAnnotation should be defined with the following values:

  • the source: texo.java.annotation
  • the key:
    • type: the annotation is placed on Classes
    • getter: the annotation is placed on the getter generated for the EStructuralFeature
    • setter: the annotation is placed on the setter generated for the EStructuralFeature
    • field: the annotation is placed on the java member generated for the EStructuralFeature
  • the value: one or more java annotations, using their fully qualified names pre-fixed with the @ symbol, for example:

@org.eclipse.emf.texo.test.models.annotations.TestAnnotationOne("type")

The annotation with key: 'type' should be placed on an EClass, the getter, setter, field annotations are placed on an EStructuralFeature normally.

Examples

The screenshot below show some examples of specifying annotations on the well-know library model. The example model with its annotations can be downloaded here.


Org.eclipse.emf.texo.library.java.annotations.png

Specifying generic annotations

Sometimes you have an annotation which is to be placed on every generated class. Texo supports this feature. Annotations can be placed on all model elements. Texo will search through the model for an annotation. This means that you can define a java annotation on the EPackage which is used for every Class. When Texo checks if there is a java annotation on an EClass and it can't find any, it will check the EPackage for an annotation with the key: type. If it finds one on the EPackage it will use that for the EClass.

Note if an EClass has a java annotation specified then it will not check for annotations on the containing model element.

The same logic is used when searching for a java annotation on an EStructuralFeature, if it is not found then the EClass is checked, and then the EPackage. Note that java annotations for EStructuralFeatures should use the key: getter, setter or field.

Back to the top