@Test public void testFindAllHandlers() throws Exception { AnnoSub listener = new AnnoSub(); Map<Class<? >, Set<EventHandler>> map = new AnnotatedHandlerFinder().findAllHandlers(listener); assertTrue(map.containsKey(SimpleEvent.class)); Collection<EventHandler> handlers = map.get(SimpleEvent.class); assertTrue(handlers.size() == 1); Iterator<EventHandler> iterator = handlers.iterator(); assertTrue(iterator.hasNext()); EventHandler handler = iterator.next(); try { assertTrue(handler.equals(new EventHandler(listener,listener.getClass().getMethod(ISubscribe.methodName,SimpleEvent.class)))); } catch (NoSuchMethodException e) { fail(); } }
@Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInAnno = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); while (clazz != null) { for (Method method : clazz.getMethods()) { Subscriber annotation = method.getAnnotation(Subscriber.class); if (annotation != null) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new IllegalArgumentException( "Method " + method + " has @Subscribe annotation, but requires " + parameterTypes.length + " arguments. Event handler methods " + "must require a single argument."); } Class<?> eventType = parameterTypes[0]; EventHandler handler = makeHandler(listener, method); put(methodsInAnno,eventType, handler); } } clazz = clazz.getSuperclass(); } return methodsInAnno; }
AnnotatedHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInAnno = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); while (clazz != null) { for (Method method : clazz.getMethods()) { Subscriber annotation = method.getAnnotation(Subscriber.class); if (annotation != null) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new IllegalArgumentException( "Method " + method + " has @Subscribe annotation, but requires " + parameterTypes.length + " arguments. Event handler methods " + "must require a single argument."); } Class<?> eventType = parameterTypes[0]; EventHandler handler = makeHandler(listener, method); put(methodsInAnno,eventType, handler); } } clazz = clazz.getSuperclass(); } return methodsInAnno; } }
AnnotatedHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInAnno = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); while (clazz != null) { for (Method method : clazz.getMethods()) { Subscriber annotation = method.getAnnotation(Subscriber.class); if (annotation != null) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new IllegalArgumentException( "Method " + method + " has @Subscribe annotation, but requires " + parameterTypes.length + " arguments. Event handler methods " + "must require a single argument."); } Class<?> eventType = parameterTypes[0]; EventHandler handler = makeHandler(listener, method); put(methodsInAnno,eventType, handler); } } clazz = clazz.getSuperclass(); } return methodsInAnno; }  }
AnnotatedHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInAnno = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); while (clazz != null) { for (Method method : clazz.getMethods()) { Subscriber annotation = method.getAnnotation(Subscriber.class); if (annotation != null) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new IllegalArgumentException( "Method " + method + " has @Subscribe annotation, but requires " + parameterTypes.length + " arguments. Event handler methods " + "must require a single argument."); } Class<?> eventType = parameterTypes[0]; EventHandler handler = makeHandler(listener, method); put(methodsInAnno,eventType, handler); } } clazz = clazz.getSuperclass(); } return methodsInAnno; }  @Override Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener); }
AnnotatedHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInAnno = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); while (clazz != null) { for (Method method : clazz.getMethods()) { Subscriber annotation = method.getAnnotation(Subscriber.class); if (annotation != null) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1) { throw new IllegalArgumentException( "Method " + method + " has @Subscribe annotation, but requires " + parameterTypes.length + " arguments. Event handler methods " + "must require a single argument."); } Class<?> eventType = parameterTypes[0]; EventHandler handler = makeHandler(listener, method); put(methodsInAnno,eventType, handler); } } clazz = clazz.getSuperclass(); } return methodsInAnno; }  @Override Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener);  }