Field substitution macros can be used in one of two ways:
- Direct Substitution or
- Conditional Substitution
This form directly substitutes the corresponding value of the element in scope into the output.
Where <macroName> can be any of the macros listed in the Field Substitution Macros tables.
This form of the macro enables alternative substitutions to be made depending on the macro's value.
Structure: %<macroName> (== "<text>") ? <subTrue> (: <subFalse>) %
- () 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
- %classAbstract=="T" ? "pure" :""%
- %opStereotype=="operator" ? "operator" :""%
- %paramDefault != "" ? " = " value : ""%
These 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 these 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:
- 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