Skip to content

Expressions

Core OCL expressions supported by OCL.js.

DefExpression

The Let expression allows a variable to be used in one OCL expression. To enable reuse of variables/operations over multiple OCL expressions, one can use a Constraint with the stereotype «definition», in which helper variables/operations are defined. All variables and operations defined in the «definition» constraint are known in the same context as any property of the Classifier.

Example

txt
context Person def:
income : Integer = self.job.salary->sum()

DeriveExpression

A derived value expression that may be linked to a property.

Example

txt
context Person::income : Integer
derive:  if underAge
 then (parents.income->sum() * 1/100).round()
 else job.salary->sum()
endif

EnumerationExpression

Resolves enumeration values registered via registerEnum.


IfExpression

Executes the then branch if the condition is truthy, otherwise the else branch.

Example

txt
if self.age < 18 then 'minor' else 'adult' endif

InvariantExpression

The OCL expression can be part of an Invariant which is a Constraint stereotyped as an «invariant». An OCL expression is an invariant of the type and must be true for all instances of that type at any time.

Example

txt
context Person inv:
self.age > 0

LetExpression

Sometimes a sub-expression is used more than once in a constraint. The let expression allows one to define a variable that can be used in the constraint.

Example

txt
context Person inv:
let income : Integer = self.job.salary->sum() in
if isUnemployed then
    income < 100
else
    income >= 100
endif

OclIsKindOfExpression

Checks if self is an instance of the class identified by the name (including subclasses).

Signature

txt
oclIsKindOf(type : T) : Boolean

OclIsTypeOfExpression

Checks if self is an instance of exactly the class identified by the name.

Signature

txt
oclIsTypeOf(s : String) : Boolean

OclIsUndefinedExpression

Checks if self is undefined or null.

Signature

txt
oclIsUndefined() : Boolean

PackageDeclaration

Groups and organises OCL constraints into packages.


PostExpression

A condition that must be fulfilled after the operation addressed by the parent OperationCallExpression has been executed.


PreExpression

A condition that must be fulfilled before executing the operation addressed by the parent OperationCallExpression.


VariableExpression

Resolves variables. Simple values are returned as-is (e.g. self.age: number); collections are aggregated.

Released under the MIT License.