Class ExpressionEvaluator

    • Constructor Detail

      • ExpressionEvaluator

        public ExpressionEvaluator​(Expression expression,
                                   VariableDeclaration iterator,
                                   java.util.List<? extends VariableDeclaration> declarators)
        Creates an expression evaluator.
        Parameters:
        expression - the expression to evaluate on
        iterator - the iterator variable, one of declarators
        declarators - all declarators of this expression in source sequence, if null a list consisting of iterator will be created
    • Method Detail

      • getDeclaratorsCount

        public int getDeclaratorsCount()
        Returns the number of declarators.
        Returns:
        the number of declarators
      • getDeclarator

        public VariableDeclaration getDeclarator​(int index)
        Returns the specified declarator.
        Parameters:
        index - the 0-based index
        Returns:
        the declarator
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= getDeclaratorsCount()
      • getResultType

        public TypeDescriptor<?> getResultType()
        Returns the explicit result type of an aggregating iterator.
        Returns:
        the explicit result type (if there are multiple declarators than it's the first one if it has a default value), null else
      • getResultDeclarator

        private VariableDeclaration getResultDeclarator()
        Returns the explicit result declarator of an aggregating iterator.
        Returns:
        the explicit declarator (if there are multiple declarators than it's the first one if it has a default value), null else
      • getResultValue

        public java.lang.Object getResultValue()
                                        throws VilException
        Returns the explicit result value of an aggregating iterator.
        Returns:
        the explicit value, null else
        Throws:
        VilException - in case that obtaining the result value fails
      • bind

        public void bind​(EvaluationVisitor evaluationVisitor)
        Binds the evaluation visitor. Must be called before evaluate(Object).
        Parameters:
        evaluationVisitor - the evaluation visitor used for evaluating the contained expression
      • unbind

        public void unbind()
        Unbinds the evaluation visitor (see evaluate(Object)).
      • evaluate

        public java.lang.Object evaluate​(java.lang.Object iteratorValue)
                                  throws VilException
        Evaluates the wrapped expression. This method is intended to be called from the type being evaluated (which does not have access to the evaluationVisitor). Thus, bind(EvaluationVisitor) must be called before and unbind() shall be called by the type being evaluated.
        Parameters:
        iteratorValue - the current value when iterating with the expression
        Returns:
        the result of evaluating expression in the current context of evaluationVisitor
        Throws:
        VilException - in case that the evaluation fails
      • getExpression

        public Expression getExpression()
        Returns the expression. Before evaluating this expression, the iterator variable must be bound with an actual value.
        Returns:
        the expression to be evaluated
      • getIteratorVariable

        public VariableDeclaration getIteratorVariable()
        Returns the iterator variable.
        Returns:
        the iterator variable
      • inferType

        public TypeDescriptor<?> inferType()
                                    throws VilException
        Description copied from class: Expression
        Infers the type of this expression including the type of the contained sub-expressions.
        Specified by:
        inferType in class Expression
        Returns:
        the type of this expression
        Throws:
        VilException - in case that inferring the type fails
      • accept

        public java.lang.Object accept​(IExpressionVisitor visitor)
                                throws VilException
        Description copied from class: Expression
        Visits the expression.
        Specified by:
        accept in class Expression
        Parameters:
        visitor - the visitor
        Returns:
        the result of visiting this expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • getStringValue

        public java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
        Description copied from interface: IStringValueProvider
        Returns the string value of this object.
        Specified by:
        getStringValue in interface IStringValueProvider
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • initializeDeclarators

        public void initializeDeclarators()
                                   throws VilException
        Initializes the declarators in case of default values given and changes the runtime environment accordingly.
        Throws:
        VilException - if evaluating or setting the evaluated value fails