package on;

import hp.e0;
import hp.l1;
import hp.m0;
import hp.p1;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kotlin.jvm.internal.t;
import nn.h0;
import nn.p0;
import sm.v;
import sm.z;
import tn.i1;
import tn.j1;
import tn.l;
import tn.m;
import tn.t0;
import tn.w0;

/* loaded from: classes3.dex */
public abstract class k {
    /* JADX INFO: Access modifiers changed from: private */
    public static final void f(e eVar, int i10, tn.b bVar, boolean z10) {
        if (g.a(eVar) == i10) {
            return;
        }
        throw new h0("Inconsistent number of parameters in the descriptor and Java reflection object: " + g.a(eVar) + " != " + i10 + "\nCalling: " + bVar + "\nParameter types: " + eVar.a() + ")\nDefault: " + z10);
    }

    public static final Object g(Object obj, tn.b descriptor) {
        e0 k10;
        Class r10;
        Method l10;
        t.g(descriptor, "descriptor");
        return (((descriptor instanceof t0) && to.h.e((j1) descriptor)) || (k10 = k(descriptor)) == null || (r10 = r(k10)) == null || (l10 = l(r10, descriptor)) == null) ? obj : l10.invoke(obj, new Object[0]);
    }

    public static final e h(e eVar, tn.b descriptor, boolean z10) {
        boolean z11;
        boolean z12;
        t.g(eVar, "<this>");
        t.g(descriptor, "descriptor");
        boolean z13 = true;
        if (!to.h.a(descriptor)) {
            List m02 = descriptor.m0();
            t.f(m02, "getContextReceiverParameters(...)");
            List list = m02;
            if (!(list instanceof Collection) || !list.isEmpty()) {
                Iterator it = list.iterator();
                while (it.hasNext()) {
                    e0 type = ((w0) it.next()).getType();
                    t.f(type, "getType(...)");
                    if (to.h.h(type)) {
                        z11 = true;
                        break;
                    }
                }
            }
            z11 = false;
            if (!z11) {
                List i10 = descriptor.i();
                t.f(i10, "getValueParameters(...)");
                List list2 = i10;
                if (!(list2 instanceof Collection) || !list2.isEmpty()) {
                    Iterator it2 = list2.iterator();
                    while (it2.hasNext()) {
                        e0 type2 = ((i1) it2.next()).getType();
                        t.f(type2, "getType(...)");
                        if (to.h.h(type2)) {
                            z12 = true;
                            break;
                        }
                    }
                }
                z12 = false;
                if (!z12) {
                    e0 returnType = descriptor.getReturnType();
                    if (!(returnType != null && to.h.c(returnType)) && !p(descriptor)) {
                        z13 = false;
                    }
                }
            }
        }
        return z13 ? new j(descriptor, eVar, z10) : eVar;
    }

