From e520b3de7e0196c616972cb3684e3e0385d7d872 Mon Sep 17 00:00:00 2001 From: Elvis de Freitas Date: Tue, 6 Aug 2024 22:06:51 -0300 Subject: [PATCH] finally fixing bug which gets the wrong list --- src/test/java/dagger/sheath/CtxWrapper.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/dagger/sheath/CtxWrapper.java b/src/test/java/dagger/sheath/CtxWrapper.java index 2a871b825..c8f67a6f1 100644 --- a/src/test/java/dagger/sheath/CtxWrapper.java +++ b/src/test/java/dagger/sheath/CtxWrapper.java @@ -8,6 +8,7 @@ import javax.inject.Provider; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.Objects; import java.util.function.Consumer; @@ -43,7 +44,7 @@ public Object get(Signature signature) { { final var found = findUsingCtx(signature); - if(found != null){ + if (found != null) { log.debug("status=foundByUsingCtx"); return found; } @@ -64,7 +65,7 @@ private Object findUsingCtx(Signature signature) { final var method = MethodUtils .getAllMethods(this.getCtxClass()) .stream() - .filter(it -> it.getReturnType().isAssignableFrom(signature.getClazz()) && it.getParameterTypes().length == 0) + .filter(it -> isAssignable(it, signature)) .findFirst(); if (method.isPresent()) { return MethodUtils.invoke(method.get(), this.ctx, true); @@ -75,6 +76,11 @@ private Object findUsingCtx(Signature signature) { return null; } + private static boolean isAssignable(Method m, Signature sig) { + final var mSig = Signature.of(m.getReturnType()); + return mSig.isSameOrInheritFrom(sig) && m.getParameterTypes().length == 0; + } + private Object findUsingBindingMethods(Class clazz) { try { final var bindingMethod = BindingMethod.findBindingMethod(this);