Interface SpelNode

All Known Implementing Classes:
Assign, BeanReference, BooleanLiteral, CompoundExpression, ConstructorReference, Elvis, FloatLiteral, FunctionReference, Identifier, Indexer, InlineList, InlineMap, IntLiteral, Literal, LongLiteral, MethodReference, NullLiteral, OpAnd, OpDec, OpDivide, OpEQ, Operator, OperatorBetween, OperatorInstanceof, OperatorMatches, OperatorNot, OperatorPower, OpGE, OpGT, OpInc, OpLE, OpLT, OpMinus, OpModulus, OpMultiply, OpNE, OpOr, OpPlus, Projection, PropertyOrFieldReference, QualifiedIdentifier, RealLiteral, Selection, SpelNodeImpl, StringLiteral, Ternary, TypeReference, VariableReference

public interface SpelNode
Represents a node in the abstract syntax tree (AST) for a parsed Spring Expression Language (SpEL) expression.
Since:
3.0
Author:
Andy Clement, Sam Brannen
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    generateCode(MethodVisitor methodVisitor, CodeFlow codeFlow)
    Generate the bytecode for this node into the supplied MethodVisitor.
    getChild(int index)
    Return the nth child under this node.
    int
    Return the number of children under this node.
    int
    Return the end position of this AST node in the expression string.
    Determine the class of the object passed in, unless it is already a class object.
    int
    Return the start position of this AST node in the expression string.
    getTypedValue(ExpressionState expressionState)
    Evaluate the expression node in the context of the supplied expression state and return the typed value.
    getValue(ExpressionState expressionState)
    Evaluate the expression node in the context of the supplied expression state and return the value.
    default boolean
    Determine if this node can be compiled to bytecode.
    boolean
    isWritable(ExpressionState expressionState)
    Determine if this expression node will support a setValue() call.
    void
    setValue(ExpressionState expressionState, Object newValue)
    Evaluate the expression to a node and then set the new value on that node.
    Return the string form of this AST node.
  • Method Details

    • getValue

      @Nullable Object getValue(ExpressionState expressionState) throws EvaluationException
      Evaluate the expression node in the context of the supplied expression state and return the value.
      Parameters:
      expressionState - the current expression state (includes the context)
      Returns:
      the value of this node evaluated against the specified state
      Throws:
      EvaluationException - if any problem occurs evaluating the expression
    • getTypedValue

      TypedValue getTypedValue(ExpressionState expressionState) throws EvaluationException
      Evaluate the expression node in the context of the supplied expression state and return the typed value.
      Parameters:
      expressionState - the current expression state (includes the context)
      Returns:
      the typed value of this node evaluated against the specified state
      Throws:
      EvaluationException - if any problem occurs evaluating the expression
    • isWritable

      boolean isWritable(ExpressionState expressionState) throws EvaluationException
      Determine if this expression node will support a setValue() call.
      Parameters:
      expressionState - the current expression state (includes the context)
      Returns:
      true if the expression node will allow setValue()
      Throws:
      EvaluationException - if something went wrong trying to determine if the node supports writing
    • setValue

      void setValue(ExpressionState expressionState, @Nullable Object newValue) throws EvaluationException
      Evaluate the expression to a node and then set the new value on that node. For example, if the expression evaluates to a property reference, then the property will be set to the new value.
      Parameters:
      expressionState - the current expression state (includes the context)
      newValue - the new value
      Throws:
      EvaluationException - if any problem occurs evaluating the expression or setting the new value
    • toStringAST

      String toStringAST()
      Return the string form of this AST node.
      Returns:
      the string form
    • getChildCount

      int getChildCount()
      Return the number of children under this node.
      Returns:
      the child count
      See Also:
    • getChild

      SpelNode getChild(int index)
      Return the nth child under this node.
      Returns:
      the child node
      See Also:
    • getObjectClass

      @Nullable Class<?> getObjectClass(@Nullable Object obj)
      Determine the class of the object passed in, unless it is already a class object.
      Parameters:
      obj - the object that the caller wants the class of
      Returns:
      the class of the object if it is not already a class object, or null if the object is null
    • getStartPosition

      int getStartPosition()
      Return the start position of this AST node in the expression string.
      Returns:
      the start position
    • getEndPosition

      int getEndPosition()
      Return the end position of this AST node in the expression string.
      Returns:
      the end position
    • isCompilable

      default boolean isCompilable()
      Determine if this node can be compiled to bytecode.

      The reasoning in each node may be different but will typically involve checking whether the exit type descriptor of the node is known and any relevant child nodes are compilable.

      The default implementation returns false.

      If you override this method, you must also override generateCode(MethodVisitor, CodeFlow).

      Returns:
      true if this node can be compiled to bytecode
      Since:
      6.2
      See Also:
    • generateCode

      default void generateCode(MethodVisitor methodVisitor, CodeFlow codeFlow)
      Generate the bytecode for this node into the supplied MethodVisitor.

      Context information about the current expression being compiled is available in the supplied CodeFlow object — for example, information about the type of the object currently on the stack.

      This method will not be invoked unless isCompilable() returns true.

      The default implementation throws an IllegalStateException since isCompilable() returns false by default.

      If you override this method, you must also override isCompilable().

      Parameters:
      methodVisitor - the ASM MethodVisitor into which code should be generated
      codeFlow - a context object with information about what is on the stack
      Since:
      6.2
      See Also: