package d.i.f.g.e;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;

/* JADX INFO: compiled from: Reflect.java */
/* JADX INFO: loaded from: classes.dex */
public class b {
    public final Class<?> a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f3661b;

    /* JADX INFO: compiled from: Reflect.java */
    public static class a {
    }

    public b(Class<?> cls) {
        this.a = cls;
        this.f3661b = cls;
    }

    public static <T extends AccessibleObject> T a(T t) {
        if (t == null) {
            return null;
        }
        if (t instanceof Member) {
            Member member = (Member) t;
            if (Modifier.isPublic(member.getModifiers()) && Modifier.isPublic(member.getDeclaringClass().getModifiers())) {
                return t;
            }
        }
        if (!t.isAccessible()) {
            t.setAccessible(true);
        }
        return t;
    }

    public static b d(Object obj) {
        return new b(obj == null ? Object.class : obj.getClass(), obj);
    }

    public static b e(Method method, Object obj, Object... objArr) throws c {
        try {
            a(method);
            if (method.getReturnType() != Void.TYPE) {
                return d(method.invoke(obj, objArr));
            }
            method.invoke(obj, objArr);
            return d(obj);
        } catch (Exception e2) {
            throw new c(e2);
        }
    }

    public static Class<?> g(Class<?> cls) {
        if (cls == null) {
            return null;
        }
        return cls.isPrimitive() ? Boolean.TYPE == cls ? Boolean.class : Integer.TYPE == cls ? Integer.class : Long.TYPE == cls ? Long.class : Short.TYPE == cls ? Short.class : Byte.TYPE == cls ? Byte.class : Double.TYPE == cls ? Double.class : Float.TYPE == cls ? Float.class : Character.TYPE == cls ? Character.class : Void.TYPE == cls ? Void.class : cls : cls;
    }

    public b b(String str, Object... objArr) throws c {
        Class<?>[] clsArr;
        Method declaredMethod;
        if (objArr == null) {
            clsArr = new Class[0];
        } else {
            Class<?>[] clsArr2 = new Class[objArr.length];
            for (int i2 = 0; i2 < objArr.length; i2++) {
                Object obj = objArr[i2];
                clsArr2[i2] = obj == null ? a.class : obj.getClass();
            }
            clsArr = clsArr2;
        }
        try {
            try {
                Class<?> superclass = this.a;
                try {
                    declaredMethod = superclass.getMethod(str, clsArr);
                } catch (NoSuchMethodException unused) {
                    do {
                        try {
                            declaredMethod = superclass.getDeclaredMethod(str, clsArr);
                        } catch (NoSuchMethodException unused2) {
                            superclass = superclass.getSuperclass();
                            if (superclass == null) {
                                throw new NoSuchMethodException();
                            }
                        }
                    } while (superclass == null);
                    throw new NoSuchMethodException();
                }
                return e(declaredMethod, this.f3661b, objArr);
            } catch (NoSuchMethodException unused3) {
                return e(f(str, clsArr), this.f3661b, objArr);
            }
        } catch (NoSuchMethodException e2) {
            throw new c(e2);
        }
    }

    public final boolean c(Method method, String str, Class<?>[] clsArr) {
        boolean z;
        if (!method.getName().equals(str)) {
            return false;
        }
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length != clsArr.length) {
            z = false;
            break;
        }
        for (int i2 = 0; i2 < clsArr.length; i2++) {
            if (clsArr[i2] != a.class && !g(parameterTypes[i2]).isAssignableFrom(g(clsArr[i2]))) {
                z = false;
                break;
            }
        }
        z = true;
        return z;
    }

    public boolean equals(Object obj) {
        if (obj instanceof b) {
            return this.f3661b.equals(((b) obj).f3661b);
        }
        return false;
    }

    public final Method f(String str, Class<?>[] clsArr) throws NoSuchMethodException {
        Class<?> superclass = this.a;
        for (Method method : superclass.getMethods()) {
            if (c(method, str, clsArr)) {
                return method;
            }
        }
        do {
            for (Method method2 : superclass.getDeclaredMethods()) {
                if (c(method2, str, clsArr)) {
                    return method2;
                }
            }
            superclass = superclass.getSuperclass();
        } while (superclass != null);
        StringBuilder sbE = d.b.a.a.a.E("No similar method ", str, " with params ");
        sbE.append(Arrays.toString(clsArr));
        sbE.append(" could be found on type ");
        sbE.append(this.a);
        sbE.append(".");
        throw new NoSuchMethodException(sbE.toString());
    }

    public int hashCode() {
        return this.f3661b.hashCode();
    }

    public String toString() {
        return this.f3661b.toString();
    }

    public b(Class<?> cls, Object obj) {
        this.a = cls;
        this.f3661b = obj;
    }
}
