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
context Person def:
income : Integer = self.job.salary->sum()DeriveExpression
A derived value expression that may be linked to a property.
Example
context Person::income : Integer
derive: if underAge
then (parents.income->sum() * 1/100).round()
else job.salary->sum()
endifEnumerationExpression
Resolves enumeration values registered via registerEnum.
IfExpression
Executes the then branch if the condition is truthy, otherwise the else branch.
Example
if self.age < 18 then 'minor' else 'adult' endifInvariantExpression
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
context Person inv:
self.age > 0LetExpression
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
context Person inv:
let income : Integer = self.job.salary->sum() in
if isUnemployed then
income < 100
else
income >= 100
endifOclIsKindOfExpression
Checks if self is an instance of the class identified by the name (including subclasses).
Signature
oclIsKindOf(type : T) : BooleanOclIsTypeOfExpression
Checks if self is an instance of exactly the class identified by the name.
Signature
oclIsTypeOf(s : String) : BooleanOclIsUndefinedExpression
Checks if self is undefined or null.
Signature
oclIsUndefined() : BooleanPackageDeclaration
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.