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 name of target; false lets the next accessor try. target is never null.
override
canWrite(EvaluationContext context, Object target, String name) → bool
Whether this accessor handles writing property name of target; return false for 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 name of target; only called after canRead returned true.
override
toString() → String
A string representation of this object.
inherited
write(EvaluationContext context, Object target, String name, Object? newValue) → void
Stores newValue in property name of target; only called after canWrite returned true.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited