From 55c8de1bfd1df9572fbac5440ac430f771b2260c Mon Sep 17 00:00:00 2001 From: Adriano Santos Date: Wed, 11 Oct 2023 15:57:30 -0300 Subject: [PATCH] Some adjusts in reflection --- lib/src/reflect_helper.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/src/reflect_helper.dart b/lib/src/reflect_helper.dart index 667d2c8..fd51362 100644 --- a/lib/src/reflect_helper.dart +++ b/lib/src/reflect_helper.dart @@ -44,7 +44,7 @@ class ReflectHelper { } static Optional invoke( - Object instance, MethodMirror method, Any payload, Context context) { + Object instance, MethodMirror method, Any? payload, Context context) { if (payload == null) { var instanceMirrorResult = reflect(instance).invoke(method.simpleName, []); @@ -110,15 +110,17 @@ class ReflectHelper { static Map getMethodsByAnnotation( List allDeclaredMethods, Type annotation) { - // ignore: omit_local_variable_types final Map methods = {}; var annotationMirror = reflectClass(annotation); + allDeclaredMethods - .where((elem) => - elem.metadata.where((test) => test.type == annotationMirror) != - null) + .where((elem) => isMethodAnnotationBy(elem, annotationMirror)) .forEach( (e) => methods[capitalize(MirrorSystem.getName(e.simpleName))] = e); return methods; } + + static bool isMethodAnnotationBy( + MethodMirror method, ClassMirror annotationMirror) => + method.metadata.where((test) => test.type == annotationMirror).isNotEmpty; }