Add New Stereotyped Templates

Return to Introduction  Previous page  Next page

Sometimes it is useful to define a specific code generation template for use with elements of a given stereotype. This enables different code to be generated for elements, depending on their stereotype. Enterprise Architect provides some default templates, which have been specialized for commonly used stereotypes in supported languages. For example the Operation Body template for C# has been specialized for the property stereotype, so that it automatically generates its constituent get and set methods. Users can override the default stereotyped templates as described in the previous topic. Additionally users can define templates for their own stereotypes, as described below.

Add A New Stereotyped Template

To override a default code generation template, follow the steps below.

1.Select the Configuration | Code Generation Templates menu option to open the Code Templates Editor.
2.Select the appropriate language, from the Language list.
3.Select one of the base templates, from the Templates list.
4.Click on the Add New Stereotyped Override button. The New Template Override dialog displays.
5.Select the required Feature and/or Class stereotype and click on the OK button.
6.The new stereotyped template override displays in Stereotype Overrides list, marked as modified.
7.Make the required modifications in the Code Templates Editor.
8.Click on the Save button. This stores the new stereotyped template in the .EAP file.

Enterprise Architect can now use the stereotyped template, when generating code for elements of that stereotype.

Note that Class and feature stereotypes can be combined to provide a further level of specialization for features. For example, if properties should be generated differently when the class has a stereotype MyStereotype, then both property and MyStereotype should be specified in the New Template Override dialog.