EvaluationContext class abstract interface

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 @name and &name, or null when 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 (=, ++, --) and Expression.setValue may write; when false both fail with notAssignable (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 (name means #root.name) when getValue is 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 <, <=, >, >= and between.
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(...) and instanceof.
no setter

Methods

assignVariable(String name, Object? valueSupplier()) → Object?
Stores the value from valueSupplier in #name and returns it; the evaluator calls this for #name = ... and #name++ inside an expression.
lookupVariable(String name) → Object?
The value of variable #name, or null when 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 #name to value from 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