p.java 源代码
package g4;
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;
public class p {
private static final Map<Class<?>, List<o>> f22666d = new ConcurrentHashMap();
private static final a[] f22667e = new a[4];
private List<h4.b> f22668a;
private final boolean f22669b;
private final boolean f22670c;
public static class a {
final List<o> f22671a = new ArrayList();
final Map<Class, Object> f22672b = new HashMap();
final Map<String, Class> f22673c = new HashMap();
final StringBuilder f22674d = new StringBuilder(128);
Class<?> f22675e;
Class<?> f22676f;
boolean f22677g;
a() {
}
private boolean b(Method method, Class<?> cls) {
this.f22674d.setLength(0);
this.f22674d.append(method.getName());
StringBuilder sb = this.f22674d;
sb.append('>');
sb.append(cls.getName());
String sb2 = this.f22674d.toString();
Class<?> declaringClass = method.getDeclaringClass();
Class put = this.f22673c.put(sb2, declaringClass);
if (put != null && !put.isAssignableFrom(declaringClass)) {
this.f22673c.put(sb2, put);
return false;
}
return true;
}
boolean a(Method method, Class<?> cls) {
Object put = this.f22672b.put(cls, method);
if (put == null) {
return true;
}
if (put instanceof Method) {
if (b((Method) put, cls)) {
this.f22672b.put(cls, this);
} else {
throw new IllegalStateException();
}
}
return b(method, cls);
}
void c(Class<?> cls) {
this.f22676f = cls;
this.f22675e = cls;
this.f22677g = false;
}
void d() {
if (this.f22677g) {
this.f22676f = null;
return;
}
Class<? super Object> superclass = this.f22676f.getSuperclass();
this.f22676f = superclass;
String name = superclass.getName();
if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
this.f22676f = null;
}
}
void e() {
this.f22671a.clear();
this.f22672b.clear();
this.f22673c.clear();
this.f22674d.setLength(0);
this.f22675e = null;
this.f22676f = null;
this.f22677g = false;
}
}
public p(List<h4.b> list, boolean z6, boolean z7) {
this.f22668a = list;
this.f22669b = z6;
this.f22670c = z7;
}
private List<o> b(Class<?> cls) {
a g6 = g();
g6.c(cls);
while (g6.f22676f != null) {
f(g6);
d(g6);
g6.d();
}
return e(g6);
}
private List<o> c(Class<?> cls) {
a g6 = g();
g6.c(cls);
while (g6.f22676f != null) {
d(g6);
g6.d();
}
return e(g6);
}
private void d(a aVar) {
Method[] methods;
try {
methods = aVar.f22676f.getDeclaredMethods();
} catch (Throwable unused) {
methods = aVar.f22676f.getMethods();
aVar.f22677g = true;
}
for (Method method : methods) {
int modifiers = method.getModifiers();
if ((modifiers & 1) != 0 && (modifiers & 5192) == 0) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1) {
m mVar = (m) method.getAnnotation(m.class);
if (mVar != null) {
Class<?> cls = parameterTypes[0];
if (aVar.a(method, cls)) {
aVar.f22671a.add(new o(method, cls, mVar.threadMode(), mVar.priority(), mVar.sticky()));
}
}
} else if (this.f22669b && method.isAnnotationPresent(m.class)) {
throw new e("@Subscribe method " + (method.getDeclaringClass().getName() + "." + method.getName()) + "must have exactly 1 parameter but has " + parameterTypes.length);
}
} else if (this.f22669b && method.isAnnotationPresent(m.class)) {
throw new e((method.getDeclaringClass().getName() + "." + method.getName()) + " is a illegal @Subscribe method: must be public, non-static, and non-abstract");
}
}
}
private List<o> e(a aVar) {
ArrayList arrayList = new ArrayList(aVar.f22671a);
aVar.e();
synchronized (f22667e) {
int i6 = 0;
while (true) {
if (i6 >= 4) {
break;
}
a[] aVarArr = f22667e;
if (aVarArr[i6] == null) {
aVarArr[i6] = aVar;
break;
}
i6++;
}
}
return arrayList;
}
private h4.a f(a aVar) {
aVar.getClass();
List<h4.b> list = this.f22668a;
if (list != null) {
Iterator<h4.b> it = list.iterator();
while (it.hasNext()) {
it.next().a(aVar.f22676f);
}
return null;
}
return null;
}
private a g() {
synchronized (f22667e) {
for (int i6 = 0; i6 < 4; i6++) {
a[] aVarArr = f22667e;
a aVar = aVarArr[i6];
if (aVar != null) {
aVarArr[i6] = null;
return aVar;
}
}
return new a();
}
}
public List<o> a(Class<?> cls) {
List<o> b6;
Map<Class<?>, List<o>> map = f22666d;
List<o> list = map.get(cls);
if (list != null) {
return list;
}
if (this.f22670c) {
b6 = c(cls);
} else {
b6 = b(cls);
}
if (!b6.isEmpty()) {
map.put(cls, b6);
return b6;
}
throw new e("Subscriber " + cls + " and its super classes have no public methods with the @Subscribe annotation");
}
}