The world an expression is evaluated in: its root object, its variables, and the plug-ins that decide which properties, methods, types and beans it can reach.
The same expression gives different results in different contexts, and a context also decides what an expression is allowed to do. Pick one of the two implementations: StandardEvaluationContext for expressions you wrote yourself (everything is available), and SimpleEvaluationContext for expressions that come from outside, such as a user-supplied filter (no types, constructors, bean references or variable assignment). A context may be reused for many evaluations; variables set on it stay.
// `n` is read on the root object, `#factor` is a variable.
EvaluationContext context = StandardEvaluationContext({'n': 2})
..setVariable('factor', 10);
SpelExpressionParser().parseExpression('n * #factor').getValue(context);
// 20
Spring (Java):
EvaluationContext context = new StandardEvaluationContext(root);
context.setVariable("factor", 10);
parser.parseExpression("n * #factor").getValue(context);
Properties
- beanResolver → BeanResolver?
-
Looks up
@nameand&name, ornullwhen the context has no bean references (they then fail with EL1057E).no setter -
constructorResolvers
→ List<
ConstructorResolver> -
The resolvers asked, in order, for
new Name(...); empty when the context does not allow constructors.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
-
indexAccessors
→ List<
IndexAccessor> -
The accessors asked, in order, for
target[index]when the target is not a list, map or string.no setter - isAssignmentEnabled → bool
-
Whether expressions may assign (
=,++,--) andExpression.setValuemay write; whenfalseboth fail withnotAssignable(EL1068E).no setter -
methodResolvers
→ List<
MethodResolver> -
The resolvers asked, in order, for
obj.method(...).no setter - operatorOverloader → OperatorOverloader
-
Gives arithmetic operators a meaning for operands with no built-in
rule.
no setter
-
propertyAccessors
→ List<
PropertyAccessor> -
The accessors asked, in order, for
obj.property.no setter - rootObject → Object?
-
The object unprefixed names are read on (
namemeans#root.name) whengetValueis called without a root object.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- typeComparator → TypeComparator
-
Orders values for
<,<=,>,>=andbetween.no setter - typeConverter → TypeConverter
-
Converts values: for
getValueAs, conditions, templates, indexes and method arguments.no setter - typeLocator → TypeLocator
-
Finds the types of
T(Name),new Name(...)andinstanceof.no setter
Methods
-
assignVariable(
String name, Object? valueSupplier()) → Object? -
Stores the value from
valueSupplierin#nameand returns it; the evaluator calls this for#name = ...and#name++inside an expression. -
lookupVariable(
String name) → Object? -
The value of variable
#name, ornullwhen unset. Registered functions are variables too. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setVariable(
String name, Object? value) → void -
Sets the variable
#nametovaluefrom Dart code, before the expression is evaluated. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited