The placement of a precondition in the UML metamodel is shown in Figure 31. The following well-formedness rule must hold. This rule also defines the value of the contextual Classifier.
context Expression
inv:
self.constraint.stereotype.name
= 'precondition' -- A
and
self.constraint.constrainedElement->size() =
1
-- B
and
self.constraint.constrainedElement->any(true).oclIsKindOf(BehavioralFeature)
-- C
and
self.constraint.constrainedElement->any(true)
-- D
.oclAsType(BehavioralFeature).owner->size() = 1
implies
contextualClassifier =
self.constraint.constrainedElement->any(true)
.oclAsType(BehavioralFeature).owner
and
self.bodyExpression.type.name = 'Boolean'
[2] Inside a precondtion constraint the use of @pre is not allowed.
context
ExpressionInOcl
inv: --