BuiltinMethodResolver class final
A MethodResolver for the common methods of core Dart types, under
their Dart names and the Java names Spring expressions use
(size(), toUpperCase(), charAt(), equals(), getOrDefault(),
putIfAbsent()).
Without reflection expressions could not call 'abc'.toUpperCase();
this table makes the usual methods of String, List, Set,
Iterable, Map, int, num, DateTime, Duration and
StringBuffer (Java's StringBuilder) available, plus toString(),
hashCode(), equals() and compareTo() on any object. A
StandardEvaluationContext registers it by default; a
SimpleEvaluationContext only after withInstanceMethods().
Where Dart and Java share a name, the method behaves like Dart's:
split, replaceAll and contains take plain strings (not regular
expressions), List.remove(x) removes an element (not the one at an
index); matches uses Dart's RegExp. String also has Java's
formatted, getBytes (UTF-8) and chars.
Number, string and bool arguments are converted to the parameter type
when needed ('abc'.substring('1')). Arguments that still do not fit
are reported as SpelMessage.methodNotFound; errors raised by the
method itself (RangeError for 'abc'.charAt(9)) propagate
unchanged, like Java exceptions from Spring's reflective calls.
final parser = SpelExpressionParser();
parser.parseExpression("'abc'.toUpperCase()").getValue(); // 'ABC'
parser.parseExpression("'a,b'.split(',').size()").getValue(); // 2
parser.parseExpression("{a: 1}.getOrDefault('b', 0)").getValue(); // 0
Spring (Java):
// Spring calls the JDK methods reflectively:
parser.parseExpression("'abc'.toUpperCase()").getValue();
parser.parseExpression("'a,b'.split(',').length").getValue();
- Implemented types
Constructors
- BuiltinMethodResolver()
-
Creates the resolver (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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolve(
EvaluationContext context, Object target, String name, List< Object?> arguments) → MethodExecutor? -
An executor that runs method
nameontargetwitharguments(already evaluated), ornullto let the next resolver try.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited