EventHandlerMeta { public static @Nullable EventHandlerMeta<?> forMethod(Method method) { if(method.isBridge() || method.isSynthetic()) return null; final EventHandler annotation = method.getAnnotation(EventHandler.class); if(annotation == null) return null; final Class<?> eventClass; if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(eventClass = method.getParameterTypes()[0])) { throw new IllegalArgumentException("Invalid @EventHandler method " + method.toGenericString() + " in " + method.getDeclaringClass().getName()); } Event.getHandlerList((Class<? extends Event>) eventClass); return forAnnotation(eventClass.asSubclass(Event.class), annotation); } EventHandlerMeta(Class<T> event, EventPriority priority, boolean ignoreCancelled); Class<T> event(); EventPriority priority(); boolean ignoreCancelled(); boolean canHandle(Event event, @Nullable EventPriority priority); boolean canCall(Method method); void assertCanCall(Method method); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static EventHandlerMeta<T> forAnnotation(Class<T> event, EventHandler annotation); static @Nullable EventHandlerMeta<?> forMethod(Method method);  }
@Test public void ignoreMethodWithoutAnnotation() throws Exception { class C { void handler(TestEvent event) {} } assertNull(EventHandlerMeta.forMethod(C.class.getDeclaredMethod("handler", TestEvent.class))); }
@Test public void missingEventParameter() throws Throwable { class C { @EventHandler void handler() {} } assertThrows(IllegalArgumentException.class, () -> EventHandlerMeta.forMethod(C.class.getDeclaredMethod("handler")) ); }
@Test public void extraParameter() throws Throwable { class C { @EventHandler void handler(TestEvent event, int what) {} } assertThrows(IllegalArgumentException.class, () -> EventHandlerMeta.forMethod(C.class.getDeclaredMethod("handler", TestEvent.class, int.class)) ); }
@Test public void abstractEvent() throws Throwable { class C { @EventHandler void handler(Event event) {} } assertThrows(IllegalArgumentException.class, () -> EventHandlerMeta.forMethod(C.class.getDeclaredMethod("handler", Event.class)) ); }