ExpressionState class final

The working state of one evaluation: which object names currently apply to, what #this is, and how many operations have run.

SpelExpression creates one for each getValue / setValue call and passes it down the tree. It tracks the active context object (what a bare name or method() applies to, and what #this is), the scope root (the active object at the start of the current compound expression, against which method arguments are evaluated) and the number of operations performed so far (see SpelParserConfiguration.maximumOperations). Applications never use it; you only meet it when writing your own SpelNodes.

// Evaluating a node by hand, as a custom node would.
final state = ExpressionState(
  StandardEvaluationContext(),
  {'n': 2},
  'n + 1',
);
state.activeContextObject; // {'n': 2}
state.withThis(5, node); // evaluates node with #this == 5

Spring (Java):

ExpressionState state = new ExpressionState(context, new TypedValue(root));
state.pushActiveContextObject(new TypedValue(element));
try {
  value = node.getValue(state);
} finally {
  state.popActiveContextObject();
}

Constructors

ExpressionState(EvaluationContext context, Object? root, String expressionString, [SpelParserConfiguration? configuration])
Starts an evaluation of expressionString in context with root as #root, #this and the initial active object, under the limits of configuration (the defaults when omitted).

Properties

activeContextObject → Object?
The object property and method references apply to.
no setter
activeContextObjectIsReal → bool
Whether activeContextObject is a real number (a Java double), also when it is integral and so an int at run time on the web.
no setter
configuration → SpelParserConfiguration
The parser configuration (limits, auto-grow).
final
context → EvaluationContext
The evaluation context (accessors, variables, types, ...).
final
expressionString → String
The expression text, used in error messages.
final
hashCode → int
The hash code for this object.
no setterinherited
root → Object?
The root object (#root) of this evaluation.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scopeRoot → Object?
#this at the start of the current compound expression; method arguments are evaluated against it.
no setter
scopeRootIsReal → bool
Whether scopeRoot is a real number (see activeContextObjectIsReal).
no setter

Methods

asBool(Object? value, int position) → bool
value as a bool, converting with the context's type converter (e.g. 'true'); null and non-convertible values throw SpelMessage.typeConversionError, like Spring.
assignVariable(String name, Object? valueSupplier()) → Object?
Assigns #name through EvaluationContext.assignVariable (counted as an operation).
error(SpelMessage code, int position, [List<Object?> inserts = const [], Object? cause]) → SpelEvaluationException
A SpelEvaluationException for this expression at position.
locate(SpelEvaluationException exception, int position) → SpelEvaluationException
exception with this expression and position filled in when it has none (errors from type locators, converters, comparators...).
located<T>(int position, T body()) → T
Runs body, adding this expression and position to a SpelEvaluationException that has none.
lookupVariable(String name) → Object?
The value of variable #name (counted as an operation).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
operate(Operation operation, Object? left, Object? right, int position) → Object?
operation on left and right by the context's OperatorOverloader; throws SpelMessage.operatorNotSupportedBetweenTypes when it does not handle them.
popActive() → void
Restores the previous active context object.
popScope() → void
Ends the scope started by pushScope.
pushActive(Object? value, {bool real = false}) → void
Makes value the active context object until popActive; real when it is a real number (a Java double) even if integral.
pushScope(Object? value, {bool real = false}) → void
Starts a new scope with value as scope root and active object (real as in pushActive); end it with popScope.
toString() → String
A string representation of this object.
inherited
trackOperation() → void
Counts one operation (Spring's trackOperation); throws SpelMessage.maxOperationsExceeded when the configured maximum is exceeded.
withThis(Object? value, SpelNode node, {bool real = false}) → Object?
Evaluates node with value as #this (real as in pushActive).

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

typeName(Object? value) → String
The type name of value for messages (null for null).