在EventHandler、EventProducer其实可以看作两个实体类,EventHandler用来保存每一个事件注册的类和注册方法,最后提供一个通过反射机制调用方法;EventProducer用来保存每一个事件生产者类和生产方法,最后提供一个通过反射机制调用方法。
AnnotatedHandlerFinder
这个类用来负责通过反射获取 通过 @Produce 注释的方法和通过 @Subscribe 注释的方法。
/**
* Load all methods annotated with {@link Produce} or {@link Subscribe} into their respective caches for the
* specified class.
* 从事件类中加载用@Producer或@Subscribe注释的方法,并放入到相应的集合中
*/
private static void loadAnnotatedMethods(Class<?> listenerClass,
Map<Class<?>, Method> producerMethods, Map<Class<?>, Set<Method>> subscriberMethods) {
// 遍历类中所有声明的方法
for (Method method : listenerClass.getDeclaredMethods()) {
// The compiler sometimes creates synthetic bridge methods as part of the
// type erasure process. As of JDK8 these methods now include the same
// annotations as