Prev Next

Substitution Examples

Field substitution macros can be used in one of two ways:

  • Direct Substitution or
  • Conditional Substitution

Direct Substitution

This form directly substitutes the corresponding value of the element in scope into the output.

Structure: %<macroName>%

Where <macroName> can be any of the macros listed in the Field Substitution Macros tables.

Examples

  • %className%
  • %opName%
  • %attName%

Conditional Substitution

This form of the macro enables alternative substitutions to be made depending on the macro's value.

Structure: %<macroName> (== "<text>")  ? <subTrue> (: <subFalse>) %

Where:

  • () denotes that values between the parentheses are optional
  • <text> is a string representing a possible value for the macro
  • <subTrue> and <subFalse> can be a combination of quoted strings and the keyword value; where the value is used, it is replaced with the macro's value in the output

Examples

  • %classAbstract=="T" ? "pure" :""%
  • %opStereotype=="operator" ? "operator" :""%
  • %paramDefault != "" ? " = " value : ""%

Those three examples output nothing if the condition fails. In this case the False condition can be omitted, resulting in this usage:

  • %classAbstract=="T" ? "pure"%
  • %opStereotype=="operator" ? "operator"%
  • %paramDefault != "" ? " = "value%

The third example of both blocks shows a comparison checking for a non-empty value or existence. This test can also be omitted.

  • %paramDefault ? " = " value : ""%
  • %paramDefault ? " = " value%

All of the above examples containing paramDefault are equivalent. If the parameter in scope had a default value of 10, the output from each of them would normally be:

= 10

Notes

  • In a conditional substitution macro, any white space following <macroName> is ignored; if white space is required in the output, it should be included within the quoted substitution strings

Learn more