Class Interpreter

    • Field Detail

      • INTER

        protected static final java.lang.ThreadLocal<Interpreter> INTER
        The thread local interpreter.
      • fp

        protected int fp
        Frame height.
      • frame

        protected final Frame frame
        Symbol values.
    • Constructor Detail

      • Interpreter

        protected Interpreter​(Engine engine,
                              JexlOptions opts,
                              JexlContext aContext,
                              Frame eFrame)
        Creates an interpreter.
        Parameters:
        engine - the engine creating this interpreter
        aContext - the evaluation context, global variables, methods and functions
        opts - the evaluation options, flags modifying evaluation behavior
        eFrame - the evaluation frame, arguments and local variables
      • Interpreter

        protected Interpreter​(Interpreter ii,
                              JexlArithmetic jexla)
        Copy constructor.
        Parameters:
        ii - the interpreter to copy
        jexla - the arithmetic instance to use (or null)
    • Method Detail

      • call

        protected java.lang.Object call​(JexlNode node,
                                        java.lang.Object target,
                                        java.lang.Object funcNode,
                                        ASTArguments argNode)
        Calls a method (or function).

        Method resolution is a follows: 1 - attempt to find a method in the target passed as parameter; 2 - if this fails, seeks a JexlScript or JexlMethod or a duck-callable* as a property of that target; 3 - if this fails, narrow the arguments and try again 1 4 - if this fails, seeks a context or arithmetic method with the proper name taking the target as first argument;

        *duck-callable: an object where a "call" function exists
        Parameters:
        node - the method node
        target - the target of the method, what it should be invoked upon
        funcNode - the object carrying the method or function or the method identifier
        argNode - the node carrying the arguments
        Returns:
        the result of the method invocation
      • evalCatch

        private java.lang.Object evalCatch​(ASTReference catchVar,
                                           JexlNode catchBody,
                                           JexlException caught,
                                           java.lang.Object data)
        Evaluate the catch in a try/catch/finally.
        Parameters:
        catchVar - the variable containing the exception
        catchBody - the body
        caught - the caught exception
        data - the data
        Returns:
        the result of body evaluation
      • evalIdentifier

        private java.lang.Object evalIdentifier​(ASTIdentifierAccess node)
        Evaluates an access identifier based on the 2 main implementations; static (name or numbered identifier) or dynamic (jxlt).
        Parameters:
        node - the identifier access node
        Returns:
        the evaluated identifier
      • executeAssign

        protected java.lang.Object executeAssign​(JexlNode node,
                                                 JexlOperator assignop,
                                                 java.lang.Object data)
        Executes an assignment with an optional side effect operator.
        Parameters:
        node - the node
        assignop - the assignment operator or null if simply assignment
        data - the data
        Returns:
        the left hand side
      • forIterator

        private java.lang.Object forIterator​(ASTForeachStatement node,
                                             java.lang.Object data)
      • forLoop

        private java.lang.Object forLoop​(ASTForeachStatement node,
                                         java.lang.Object data)
      • interpret

        public java.lang.Object interpret​(JexlNode node)
        Interpret the given script/expression.

        If the underlying JEXL engine is silent, errors will be logged through its logger as warning.

        Parameters:
        node - the script or expression to interpret.
        Returns:
        the result of the interpretation.
        Throws:
        JexlException - if any error occurs during interpretation.
      • isInstance

        private boolean isInstance​(java.lang.Object object,
                                   java.lang.Object clazz)
        Determines if the specified Object is assignment-compatible with the object represented by the Class.
        Parameters:
        object - the Object
        clazz - the Class
        Returns:
        the result of isInstance call
      • processAnnotation

        protected java.lang.Object processAnnotation​(ASTAnnotatedStatement stmt,
                                                     int index,
                                                     java.lang.Object data)
        Processes an annotated statement.
        Parameters:
        stmt - the statement
        index - the index of the current annotation being processed
        data - the contextual data
        Returns:
        the result of the statement block evaluation
      • processAnnotation

        protected java.lang.Object processAnnotation​(java.lang.String annotation,
                                                     java.lang.Object[] args,
                                                     java.util.concurrent.Callable<java.lang.Object> stmt)
                                              throws java.lang.Exception
        Delegates the annotation processing to the JexlContext if it is an AnnotationProcessor.
        Parameters:
        annotation - the annotation name
        args - the annotation arguments
        stmt - the statement / block that was annotated
        Returns:
        the result of statement.call()
        Throws:
        java.lang.Exception - if anything goes wrong
      • putThreadInterpreter

        protected Interpreter putThreadInterpreter​(Interpreter inter)
        Swaps the current thread local interpreter.
        Parameters:
        inter - the interpreter or null
        Returns:
        the previous thread local interpreter
      • resolveClassName

        private java.lang.String resolveClassName​(java.lang.String name)
        Resolves a class name.
        Parameters:
        name - the simple class name
        Returns:
        the fully qualified class name or the name
      • runClosure

        protected java.lang.Object runClosure​(Closure closure)
        Runs a closure.
        Parameters:
        closure - the closure
        Returns:
        the closure return value
      • testPredicate

        private boolean testPredicate​(JexlNode node,
                                      java.lang.Object condition)
      • visit

        protected java.lang.Object visit​(ASTBlock node,
                                         java.lang.Object data)
        Specified by:
        visit in class ParserVisitor
      • visit

        protected java.lang.Object visit​(ASTBreak node,
                                         java.lang.Object data)
        Specified by:
        visit in class ParserVisitor
      • visit

        private java.lang.Object visit​(ASTMethodNode node,
                                       java.lang.Object antish,
                                       java.lang.Object data)
        Execute a method call, ie syntactically written as name.call(...).
        Parameters:
        node - the actual method call node
        antish - non-null when name.call is an antish variable
        data - the context
        Returns:
        the method call result
      • visit

        protected java.lang.Object visit​(ASTVar node,
                                         java.lang.Object data)
        Specified by:
        visit in class ParserVisitor
      • visitBlock

        private java.lang.Object visitBlock​(ASTBlock node,
                                            java.lang.Object data)
        Base visitation for blocks.
        Parameters:
        node - the block
        data - the usual data
        Returns:
        the result of the last expression evaluation
      • visitLexicalNode

        protected java.lang.Object visitLexicalNode​(JexlNode node,
                                                    java.lang.Object data)
        Runs a node.
        Parameters:
        node - the node
        data - the usual data
        Returns:
        the return value