    public static /* synthetic */ e i(e eVar, tn.b bVar, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return h(eVar, bVar, z10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final Method j(Class cls, tn.b bVar) {
        try {
            Method declaredMethod = cls.getDeclaredMethod("box-impl", l(cls, bVar).getReturnType());
            t.d(declaredMethod);
            return declaredMethod;
        } catch (NoSuchMethodException unused) {
            throw new h0("No box method found in inline class: " + cls + " (calling " + bVar + ')');
        }
    }

    private static final e0 k(tn.b bVar) {
        w0 g02 = bVar.g0();
        w0 Z = bVar.Z();
        if (g02 != null) {
            return g02.getType();
        }
        if (Z != null) {
            if (bVar instanceof l) {
                return Z.getType();
            }
            m b10 = bVar.b();
            tn.e eVar = b10 instanceof tn.e ? (tn.e) b10 : null;
            if (eVar != null) {
                return eVar.q();
            }
        }
        return null;
    }

    public static final Method l(Class cls, tn.b descriptor) {
        t.g(cls, "<this>");
        t.g(descriptor, "descriptor");
        try {
            Method declaredMethod = cls.getDeclaredMethod("unbox-impl", new Class[0]);
            t.d(declaredMethod);
            return declaredMethod;
        } catch (NoSuchMethodException unused) {
            throw new h0("No unbox method found in inline class: " + cls + " (calling " + descriptor + ')');
        }
    }

    public static final List m(m0 type) {
        int v10;
        int v11;
        t.g(type, "type");
        List n10 = n(l1.a(type));
        if (n10 == null) {
            return null;
        }
        List list = n10;
        v10 = v.v(list, 10);
        ArrayList arrayList = new ArrayList(v10);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            arrayList.add("unbox-impl-" + ((String) it.next()));
        }
        tn.h p10 = type.K0().p();
        t.e(p10, "null cannot be cast to non-null type org.jetbrains.kotlin.descriptors.ClassDescriptor");
        Class q10 = p0.q((tn.e) p10);
        t.d(q10);
        v11 = v.v(arrayList, 10);
        ArrayList arrayList2 = new ArrayList(v11);
        Iterator it2 = arrayList.iterator();
        while (it2.hasNext()) {
            arrayList2.add(q10.getDeclaredMethod((String) it2.next(), new Class[0]));
        }
        return arrayList2;
    }

    private static final List n(m0 m0Var) {
        Collection e10;
        int v10;
        if (!to.h.i(m0Var)) {
            return null;
        }
        tn.h p10 = m0Var.K0().p();
        t.e(p10, "null cannot be cast to non-null type org.jetbrains.kotlin.descriptors.ClassDescriptor");
        tn.h0 q10 = xo.c.q((tn.e) p10);
        t.d(q10);
        List<rm.v> b10 = q10.b();
        ArrayList arrayList = new ArrayList();
        for (rm.v vVar : b10) {
            ro.f fVar = (ro.f) vVar.a();
            List n10 = n((m0) vVar.b());
            if (n10 != null) {
                List list = n10;
                v10 = v.v(list, 10);
                e10 = new ArrayList(v10);
                Iterator it = list.iterator();
                while (it.hasNext()) {
                    e10.add(fVar.m() + '-' + ((String) it.next()));
                }
            } else {
                e10 = sm.t.e(fVar.m());
            }
            z.A(arrayList, e10);
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final List o(m0 m0Var, tn.b bVar) {
        Method l10;
        List e10;
        List m10 = m(m0Var);
        if (m10 != null) {
            return m10;
        }
        Class r10 = r(m0Var);
        if (r10 == null || (l10 = l(r10, bVar)) == null) {
            return null;
        }
        e10 = sm.t.e(l10);
        return e10;
    }

    private static final boolean p(tn.b bVar) {
        e0 k10 = k(bVar);
        return k10 != null && to.h.h(k10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final List q(tn.b bVar, dn.l lVar) {
        ArrayList arrayList = new ArrayList();
        w0 g02 = bVar.g0();
        e0 type = g02 != null ? g02.getType() : null;
        if (type != null) {
            arrayList.add(type);
        } else if (bVar instanceof l) {
            tn.e x10 = ((l) bVar).x();
            t.f(x10, "getConstructedClass(...)");
            if (x10.I()) {
                m b10 = x10.b();
                t.e(b10, "null cannot be cast to non-null type org.jetbrains.kotlin.descriptors.ClassDescriptor");
                arrayList.add(((tn.e) b10).q());
            }
        } else {
            m b11 = bVar.b();
            t.f(b11, "getContainingDeclaration(...)");
            if ((b11 instanceof tn.e) && ((Boolean) lVar.invoke(b11)).booleanValue()) {
                arrayList.add(((tn.e) b11).q());
            }
        }
        List i10 = bVar.i();
        t.f(i10, "getValueParameters(...)");
        Iterator it = i10.iterator();
        while (it.hasNext()) {
            arrayList.add(((i1) it.next()).getType());
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final Class r(e0 e0Var) {
        Class s10 = s(e0Var.K0().p());
        if (s10 == null) {
            return null;
        }
        if (!p1.l(e0Var)) {
            return s10;
        }
        e0 k10 = to.h.k(e0Var);
        if (k10 == null || p1.l(k10) || qn.g.s0(k10)) {
            return null;
        }
        return s10;
    }

    public static final Class s(m mVar) {
        if (!(mVar instanceof tn.e) || !to.h.b(mVar)) {
            return null;
        }
        tn.e eVar = (tn.e) mVar;
        Class q10 = p0.q(eVar);
        if (q10 != null) {
            return q10;
        }
        throw new h0("Class object for the class " + eVar.getName() + " cannot be found (classId=" + xo.c.k((tn.h) mVar) + ')');
    }

    public static final String t(tn.h hVar) {
        t.g(hVar, "<this>");
        ro.b k10 = xo.c.k(hVar);
        t.d(k10);
        String c10 = k10.c();
        t.f(c10, "asString(...)");
        return qo.b.b(c10);
    }
}
