/** * Recursively finds events defined by the given type and its implemented interfaces. * * @param type the type for which to find events * @return the events defined by the given type and its parent interfaces */ private static Map<Method, EventType> findMethods(Class<?> type) { Map<Method, EventType> events = new HashMap<>(); for (Method method : type.getDeclaredMethods()) { Event event = method.getAnnotation(Event.class); if (event != null) { String name = event.value().equals("") ? method.getName() : event.value(); events.put(method, EventType.from(name)); } } for (Class<?> iface : type.getInterfaces()) { events.putAll(findMethods(iface)); } return events; }
/** * Recursively finds events defined by the given type and its implemented interfaces. * * @param type the type for which to find events * @return the events defined by the given type and its parent interfaces */ private static Map<EventType, Method> findEvents(Class<?> type) { Map<EventType, Method> events = new HashMap<>(); for (Method method : type.getDeclaredMethods()) { Event event = method.getAnnotation(Event.class); if (event != null) { String name = event.value().equals("") ? method.getName() : event.value(); events.put(EventType.from(name), method); } } for (Class<?> iface : type.getInterfaces()) { events.putAll(findEvents(iface)); } return events; }