Class InsertIsPresentChecksVisitor

java.lang.Object
de.monticore.tf.odrules.subConstraints.InsertIsPresentChecksVisitor
All Implemented Interfaces:
CommonExpressionsVisitor2, de.monticore.visitor.IVisitor

public class InsertIsPresentChecksVisitor extends Object implements CommonExpressionsVisitor2
Created by Alexander Wilts on 16.01.2017.

This visitor inserts isPresent()-checks into expressions that contain optional variables.

Let $O be an optional variable in this expression: isValid($O). In case that no value is present for $O, the evaluation of this expression would produce a NoSuchElementException. In order to prevent this we add an isPresent()-check to the expression like this: !$O.isPresent || isValid($O)

Additionally we have to consider the context of the optional. The isPresent-Check has to be implemented differently depending on whether the optional is used inside an OR-Expression or an AND-Expression.

Examples for normal variable $A and optional variable $O:

$A && $O results in $A && (!$O.isPresent || isValid($O)) $A || $O results in $A || ($O.isPresent && isValid($O))