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
expressionStringincontextwithrootas#root,#thisand the initial active object, under the limits ofconfiguration(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 anintat 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?
-
#thisat 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 -
valueas abool, converting with the context's type converter (e.g.'true');nulland non-convertible values throw SpelMessage.typeConversionError, like Spring. -
assignVariable(
String name, Object? valueSupplier()) → Object? -
Assigns
#namethroughEvaluationContext.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 -
exceptionwith this expression andpositionfilled in when it has none (errors from type locators, converters, comparators...). -
located<
T> (int position, T body()) → T -
Runs
body, adding this expression andpositionto 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? -
operationonleftandrightby 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
valuethe active context object until popActive;realwhen it is a real number (a Javadouble) even if integral. -
pushScope(
Object? value, {bool real = false}) → void -
Starts a new scope with
valueas scope root and active object (realas 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
nodewithvalueas#this(realas in pushActive).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited