Code and Transform Templates




See also


Code and transform templates enable you to customize code generation of existing languages or customize an MDA Transformation.

Generate Source Code

Model Transformation


Start Point

By default the File template is the start point of a process though the templates.

Calls can be made to the predefined templates as well as to user defined templates.

The order of the predefined templates in the Code Template Editor and Transformation Template Editor relates to the hierarchical order of the objects and their parts that are to be processed

    File consists of Classes which can contain Attributes and Operations.


Base Templates

Built-in Transformations

Calling Templates


Within any template, other templates can be called using %TemplateName%. The enclosing percent (%) signs indicate a macro.

You would use this for a single call to the ClassBody template, %ClassBody%, as below:


%list="TemplateName" @separator="\n" @indent="  "%


The %list macro performs an iterative pass on all the objects in the scope of the current template and calls the TemplateName for each of these:


%list="ClassBody" @separator="\n" @indent="  "%


After generation or transformation, each macro is substituted to produce the generated output; for a language such as C++, the result of processing the above template might be:



* This is an example class note generated using code templates

* @author Sparx Systems


class ClassA: public ClassB









List Macro

Execution of Code Templates

Each template is designed for use with a particular element; for example, the ClassNotes template is to be used with UML Class elements.

The element that is currently being generated is said to be in scope; if the element in scope is stereotyped, Enterprise Architect looks for a template that has been defined for that stereotype.

If a match is found, the specialized template is executed; otherwise the default implementation of the base template is used.

Templates are processed sequentially, line by line, replacing each macro with its underlying text value from the model.



Transfer Templates Between Projects

If you edit a base Code Generation or Transformation template, or create a customized template, you can copy them from one project to another as Reference Data.


Export Code Generation and Transformation Templates

Import Code Generation and Transformation Templates