Skip to content

Commit

Permalink
finally fixing bug which gets the wrong list
Browse files Browse the repository at this point in the history
  • Loading branch information
mageddo committed Aug 7, 2024
1 parent 69565b5 commit e520b3d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/test/java/dagger/sheath/CtxWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e520b3d

Please sign in to comment.