Skip to content

Commit

Permalink
Some adjusts in reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Santos committed Oct 11, 2023
1 parent fc0a972 commit 55c8de1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/src/reflect_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ReflectHelper {
}

static Optional<Any> 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, []);
Expand Down Expand Up @@ -110,15 +110,17 @@ class ReflectHelper {

static Map<String, MethodMirror> getMethodsByAnnotation(
List<MethodMirror> allDeclaredMethods, Type annotation) {
// ignore: omit_local_variable_types
final Map<String, MethodMirror> 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;
}

0 comments on commit 55c8de1

Please sign in to comment.