Expressions

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. This «definition» Constraint must be attached to a Classifier and may only contain variable and/or operation definitions, nothing else. All variables and operations defined in the «definition» constraint are known in the same context as where any property of the Classifier can be used. Such variables and operations are attributes and operations with stereotype «OclHelper» of the classifier. They are used in an OCL expression in exactly the same way as normal attributes or operations are used. The syntax of the attribute or operation definitions is similar to the Let expression, but each attribute and operation definition is prefixed with the keyword ‘def’ as shown below.
context Person def: income : Integer = self.job.salary->sum()

DeriveExpression

A derived value expression is an expression that may be linked to a property

IfExpression

The IfExpression allows to execute a statement if the given condition is truthy. Otherwise the else part is taken.

InitExpression

InvariantExpression

NativeJsFunctionCallExpression

OclIsKindOfExpression

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

oclIsKindOf(type : T) : Boolean

OclIsTypeOfExpression

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

oclIsTypeOf(s : String) : Boolean

OclIsUndefinedExpression

Checks if self is not defined

oclIsUndefined() : Boolean

OperationCallExpression

PackageDeclaration

In order to group and organise OCL constraints, packages can be used.

PostExpression

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

PreExpression

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

VariableExpression

Resolve variables. Simple values are returned as is (e.g. self.age: number), collections are aggregated.

Collection Expressions

AnyExpression

Return the first element that matches the given OclExpression.

any(expr : OclExpression) : T

self.collection->any(i < 2)

AppendExpression

AsSetExpression

Returns the given collection as set, containing unique entries.

asSet() : Collection

self.collection->asSet()

AtExpression

Returns the element of the collection at index index.

at(index : Number) : T

self.collection->at(2)

CollectExpression

Returns a collection having the same size as the original one. The given oclExpression is applied on all elements of the collection.

collect(expr : OclExpression) : Collection

self.children->collect(age)

ExistsExpression

Operation which checks whether a collection contains an element specified by expr.

exists(expr : OclExpression) : Boolean

self.collection->exists(i | i < 2)

FirstExpression

Returns the first element of the collection.

first() : T

self.collection->first()

ForAllExpression

IsEmptyExpression

Returns true if self is empty, false otherwise.

isEmpty() : Boolean

self.cars->isEmpty()

LastExpression

Returns the last element of the collection.

last() : T

self.collection->last()

NotEmptyExpression

Returns true if self is not empty, false otherwise.

notEmpty() : Boolean

self.cars->notEmpty()

OneExpression

Returns true of there is exactly one element matching the given expression, false otherwise.

one(expr : oclExpression) : boolean

RejectExpression

Returns a collection with all elements except for those who the given oclExpression validates to true.

reject(expr : oclExpression) : Collection

self.customer->reject(underage)

SelectExpression

Selects all elements from collection which fit the expr.

select(expr : oclExpression) : Collection

self.collection->select(item | item.name = "random")

SizeExpression

Returns the size of the given collection.

size() : Number

self.collection->size()

SumExpression

Returns the sum of all elements contained in self if they support the ‘+’ operation.

sum() : Number

self.jobs.salary->sum()

UnionExpression

Returns a collection containing all elements of self and all elements of the passed in collection.

union(c : Collection) : Collection

self.collection->union(self.anotherCollection)

Gate Expressions

AndExpression

A B A and B
false false false
false true false
true false false
true true true
false and true

ImpliesExpression

A B A implies B
false false true
false true true
true false false
true true true
false implies true

NotExpression

A NOT A
true false
false true
not false

OrExpression

A B A or B
false false false
false true true
true false true
true true true
false or true

XorExpression

A B A xor B
false false false
false true true
true false true
true true false
false xor true

String Expressions

ConcatExpression

Returns a string that is concatenated using source and body

String::concat (s : String) : String

self.name.concat("string")

IndexOfExpression

Returns the index of the given string in self or 0 if it is not condained.

String::indexOf (s : String) : Number

self.name.indexOf("string")

SubstringExpression

Returns a string containing all characters from self starting from index start up to index end included. Both start and end parameters should be contained between 1 and self.size() included. start cannot be greater than end.

String::substring (start : Number, end : Number) : String

self.name.substring(0,2)

ToIntegerExpression

Tries to convert a string to a number.

String::toInteger () : Number

"3.414".toInteger()

ToLowerCaseExpression

Returns self as lower case string.

String:: toLowerCase () : String

self.name.toLowerCase()

ToRealExpression

Tries to convert a string to a number.

String:: toReal () : Number

"3.414".toReal()

ToUpperCaseExpression

Returns self into upper case string.

String:: toUpperCase () : String

self.name.toUpperCase()

Math Expressions

AbsExpression

Returns the absolute value of self.

Number::abs () : Number

-2.abs() = 2

AdditionExpression

Addition

Symbol: +

1 + 2

DivExpression

Returns the integer quotient of the division of self by i.

Number::div ( i : Number ) : Number

3 div 2 = 1

DivideExpression

Division

Symbol: /

17 / 2

MaxExpression

Returns the greatest number of self and i.

Number::max ( i : Number ) : Number

6.max(3) = 6

MinExpression

Returns the lowest number of self and i.

Number::min ( i : Number ) : Number

6.max(3) = 3

ModuloExpression

Returns the number remainder of the division of self by i.

Number::mod ( i : Number ) : Number

4 mod 2 = 0

MultiplyExpression

Multiply

Symbol: *

1 * 2

PowerExpression

Power

Symbol: ^

4 ^ 2

RoundExpression

Returns the nearest number to self.

Number::round () : Number

SqrtExpression

Returns the square root of self.

Number::sqrt () : Number

9.sqrt() = 3

SubstractionExpression

Substraction

Symbol: -

1 - 2

Literal Expressions

BooleanExpression

NilExpression

NumberExpression

StringExpression

Context Expressions

ClassifierContextExpression

Define invariants and definitions on a given types

context <Type> (inv|def)

OperationContextExpression

The Operation Context Expression allows to define pre and or post conditions of functions.

context Person::kill() (pre|post)

context Person::setAge(age: number)
    pre: age > 0

PropertyContextExpression

A PropertyContextDefinition allows to initialize or derive a value for the targeted property.

context Person::age (init|derive)