/** * Gets the given class's {@link Method}s marked with the annotation of the * specified class. * <p> * Unlike {@link Class#getMethods()}, the result will include any non-public * methods, including methods defined in supertypes of the given class. * </p> * * @param c The class to scan for annotated methods. * @param annotationClass The type of annotation for which to scan. * @return A list containing all methods with the requested annotation. Note * that for performance reasons, lists may be cached and reused, so it * is best to make a copy of the result if you need to modify it. */ public static <A extends Annotation> List<Method> getAnnotatedMethods( final Class<?> c, final Class<A> annotationClass) { List<Method> methods = methodCache.getList(c, annotationClass); if (methods == null) { methods = new ArrayList<>(); getAnnotatedMethods(c, annotationClass, methods); } return methods; }
/** * Gets the given class's {@link Method}s marked with the annotation of the * specified class. * <p> * Unlike {@link Class#getMethods()}, the result will include any non-public * methods, including methods defined in supertypes of the given class. * </p> * * @param c The class to scan for annotated methods. * @param annotationClass The type of annotation for which to scan. * @return A list containing all methods with the requested annotation. Note * that for performance reasons, lists may be cached and reused, so it * is best to make a copy of the result if you need to modify it. */ public static <A extends Annotation> List<Method> getAnnotatedMethods( final Class<?> c, final Class<A> annotationClass) { List<Method> methods = methodCache.getList(c, annotationClass); if (methods == null) { methods = new ArrayList<>(); getAnnotatedMethods(c, annotationClass, methods); } return methods; }
@Override public List<EventSubscriber<?>> subscribe(final Object o) { final List<Method> eventHandlers = ClassUtils.getAnnotatedMethods(o.getClass(), EventHandler.class); if (eventHandlers.isEmpty()) return Collections.emptyList(); final ArrayList<EventSubscriber<?>> subscribers = new ArrayList<>(); for (final Method m : eventHandlers) { // verify that the event handler method is valid final Class<? extends SciJavaEvent> eventClass = getEventClass(m); if (eventClass == null) { log.warn("Invalid EventHandler method: " + m); continue; } // verify that the event handler key isn't already claimed final String key = m.getAnnotation(EventHandler.class).key(); if (!key.isEmpty()) { synchronized (keys) { if (keys.contains(key)) continue; keys.add(key); } } // subscribe the event handler subscribers.add(subscribe(eventClass, o, m)); } return subscribers; }
@Override public List<EventSubscriber<?>> subscribe(final Object o) { final List<Method> eventHandlers = ClassUtils.getAnnotatedMethods(o.getClass(), EventHandler.class); if (eventHandlers.isEmpty()) return Collections.emptyList(); final ArrayList<EventSubscriber<?>> subscribers = new ArrayList<>(); for (final Method m : eventHandlers) { // verify that the event handler method is valid final Class<? extends SciJavaEvent> eventClass = getEventClass(m); if (eventClass == null) { log.warn("Invalid EventHandler method: " + m); continue; } // verify that the event handler key isn't already claimed final String key = m.getAnnotation(EventHandler.class).key(); if (!key.isEmpty()) { synchronized (keys) { if (keys.contains(key)) continue; keys.add(key); } } // subscribe the event handler subscribers.add(subscribe(eventClass, o, m)); } return subscribers; }
if (!ClassUtils.getAnnotatedMethods(c, EventHandler.class).isEmpty()) {
if (!ClassUtils.getAnnotatedMethods(c, EventHandler.class).isEmpty()) {
ClassUtils.getAnnotatedMethods(namespaceClass, OpMethod.class);