package kotlin.reflect;

import g.h.a.i;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import kotlin.Metadata;
import kotlin.NoWhenBranchMatchedException;
import kotlin.jvm.internal.o;
import kotlin.reflect.KClass;
import kotlin.reflect.KType;
import kotlin.reflect.w.internal.y0.n.c2.c;
import kotlin.sequences.Sequence;
import kotlin.sequences.q;
import kotlin.text.j;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u00000\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\u001a\"\u0010\n\u001a\u00020\u00012\n\u0010\u000b\u001a\u0006\u0012\u0002\b\u00030\f2\f\u0010\r\u001a\b\u0012\u0004\u0012\u00020\u00070\u000eH\u0003\u001a\u0010\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0011\u001a\u00020\u0001H\u0002\u001a\u0016\u0010\u0012\u001a\u00020\u0001*\u00020\u00022\b\b\u0002\u0010\u0013\u001a\u00020\u0014H\u0003\"\u001e\u0010\u0000\u001a\u00020\u0001*\u00020\u00028FX\u0087\u0004¢\u0006\f\u0012\u0004\b\u0003\u0010\u0004\u001a\u0004\b\u0005\u0010\u0006\"\u001e\u0010\u0000\u001a\u00020\u0001*\u00020\u00078BX\u0083\u0004¢\u0006\f\u0012\u0004\b\u0003\u0010\b\u001a\u0004\b\u0005\u0010\t¨\u0006\u0015"}, d2 = {"javaType", "Ljava/lang/reflect/Type;", "Lkotlin/reflect/KType;", "getJavaType$annotations", "(Lkotlin/reflect/KType;)V", "getJavaType", "(Lkotlin/reflect/KType;)Ljava/lang/reflect/Type;", "Lkotlin/reflect/KTypeProjection;", "(Lkotlin/reflect/KTypeProjection;)V", "(Lkotlin/reflect/KTypeProjection;)Ljava/lang/reflect/Type;", "createPossiblyInnerType", "jClass", "Ljava/lang/Class;", "arguments", "", "typeToString", "", "type", "computeJavaType", "forceWrapper", "", "kotlin-stdlib"}, k = 2, mv = {1, 7, 1}, xi = 48)
public final class s {

    @Metadata(k = 3, mv = {1, 7, 1}, xi = 48)
    public /* synthetic */ class a {
        public static final /* synthetic */ int[] a;

        static {
            KVariance.values();
            int[] iArr = new int[3];
            try {
                iArr[1] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[0] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[2] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            a = iArr;
        }
    }

    public static final String a(Type type) {
        String name;
        Object next;
        if (!(type instanceof Class)) {
            return type.toString();
        }
        Class cls = (Class) type;
        if (cls.isArray()) {
            Sequence sequenceO = c.O(type, t.f6237f);
            StringBuilder sb = new StringBuilder();
            o.f(sequenceO, "<this>");
            Iterator it = sequenceO.iterator();
            if (!it.hasNext()) {
                throw new NoSuchElementException("Sequence is empty.");
            }
            do {
                next = it.next();
            } while (it.hasNext());
            sb.append(((Class) next).getName());
            sb.append(j.A("[]", q.b(sequenceO)));
            name = sb.toString();
        } else {
            name = cls.getName();
        }
        o.e(name, "{\n        if (type.isArr…   } else type.name\n    }");
        return name;
    }

    public static final Type b(KType kType, boolean z2) {
        KClassifier kClassifierE = kType.e();
        if (kClassifierE instanceof KTypeParameter) {
            return new TypeVariableImpl((KTypeParameter) kClassifierE);
        }
        if (!(kClassifierE instanceof KClass)) {
            throw new UnsupportedOperationException("Unsupported type classifier: " + kType);
        }
        KClass kClass = (KClass) kClassifierE;
        Class clsO1 = z2 ? i.o1(kClass) : i.l1(kClass);
        List<KTypeProjection> listC = kType.c();
        if (listC.isEmpty()) {
            return clsO1;
        }
        if (!clsO1.isArray()) {
            return d(clsO1, listC);
        }
        if (clsO1.getComponentType().isPrimitive()) {
            return clsO1;
        }
        KTypeProjection kTypeProjection = (KTypeProjection) kotlin.collections.j.b0(listC);
        if (kTypeProjection == null) {
            throw new IllegalArgumentException("kotlin.Array must have exactly one type argument: " + kType);
        }
        KVariance kVariance = kTypeProjection.f6221c;
        KType kType2 = kTypeProjection.f6222d;
        int i2 = kVariance == null ? -1 : a.a[kVariance.ordinal()];
        if (i2 == -1 || i2 == 1) {
            return clsO1;
        }
        if (i2 != 2 && i2 != 3) {
            throw new NoWhenBranchMatchedException();
        }
        o.c(kType2);
        Type typeC = c(kType2, false, 1);
        return typeC instanceof Class ? clsO1 : new GenericArrayTypeImpl(typeC);
    }

    public static /* synthetic */ Type c(KType kType, boolean z2, int i2) {
        if ((i2 & 1) != 0) {
            z2 = false;
        }
        return b(kType, z2);
    }

    public static final Type d(Class<?> cls, List<KTypeProjection> list) {
        Class<?> declaringClass = cls.getDeclaringClass();
        if (declaringClass == null) {
            ArrayList arrayList = new ArrayList(i.H(list, 10));
            Iterator<T> it = list.iterator();
            while (it.hasNext()) {
                arrayList.add(e((KTypeProjection) it.next()));
            }
            return new ParameterizedTypeImpl(cls, null, arrayList);
        }
        if (Modifier.isStatic(cls.getModifiers())) {
            ArrayList arrayList2 = new ArrayList(i.H(list, 10));
            Iterator<T> it2 = list.iterator();
            while (it2.hasNext()) {
                arrayList2.add(e((KTypeProjection) it2.next()));
            }
            return new ParameterizedTypeImpl(cls, declaringClass, arrayList2);
        }
        int length = cls.getTypeParameters().length;
        Type typeD = d(declaringClass, list.subList(length, list.size()));
        List<KTypeProjection> listSubList = list.subList(0, length);
        ArrayList arrayList3 = new ArrayList(i.H(listSubList, 10));
        Iterator<T> it3 = listSubList.iterator();
        while (it3.hasNext()) {
            arrayList3.add(e((KTypeProjection) it3.next()));
        }
        return new ParameterizedTypeImpl(cls, typeD, arrayList3);
    }

    public static final Type e(KTypeProjection kTypeProjection) {
        KVariance kVariance = kTypeProjection.f6221c;
        if (kVariance == null) {
            return WildcardTypeImpl.f6239m;
        }
        KType kType = kTypeProjection.f6222d;
        o.c(kType);
        int iOrdinal = kVariance.ordinal();
        if (iOrdinal == 0) {
            return b(kType, true);
        }
        if (iOrdinal == 1) {
            return new WildcardTypeImpl(null, b(kType, true));
        }
        if (iOrdinal == 2) {
            return new WildcardTypeImpl(b(kType, true), null);
        }
        throw new NoWhenBranchMatchedException();
    }
}
