Roundtripping class code

When generating code, IBM® Rational® Rhapsody® places all user code for method bodies and transition code written in statecharts between special annotation symbols.

About this task

The following table lists the special annotation symbols.

Table 1. Special annotation symbols for generated code
Language Body Annotation Symbols
Ada --+[ <ElementType> <ElementName>
--+]
C /*#[ <ElementType> <ElementName> */
/*#]*/
C++ and Java //#[ <ElementType> <ElementName>
//#]

For example, the following Initialize() operation for the Connection class in the PBX sample contains user code that was entered in the Implementation field of the Operation window. The user code is placed between the annotation symbols when code is generated for the class:

void Connection::Initialize() {
   //#[ operation Initialize()
   DigitsDialed = 0;
   Digits[0] = 0;
   Digits[1] = 0;
   Busy = FALSE;
   Extension = 0;
   //#]
}

You can edit the code between the annotation symbols in a text editor and then roundtrip your changes back into the model. The roundtripped edits are retained upon the next code generation. This feature Rational Rhapsody keeps the code and the model synchronized to provide model-code associativity.

Note: Any text edits made outside the annotation symbols might be lost with the next code generation.

To roundtrip code changes back into the model:

Procedure

  1. Edit the generated class code between the //#[ and //#] annotation symbols.
  2. In the browser or diagram, right-click the class containing the code that you edited and select Roundtrip.

Results

If you view the Implementation box of the specification window for the operation (or the statechart for the class if you edited transition code), you can see that your text edits were added to the model.


Feedback