Method restrictions
The rule language supports method calls as expressions and actions.
- Expression
-
Expressions can be used in both rule conditions and rule actions.
Expressions can consist of a call to a method or a call to a constructor. If the expression consists of a call to a method, the method must be a pure function.
- Action
-
Actions are used in rule actions only. Actions modify the value of variables and attributes.
If the action consists of a call to a method, the method must be a modifier (setter, adder, remover, or clearer).
Expressions and actions need to meet the restrictions that are described in this topic to be properly evaluated.
get method
A getter returns the value of an attribute for a class or object.
It must start with the get prefix. It can also start with the
is prefix with Boolean values.
A get method must be pure. It can be a static method or an instance method.
set method
A setter assigns or updates the value of an attribute for a class or object.
It must start with the set prefix and has one parameter, a value.
set method can be a static method or an instance method. It must meet the
following requirements:- At the end of the method call, the value of the attribute must equal the given value.
- The other attributes of the class or object must have the same value at the start and at the end of the method call.
- The attributes of other classes or objects must have the same value at the start and at the end of the method call.
- Each variable must have the same value at the start and at the end of the method call.
add method
An adder adds a value to a collection-valued attribute for a class or object.
It must start with the add prefix and has one parameter, a value.
add method can be a static method or an instance method. It must meet the
following requirements:- At the end of the method call, the collection must contain the new value in addition to the values it already contained before the method call.
- The other attributes of the class or object must have the same value at the start and at the end of the method call.
- The attributes of other classes or objects must have the same value at the start and at the end of the method call.
- Each variable must have the same value at the start and at the end of the method call.
remove method
A remover removes a value from a collection-valued attribute for a class or object.
It must start with the remove prefix and has one parameter, a value.
remove method can be a static method or an instance method. It must meet the
following requirements:- At the end of the method call, the collection must contain the same values that it contained before the method call, except for the value that was removed.
- The other attributes of the class or object must have the same value at the start and at the end of the method call.
- The attributes of other classes or objects must have the same value at the start and at the end of the method call.
- Each variable must have the same value at the start and at the end of the method call.
clear method
A clearer clears all the values from a collection-valued attribute for a class or object.
It must start with the clear prefix. It does not have any parameter.
clear method can be a static method or an instance method. It must meet the
following requirements:- At the end of the method call, the collection must contain no value.
- The other attributes of the class or object must have the same value at the start and at the end of the method call.
- The attributes of other classes or objects must have the same value at the start and at the end of the method call.
- Each variable must have the same value at the start and at the end of the method call.
The add, remove, and clear methods must be
annotated with @CollectionAttribute, as explained in Collections.