Contents > 8 Defining Custom Design Metrics and Rules > 8.3 Definition of Design Rules > 8.3.5 Word lists

8.3.5 Word lists

One aspect of design rule checking involves the use of reserved keywords of the UML or programming languages as names of model elements.

To check model element names for keywords, we define a list of keywords in the metric definition file, and add a rule that checks for names on the list:

<wordlist name="CPP" ignorecase="false" > 
  <entry word="auto" />
  <entry word="bool" />
  <entry word="break" />


<rule name="Keyword" domain="class" category="Naming" severity="1-high">
  <description>Class name is a reserved C++ keyword.</description>
  <violation condition="name onlist CPP" value="name" />
The word list is enclosed in wordlist tags. Attribute name defines a name for the keyword list, which is used later to reference the list. Attribute ignorecase controls if uppercase and lowercase letters should be distinguished when searching for a word on the list. For programming languages that are case-insensitive, set ignorecase to "true". By default, ignorecase is "false" (i.e., case-sensitive search).

The word list contains a list of entry elements. An entry has one required attribute word that contains one word of the list.

To check if a word is on a list, there is a special operator onlist which you can use in condition expressions (see Section 8.5.4 "Condition Expressions"). In the condition expression of rule "Keyword" above, the left hand operator yields the name of the class, the right hand operator is the name of the word list to check.

Note that while the main purpose of the word list feature is to define design rules checking for keywords, there are other possible uses: