Contents > 8 Defining Custom Design Metrics and Rules > 8.1 Definition of Metrics > 8.1.1 Projection > Attribute "nesting" Attribute "nesting"

Like the "recurse" attribute, the "nesting" attribute takes the transitive closure of relations or sets into account. However, it has a very different meaning; with the "nesting" attribute, you determine the length of the longest path in the transitive graph of a relation.

The "nesting" attribute takes the values "true" or "false" (default). When "nesting" is set to true for a project metric m for type t, the metric is recursively applied to all "compatible" elements in the projection. An element is "compatible" if its type is t, or if its type is a subtype or supertype of t and metric m is also defined for the type. The maximum value of all values returned, increased by one, is the value of the metric. Example:

<metric name="DIT" domain="class">
  <description>Depth of the class in the inheritance tree.</description>
  <projection relation="genchild" target="generalization" 
              element="genparent" eltype="class" nesting="true"/> 
Without the nesting="true" attribute, the above metric would simply count the number of parent classes of a class. With "nesting" set to true, the meaning of the metric changes as follows: calculate the DIT for all parents of the class, take the maximum DIT over all parent classes, increase it by one. As a result, this metric calculates the longest path from the class to the root in the inheritance graph.

The "nesting" attribute cannot be combined with the "sum" attribute or the "recurse" attribute. It can, however, be combined with all other attributes, including the filter attributes (target, targetcondition, element, eltype, scope, condition). Recursive calls are not applied to elements that do not fulfill the filter criteria.