BuiltinPropertyAccessor class final
A PropertyAccessor for the common read-only properties of core Dart types, which expressions cannot reach otherwise without reflection.
It covers length/size, isEmpty, isNotEmpty, first and last
of strings and iterables; keys, values and entries of maps (as
lists) and key/value of entries; isNegative, isNaN, sign, ...
of numbers; the parts of a DateTime (year, month, weekday, ...)
and of a Duration (inSeconds, ...); name and index of enums.
Java-style names work too (size, empty, keySet, entrySet).
Both contexts register it by default.
final parser = SpelExpressionParser();
parser.parseExpression("'abc'.length").getValue(); // 3
parser.parseExpression('{1, 2}.size').getValue(); // 2
parser.parseExpression('#d.year').getValue(
StandardEvaluationContext()..setVariable('d', DateTime(2026)),
); // 2026
Spring (Java):
// Spring reads JavaBean getters reflectively:
parser.parseExpression("'abc'.bytes.length").getValue();
parser.parseExpression("{1, 2}.size()").getValue();
- Implemented types
Constructors
- BuiltinPropertyAccessor()
-
Creates the accessor (stateless).
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canRead(
EvaluationContext context, Object target, String name) → bool -
Whether this accessor handles reading property
nameoftarget;falselets the next accessor try.targetis nevernull.override -
canWrite(
EvaluationContext context, Object target, String name) → bool -
Whether this accessor handles writing property
nameoftarget; returnfalsefor read-only properties.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
EvaluationContext context, Object target, String name) → Object? -
The value of property
nameoftarget; only called after canRead returnedtrue.override -
toString(
) → String -
A string representation of this object.
inherited
-
write(
EvaluationContext context, Object target, String name, Object? newValue) → void -
Stores
newValuein propertynameoftarget; only called after canWrite returnedtrue.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited