MethodResolver class abstract interface

A plug-in that tells expressions which code to run for a method call such as greeter.greet('Ada').

Without reflection an expression can only call methods some resolver knows. The contexts bring resolvers for @Introspected classes (IntrospectionMethodResolver) and core Dart types (BuiltinMethodResolver); for other classes a FunctionMethodResolver is usually enough. Implement this interface when the methods are only known at run time. For each call the context asks its resolvers in order and runs the first MethodExecutor returned; when none matches, the call fails with methodNotFound (EL1004E).

// Lets rules call greet(...) on a Greeter from another package.
final class GreeterResolver implements MethodResolver {
  @override
  MethodExecutor? resolve(EvaluationContext context, Object target,
          String name, List<Object?> arguments) =>
      target is Greeter && name == 'greet'
          ? (_, t, args) => (t as Greeter).greet(args.first! as String)
          : null;
}

final context = StandardEvaluationContext(Greeter())
  ..addMethodResolver(GreeterResolver());
SpelExpressionParser()
    .parseExpression("greet('Ada')")
    .getValue(context);

Spring (Java):

// Spring's ReflectiveMethodResolver finds greet(String) by reflection.
context.addMethodResolver(new MyMethodResolver());
parser.parseExpression("greet('Ada')").getValue(context);

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 name on target with arguments (already evaluated), or null to let the next resolver try.
toString() → String
A string representation of this object.
inherited

Operators

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