Including requirements as comments in generated code

To facilitate the tracing of requirements to code and vice versa, you can specify that the code generated by IBM® Engineering Systems Design Rhapsody® should include comments that represent the requirements that are met by each code element.

Procedure

Note: This feature can be used for C, C++, or Java code.

To include requirements as comments in the generated code:

  1. Associate the requirement with the relevant model element by using one of the following approaches:
    • Create the requirement beneath the element in the browser
    • Create a dependency from the element to the requirement
    • Use an anchor to connect the requirement to the element
  2. Open the Features window for the relevant configuration, and on the Settings tab select the Include Requirements as Comments in Code option. (This controls the value of the CG::Configuration::IncludeRequirementsAsComments property.)
  3. Generate code.

Results

A comment that indicates which requirement was met by the element is generated after the comment that represents the element description. In addition, a comment is generated for the text of the requirement's Specification field.

Including requirements as comments in implementation files

If you are generating C or C++ code from your model, you can specify that requirements should be generated as comments in the implementation files, next to the operations that realize the requirements. There is also an option to have requirements generated as comments in both the specification and implementation files.

Procedure

To have requirements generated in implementation files:

  1. Create a dependency from an operation or global function to the requirement it realizes.
  2. Open the Features window for the relevant configuration, and on the Settings tab select the Include Requirements as Comments in Code option.
  3. Open the Features window for the dependency that you created.
  4. Apply the "trace" stereotype to the dependency.
  5. Set the value of the Show in field to Implementation or Specification+Implementation.
  6. Generate code for the class that contains the operation.

Results

If you set the value of the Show in field to Implementation, the comment for the requirement is generated in the implementation file, before the relevant operation.

If you set the value of the Show in field to Specification+Implementation, comments are generated in both the specification and implementation files, before the relevant operation.

Note:

If you want to customize the text that is generated for the requirement in the implementation file, modify the value of the [lang]_CG::Requirement::DescriptionTemplateForImplementation property.

If you want to customize the text that is generated for the requirement in the specification file, modify the value of the [lang]_CG::Requirement::DescriptionTemplate property.

The values of these two properties can be set for the whole model, for individual packages, or for individual requirements.