Contents > 8 Defining Custom Design Metrics and Rules > 8.1 Definition of Metrics > 8.1.1 Projection > 8.1.1.5 Filter Attributes "condition" and "targetcondition"
8.1.1.5 Filter Attributes "condition" and "targetcondition"
Besides filtering elements of a certain type, you can filter for
elements that satisfy a certain condition. Assume we have defined a
multi-valued attribute 'ownedoperations' for classes, which contains
the operations of the class.
<metric name="NumPublicOps" domain="class">
<description>The number of public operations in the class.</description>
<projection relset="ownedoperations" condition="visibility='public'" />
</metric>
The condition expression "visibility='public'" is evaluated for each
element in the set, only operations that fulfill this condition are
counted. The admissible operations for condition expressions are
described in Section 8.5.4 "Condition Expressions".
If you combine the "condition" attribute with the "element" and
"eltype" attributes, the expression will be evaluated for the model
elements returned by those attributes, e.g.,
<metric name="AbstractDep" domain="package">
<description>
The number of abstract classes the class depends on.
</description>
<projection relation="depclient" target="dependency" element="depsupplier"
eltype="class" condition="abstract='true'"/>
</metric>
With attribute "targetcondition" you can specify a condition that is
always evaluated for the element returned by the "target" attribute,
even if the "element" and "eltype" attributes are used. The following
example assumes that "stereotypename" is an attribute or metric that
yields the name of the stereotype of a model element:
<metric name="Realize" domain="package">
<description>The number of classes the class realizes.</description>
<projection relation="depclient" target="dependency"
targetcondition="stereotypename='realize'" element="depsupplier"
eltype="class" />
</metric>
This metric only counts dependencies with stereotype
<<realize>> that have a class as supplier.
Prev |
Up |
Next |
Section 8.1.1.4 "Filter Attributes "element" and "eltype"" | Contents | Section 8.1.1.6 "Filter Attribute "scope"" |