Prev - Next - Down | SDMetrics - the UML design measurement tool |

Contents > 8 Defining Custom Design Metrics and Rules > 8.5 Expression Terms > 8.5.2 Metric Expressions > 8.5.2.2 Special Operators

**1. The "dot" operator**

In an expression term, it is sometimes useful to refer to attribute or metric values of related elements. This can be accomplished with the dot operator.

For example, to access the name of an operation's owner, we simply write "context.name". The left hand side expression "context" refers to the owner of the operation, which has to be some model element (e.g., a class). For that model element, the right hand side expression "name" is evaluated, which yields the value of its attribute "name".

In general, evaluating expression `a.b` for a model element
*e* works as follows:

- Evaluate metric expression
`a`for model element*e*. This yields a second model element,*e'*. - Evaluate metric expression
`b`for model element*e'*. This is the result of`a.b`. - If an error occurs during evaluation of expression
`a`or`b`, or if expression`a`does not yield a model element, no error is reported. Instead, an empty string is returned as value of`a.b`.

If we want to determine the package in which a class resides, we usually access it via its "context" attribute. However, the owner of a class need not be a package. For an inner class, for example, the "context" attribute yields its containing outer class.

The "upto" operator in the expression "context upto (typeof(self)='package')" follows the "context" attribute, across several model elements if necessary, until it encounters a model element of type package.

In general, evaluation of the expression `a upto b` for a model
element *e* works as follows:

- Evaluate metric expression
`a`for model element*e*. Let*e'*denote the result of this evaluation. - If
*e'*is not a model element, an empty string is returned as value of`a upto b`. - Evaluate condition expression
`b`for model element*e'*. - If the result of
`b`is true, then*e'*is returned as result of the metric expression`a upto b`. - Otherwise, set
*e=e'*and repeat from step 1.

Similar to the "upto" operator, the "topmost" operator successively evaluates a condition expression for a chain of model elements. Whereas the "upto" operator returns the first element that fulfills the condition expression, the "topmost" operator returns the last element in the chain that fulfills the condition expression.

The "topmost" operator in the expression "context topmost (typeof(self)='package')" yields the top-level package that contains the element.

In general, evaluation of the expression `a topmost b` for a
model element *e* works as follows:

- Set
*result*to be the empty string. - Evaluate metric expression
`a`for model element*e*. Let*e'*denote the result of this evaluation. - If
*e'*is not a model element, return*result*as value of`a upto b`. - Evaluate condition expression
`b`for model element*e'*. - If the result of
`b`is true, set*result=e'*. - Set
*e=e'*and repeat from step 2.

Prev | Up | Next |

Section 8.5.2.1 "Mathematical Operators and Functions" | Contents | Section 8.5.3 "Set Expressions" |