226 lines
7.2 KiB
Java
226 lines
7.2 KiB
Java
package org.greenrobot.eventbus;
|
|
|
|
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
|
import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import org.greenrobot.eventbus.meta.SubscriberInfo;
|
|
import org.greenrobot.eventbus.meta.SubscriberInfoIndex;
|
|
|
|
/* loaded from: classes2.dex */
|
|
class SubscriberMethodFinder {
|
|
private static final Map<Class<?>, List<SubscriberMethod>> d = new ConcurrentHashMap();
|
|
private static final FindState[] e = new FindState[4];
|
|
private List<SubscriberInfoIndex> a;
|
|
private final boolean b;
|
|
private final boolean c;
|
|
|
|
SubscriberMethodFinder(List<SubscriberInfoIndex> list, boolean z, boolean z2) {
|
|
this.a = list;
|
|
this.b = z;
|
|
this.c = z2;
|
|
}
|
|
|
|
private List<SubscriberMethod> b(Class<?> cls) {
|
|
FindState a = a();
|
|
a.a(cls);
|
|
while (a.e != null) {
|
|
a.g = c(a);
|
|
SubscriberInfo subscriberInfo = a.g;
|
|
if (subscriberInfo != null) {
|
|
for (SubscriberMethod subscriberMethod : subscriberInfo.a()) {
|
|
if (a.a(subscriberMethod.a, subscriberMethod.c)) {
|
|
a.a.add(subscriberMethod);
|
|
}
|
|
}
|
|
} else {
|
|
a(a);
|
|
}
|
|
a.a();
|
|
}
|
|
return b(a);
|
|
}
|
|
|
|
private SubscriberInfo c(FindState findState) {
|
|
SubscriberInfo subscriberInfo = findState.g;
|
|
if (subscriberInfo != null && subscriberInfo.b() != null) {
|
|
SubscriberInfo b = findState.g.b();
|
|
if (findState.e == b.c()) {
|
|
return b;
|
|
}
|
|
}
|
|
List<SubscriberInfoIndex> list = this.a;
|
|
if (list == null) {
|
|
return null;
|
|
}
|
|
Iterator<SubscriberInfoIndex> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
SubscriberInfo a = it.next().a(findState.e);
|
|
if (a != null) {
|
|
return a;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
List<SubscriberMethod> a(Class<?> cls) {
|
|
List<SubscriberMethod> list = d.get(cls);
|
|
if (list != null) {
|
|
return list;
|
|
}
|
|
List<SubscriberMethod> c = this.c ? c(cls) : b(cls);
|
|
if (!c.isEmpty()) {
|
|
d.put(cls, c);
|
|
return c;
|
|
}
|
|
throw new EventBusException("Subscriber " + cls + " and its super classes have no public methods with the @Subscribe annotation");
|
|
}
|
|
|
|
static class FindState {
|
|
final List<SubscriberMethod> a = new ArrayList();
|
|
final Map<Class, Object> b = new HashMap();
|
|
final Map<String, Class> c = new HashMap();
|
|
final StringBuilder d = new StringBuilder(PeripheralType.SERVO);
|
|
Class<?> e;
|
|
boolean f;
|
|
SubscriberInfo g;
|
|
|
|
FindState() {
|
|
}
|
|
|
|
void a(Class<?> cls) {
|
|
this.e = cls;
|
|
this.f = false;
|
|
this.g = null;
|
|
}
|
|
|
|
void b() {
|
|
this.a.clear();
|
|
this.b.clear();
|
|
this.c.clear();
|
|
this.d.setLength(0);
|
|
this.e = null;
|
|
this.f = false;
|
|
this.g = null;
|
|
}
|
|
|
|
boolean a(Method method, Class<?> cls) {
|
|
Object put = this.b.put(cls, method);
|
|
if (put == null) {
|
|
return true;
|
|
}
|
|
if (put instanceof Method) {
|
|
if (b((Method) put, cls)) {
|
|
this.b.put(cls, this);
|
|
} else {
|
|
throw new IllegalStateException();
|
|
}
|
|
}
|
|
return b(method, cls);
|
|
}
|
|
|
|
private boolean b(Method method, Class<?> cls) {
|
|
this.d.setLength(0);
|
|
this.d.append(method.getName());
|
|
StringBuilder sb = this.d;
|
|
sb.append('>');
|
|
sb.append(cls.getName());
|
|
String sb2 = this.d.toString();
|
|
Class<?> declaringClass = method.getDeclaringClass();
|
|
Class put = this.c.put(sb2, declaringClass);
|
|
if (put == null || put.isAssignableFrom(declaringClass)) {
|
|
return true;
|
|
}
|
|
this.c.put(sb2, put);
|
|
return false;
|
|
}
|
|
|
|
void a() {
|
|
if (this.f) {
|
|
this.e = null;
|
|
return;
|
|
}
|
|
this.e = this.e.getSuperclass();
|
|
String name = this.e.getName();
|
|
if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
|
|
this.e = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private List<SubscriberMethod> c(Class<?> cls) {
|
|
FindState a = a();
|
|
a.a(cls);
|
|
while (a.e != null) {
|
|
a(a);
|
|
a.a();
|
|
}
|
|
return b(a);
|
|
}
|
|
|
|
private FindState a() {
|
|
synchronized (e) {
|
|
for (int i = 0; i < 4; i++) {
|
|
FindState findState = e[i];
|
|
if (findState != null) {
|
|
e[i] = null;
|
|
return findState;
|
|
}
|
|
}
|
|
return new FindState();
|
|
}
|
|
}
|
|
|
|
private List<SubscriberMethod> b(FindState findState) {
|
|
ArrayList arrayList = new ArrayList(findState.a);
|
|
findState.b();
|
|
synchronized (e) {
|
|
int i = 0;
|
|
while (true) {
|
|
if (i >= 4) {
|
|
break;
|
|
}
|
|
if (e[i] == null) {
|
|
e[i] = findState;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
private void a(FindState findState) {
|
|
Method[] methods;
|
|
try {
|
|
methods = findState.e.getDeclaredMethods();
|
|
} catch (Throwable unused) {
|
|
methods = findState.e.getMethods();
|
|
findState.f = true;
|
|
}
|
|
for (Method method : methods) {
|
|
int modifiers = method.getModifiers();
|
|
if ((modifiers & 1) != 0 && (modifiers & 5192) == 0) {
|
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
|
if (parameterTypes.length == 1) {
|
|
Subscribe subscribe = (Subscribe) method.getAnnotation(Subscribe.class);
|
|
if (subscribe != null) {
|
|
Class<?> cls = parameterTypes[0];
|
|
if (findState.a(method, cls)) {
|
|
findState.a.add(new SubscriberMethod(method, cls, subscribe.threadMode(), subscribe.priority(), subscribe.sticky()));
|
|
}
|
|
}
|
|
} else if (this.b && method.isAnnotationPresent(Subscribe.class)) {
|
|
throw new EventBusException("@Subscribe method " + (method.getDeclaringClass().getName() + "." + method.getName()) + "must have exactly 1 parameter but has " + parameterTypes.length);
|
|
}
|
|
} else if (this.b && method.isAnnotationPresent(Subscribe.class)) {
|
|
throw new EventBusException((method.getDeclaringClass().getName() + "." + method.getName()) + " is a illegal @Subscribe method: must be public, non-static, and non-abstract");
|
|
}
|
|
}
|
|
}
|
|
}
|