From 6d3ed4aab2bbcdaa53208f8c3645de0d3f5a5a52 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 7 Feb 2023 10:55:17 +0000 Subject: [PATCH] Add equals for provider implementations --- .../guice/module/SpringModule.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/guice/module/SpringModule.java b/src/main/java/org/springframework/guice/module/SpringModule.java index 9fa1021..37a02e3 100644 --- a/src/main/java/org/springframework/guice/module/SpringModule.java +++ b/src/main/java/org/springframework/guice/module/SpringModule.java @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Queue; import java.util.Set; @@ -178,7 +179,8 @@ public class SpringModule extends AbstractModule { bindConditionally(binder(), name, clazz, typeProvider, namedProvider, bindingAnnotation); } for (Type superType : getAllSuperTypes(type, clazz)) { - if (!superType.getTypeName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)) { + if (!superType.getTypeName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR) + && !superType.equals(Object.class)) { bindConditionally(binder(), name, superType, typeProvider, namedProvider, bindingAnnotation); } } @@ -451,6 +453,23 @@ public class SpringModule extends AbstractModule { return this.resultProvider.get(); } + @Override + public boolean equals(Object obj) { + if (obj instanceof BeanFactoryProvider) { + BeanFactoryProvider o = (BeanFactoryProvider) obj; + return ((this.name == null && o.name == null) || (this.name != null && this.name.equals(o.name))) + && this.type.equals(o.type); + } + else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.name, this.type); + } + } private static class CompositeTypeMatcher implements BindingTypeMatcher {