private void findUsingReflectionInSingleClass(FindState findState){
Method[] methods;try{// This is faster than getMethods, especially when subscribers are fat classes like Activities
methods = findState.clazz.getDeclaredMethods();}catch(Throwable th){// Workaround for java.lang.NoClassDefFoundError, see https://github.com/greenrobot/EventBus/issues/149try{
methods = findState.clazz.getMethods();}catch(LinkageError error){// super class of NoClassDefFoundError to be a bit more broad...
String msg ="Could not inspect methods of "+ findState.clazz.getName();if(ignoreGeneratedIndex){
msg +=". Please consider using EventBus annotation processor to avoid reflection.";}else{
msg +=". Please make this class visible to EventBus annotation processor to avoid reflection.";}throw new EventBusException(msg, error);}
findState.skipSuperClasses =true;}for(Method method : methods){
int modifiers = method.getModifiers();if((modifiers & Modifier.PUBLIC)!=0&&(modifiers & MODIFIERS_IGNORE)==0){
Class<?>[] parameterTypes = method.getParameterTypes();if(parameterTypes.length ==1){
Subscribe subscribeAnnotation = method.getAnnotation(Subscribe.class);if(subscribeAnnotation !=null){
Class<?> eventType = parameterTypes[0];if(findState.checkAdd(method, eventType)){
ThreadMode threadMode = subscribeAnnotation.threadMode();
findState.subscriberMethods.add(new SubscriberMethod(method, eventType, threadMode,
subscribeAnnotation.priority(), subscribeAnnotation.sticky()));}}}elseif(strictMethodVerification && method.isAnnotationPresent(Subscribe.class)){
String methodName = method.getDeclaringClass().getName()+"."+ method.getName();throw new EventBusException("@Subscribe method "+ methodName +"must have exactly 1 parameter but has "+ parameterTypes.length);}}elseif(strictMethodVerification && method.isAnnotationPresent(Subscribe.class)){
String methodName = method.getDeclaringClass().getName()+"."+ method.getName();throw new EventBusException(methodName +" is a illegal @Subscribe method: must be public, non-static, and non-abstract");}}}
/** Posts the given event to the event bus. */public void post(Object event){
PostingThreadState postingState = currentPostingThreadState.get();
List<Object> eventQueue = postingState.eventQueue;
eventQueue.add(event);if(!postingState.isPosting){
postingState.isMainThread =isMainThread();
postingState.isPosting =true;if(postingState.canceled){throw new EventBusException("Internal error. Abort state was not reset");}try{while(!eventQueue.isEmpty()){postSingleEvent(eventQueue.remove(0), postingState);}}finally{
postingState.isPosting =false;
postingState.isMainThread =false;}}}