Code generation templates 

You can use code templates to adjust the code formatting and, to some degree, the contents that the transformation produce.

Code templates are strings that you can edit in the Eclipse properties. To access the properties, complete the following steps:

  1. Click Window > Preferences.

  2. Expand Modeling, expand Transformations, and click UML to C++ Transformation.

  3. Click the Templates tab.

You can edit the text of the templates ("Header" for header .h files, "Body" for body .cpp files), save it, and use it in different Eclipse workspaces.

A simplified code template for the header file of the class could look like the following example:

class $(name)

{

            $(body)

};

In this example the transformation replaces the $(name) and $(body) tags with actual values.

The template for the body file of the class could look like the following example:

$(includes)

$(body)

The transformation attempts to manage the white space in the generated code. If a tag has only white space between the beginning of the line and the tag, the transformation indents the replacement code with the white space. The $(left) tag at the beginning of the line turns off the indentation for the line. You can use the $(del) tag to indicate "soft" lines, which are lines that the transformation removes if they do not have any information.

You can import and export templates from the Eclipse workspace that stores them by using the Import and Export buttons on the plug-in Preferences page. If you export a template, the system creates an XML file that represents a set of templates that you can import to another computer or workspace.

To revert to the default set of templates for the C++ transformation, on the plug-in Properties page click Restore Defaults.

Top

Terms of use | Feedback
(C) Copyright IBM Corporation 2004. All Rights Reserved.