Contents > 8 Defining Custom Design Metrics and Rules > 8.3 Definition of Design Rules > 8.3.3 Projection for Rules

8.3.3 Projection for Rules

The projection procedure for rules calculates a set projection for a model element (see Section 8.2.1 "Projection"), and reports any elements contained in there as violation of the rule. Consider this example:

<rule name="MissingGuard" domain="state" category="Correctness" 
      severity="1-high">
  <description>If there are two or more transitions from a choice 
      state, they all must have guards.</description>
  <projection precondition="kind='choice' and Outgoing>1"
      relation="transsource" target="transition" condition="Guards=0"
</rule>
Attributes relation, target, and condition define the projection, and are processed exactly the same way as we know them from set projections. In the above example, the projection yields, for a state, the set of outgoing transitions that have no guard.

In the context of a rule, a projection can have three additional attributes:

<rule name="DupName" domain="state" category="Correctness" severity="1-high">
  <description>The compound state has two or more states of 
                 the same name.</description>
  <projection relation="context" target="state" condition="name!=''"
              valueset="name" mincnt="2" />
</rule>
For rule "DupName", the projection defines the value set of names of the states of a compound state (omitting anonymous states). By setting mincnt="2", only names that occur two times or more will be reported.

Note the following restrictions that apply in the context of a rule projection: