Contents > 8 Defining Custom Design Metrics and Rules > 8.2 Definition of Sets > 8.2.1 Projection > 8.2.1.1 Attribute "recurse"

8.2.1.1 Attribute "recurse"

The recurse attribute known from metrics projections is also available for sets. By setting recurse="true", SDMetrics recursively calculates and takes the union of sets for compatible elements in the relation. The element is compatible if it is of the same type as the domain of the metric, or a subtype or supertype and the set is also defined for the type.

For example, we can easily change the definition of the set of children classes from above to yield the element set of descendents classes:

<set name="Descendents" domain="class"> 
  <description>The set of descendents of a class.</description>
  <projection relation="genparent" target="generalization"
              element="genchild" eltype="class" recurse="true"/>
</set>
For each child class, the set "Descendents" is evaluated, and the union of all these sets is taken. The child classes themselves also are included in the set. This effectively produces the set of descendents for a class.