invoke method
Implementation
Object? invoke(InterpreterVisitor visitor, String method, List<Object?> args,
Map<String, Object?> namedArgs) {
final methodAdapter = _methods[method] ?? enumType.methods[method];
if (methodAdapter == null) {
// Special case: if calling .toString() and there is no specific adapter,
// return the standard representation.
if (method == 'toString' && args.isEmpty && namedArgs.isEmpty) {
return '${enumType.name}.$name';
}
throw RuntimeD4rtException(
'Method "$method" not found on enum value ${enumType.name}.$name');
}
try {
// Call the bridged method adapter
return methodAdapter(
visitor, // Pass the visitor
nativeValue, // The native enum object is the target
args, // Interpreted positional arguments
namedArgs, // Interpreted named arguments (if supported by the adapter)
null, // Type arguments (not needed for enum methods)
);
} catch (e) {
throw RuntimeD4rtException(
'Error executing bridged method "$method" on ${enumType.name}.$name: $e');
}
}