SpelExpression class final
One parsed SpEL expression: the syntax tree of the text and the parser options it runs under.
SpelExpressionParser returns one for a plain expression (and for
each #{...} part of a template). Use it through Expression; the
concrete type only matters to tools that inspect the parsed tree in
ast. Every evaluation counts operations against the limits of
configuration, and an expression nested too deeply for the stack
fails with maxExpressionNestingDepthExceeded instead of a stack
overflow.
// A tool printing how an expression was understood.
final expression = SpelExpressionParser().parseExpression('a + b');
expression is SpelExpression; // true
expression.getValue(StandardEvaluationContext({'a': 1, 'b': 2})); // 3
Spring (Java):
SpelExpression expression =
(SpelExpression) parser.parseExpression("a + b");
SpelNode ast = expression.getAST();
- Implemented types
Constructors
- SpelExpression(String expressionString, SpelNode ast, [SpelParserConfiguration? configuration])
-
Wraps the parsed
astofexpressionString, evaluated underconfiguration(the defaults when omitted). The parser calls it; applications do not.
Properties
- ast → SpelNode
-
The root node of the parsed tree; its
toString()prints the expression as the parser read it, with parentheses ((a + b)).final - configuration → SpelParserConfiguration
-
The operation limit and auto-grow options every evaluation uses,
taken from the parser.
final
- expressionString → String
-
The text the expression was parsed from (the whole template for a
template).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getValue(
[EvaluationContext? context, Object? rootObject]) → Object? -
Evaluates the expression and returns its value.
override
-
getValueAs<
T> ([EvaluationContext? context, Object? rootObject]) → T -
Evaluates like getValue and returns the value as a
T.override -
getValueType(
[EvaluationContext? context, Object? rootObject]) → Type? -
The runtime type of the value, or
nullwhen the value isnull(Stringfor a template).override -
isWritable(
[EvaluationContext? context, Object? rootObject]) → bool -
Whether setValue would store a value: the expression names a
writable property, variable or element and the context allows
assignment.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setValue(
EvaluationContext? context, Object? rootObject, Object? value) → void -
Stores
valuein the property, variable or element the expression names, such asuser.name,#countoritems[0].override -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited