Test priorities for inheritance
All checks were successful
zdm/event-bus/pipeline/head This commit looks good

This commit is contained in:
2022-01-12 15:59:45 +01:00
parent 7fb633d69f
commit 722bf2b999
5 changed files with 25 additions and 11 deletions

View File

@ -7,7 +7,6 @@ import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import dev.kske.eventbus.core.handler.*;
@ -272,8 +271,9 @@ public final class EventBus {
Set<Method> methods = getMethodsAnnotatedWith(listenerClass, Event.class);
// Recursively add superclass handlers
if (listenerClass.getSuperclass() != null)
methods.addAll(getHandlerMethods(listenerClass.getSuperclass()));
Class<?> superClass = listenerClass.getSuperclass();
if (superClass != null && superClass != Object.class)
methods.addAll(getHandlerMethods(superClass));
// Recursively add interface handlers
for (Class<?> iClass : listenerClass.getInterfaces())
@ -292,9 +292,12 @@ public final class EventBus {
*/
private Set<Method> getMethodsAnnotatedWith(Class<?> enclosingClass,
Class<? extends Annotation> annotationClass) {
return Arrays.stream(enclosingClass.getDeclaredMethods())
.filter(m -> m.isAnnotationPresent(annotationClass))
.collect(Collectors.toSet());
var methods = new HashSet<Method>();
for (var method : enclosingClass.getDeclaredMethods())
if (method.isAnnotationPresent(annotationClass))
methods.add(method);
return methods;
}
/**