package defpackage;

import com.squareup.moshi.JsonDataException;
import j$.util.DesugarCollections;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Set;

/* JADX INFO: renamed from: ᵲᵴ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC4534 {

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static final Class f17253;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static final Set f17254 = Collections.EMPTY_SET;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static final Type[] f17252 = new Type[0];

    static {
        Class<?> cls;
        try {
            cls = Class.forName(getKotlinMetadataClassName());
        } catch (ClassNotFoundException unused) {
            cls = null;
        }
        f17253 = cls;
        LinkedHashMap linkedHashMap = new LinkedHashMap(16);
        linkedHashMap.put(Boolean.TYPE, Boolean.class);
        linkedHashMap.put(Byte.TYPE, Byte.class);
        linkedHashMap.put(Character.TYPE, Character.class);
        linkedHashMap.put(Double.TYPE, Double.class);
        linkedHashMap.put(Float.TYPE, Float.class);
        linkedHashMap.put(Integer.TYPE, Integer.class);
        linkedHashMap.put(Long.TYPE, Long.class);
        linkedHashMap.put(Short.TYPE, Short.class);
        linkedHashMap.put(Void.TYPE, Void.class);
        DesugarCollections.unmodifiableMap(linkedHashMap);
    }

    private static String getKotlinMetadataClassName() {
        return "kotlin.Metadata";
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static void m9575(Type type) {
        if ((type instanceof Class) && ((Class) type).isPrimitive()) {
            C4468.m9517("Unexpected primitive ", type, ". Use the boxed type.");
        }
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public static String m9576(Type type, Set set) {
        String str;
        StringBuilder sb = new StringBuilder();
        sb.append(type);
        if (set.isEmpty()) {
            str = " (with no annotations)";
        } else {
            str = " annotated " + set;
        }
        sb.append(str);
        return sb.toString();
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static Type m9577(Type type, Class cls, Class cls2) {
        if (cls2 == cls) {
            return type;
        }
        if (cls2.isInterface()) {
            Class<?>[] interfaces = cls.getInterfaces();
            int length = interfaces.length;
            for (int i = 0; i < length; i++) {
                Class<?> cls3 = interfaces[i];
                if (cls3 == cls2) {
                    return cls.getGenericInterfaces()[i];
                }
                if (cls2.isAssignableFrom(cls3)) {
                    return m9577(cls.getGenericInterfaces()[i], interfaces[i], cls2);
                }
            }
        }
        if (!cls.isInterface()) {
            while (cls != Object.class) {
                Class<?> superclass = cls.getSuperclass();
                if (superclass == cls2) {
                    return cls.getGenericSuperclass();
                }
                if (cls2.isAssignableFrom(superclass)) {
                    return m9577(cls.getGenericSuperclass(), superclass, cls2);
                }
                cls = superclass;
            }
        }
        return cls2;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static JsonDataException m9578(String str, String str2, C4877 c4877) {
        String string;
        String strM10131 = c4877.m10131();
        if (str2.equals(str)) {
            string = AbstractC0793.m2874("Required value '", str, "' missing at ", strM10131);
        } else {
            StringBuilder sbM8226 = AbstractC3653.m8226("Required value '", str, "' (JSON name '", str2, "') missing at ");
            sbM8226.append(strM10131);
            string = sbM8226.toString();
        }
        return new JsonDataException(string);
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public static JsonDataException m9579(String str, String str2, C4877 c4877) {
        String string;
        String strM10131 = c4877.m10131();
        if (str2.equals(str)) {
            string = AbstractC0793.m2874("Non-null value '", str, "' was null at ", strM10131);
        } else {
            StringBuilder sbM8226 = AbstractC3653.m8226("Non-null value '", str, "' (JSON name '", str2, "') was null at ");
            sbM8226.append(strM10131);
            string = sbM8226.toString();
        }
        return new JsonDataException(string);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static Type m9580(Type type) {
        if (type instanceof Class) {
            Class cls = (Class) type;
            return cls.isArray() ? new C4242(m9580(cls.getComponentType())) : cls;
        }
        if (type instanceof ParameterizedType) {
            if (type instanceof C2513) {
                return type;
            }
            ParameterizedType parameterizedType = (ParameterizedType) type;
            return new C2513(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
        }
        if (type instanceof GenericArrayType) {
            return type instanceof C4242 ? type : new C4242(((GenericArrayType) type).getGenericComponentType());
        }
        if (!(type instanceof WildcardType) || (type instanceof C0704)) {
            return type;
        }
        WildcardType wildcardType = (WildcardType) type;
        return new C0704(wildcardType.getUpperBounds(), wildcardType.getLowerBounds());
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public static void m9581(InvocationTargetException invocationTargetException) {
        Throwable targetException = invocationTargetException.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw ((RuntimeException) targetException);
        }
        if (!(targetException instanceof Error)) {
            throw new RuntimeException(targetException);
        }
        throw ((Error) targetException);
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static boolean m9582(Class cls) {
        String name = cls.getName();
        return name.startsWith("android.") || name.startsWith("androidx.") || name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("kotlin.") || name.startsWith("kotlinx.") || name.startsWith("scala.");
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public static String m9583(Type type) {
        return type instanceof Class ? ((Class) type).getName() : type.toString();
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0049  */
    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Type m9584(Type type, Class cls, Type type2, LinkedHashSet linkedHashSet) {
        TypeVariable typeVariable;
        do {
            int i = 0;
            if (!(type2 instanceof TypeVariable)) {
                if (type2 instanceof Class) {
                    Class cls2 = (Class) type2;
                    if (cls2.isArray()) {
                        Class<?> componentType = cls2.getComponentType();
                        Type typeM9584 = m9584(type, cls, componentType, linkedHashSet);
                        return componentType == typeM9584 ? cls2 : new C4242(typeM9584);
                    }
                }
                if (type2 instanceof GenericArrayType) {
                    GenericArrayType genericArrayType = (GenericArrayType) type2;
                    Type genericComponentType = genericArrayType.getGenericComponentType();
                    Type typeM95842 = m9584(type, cls, genericComponentType, linkedHashSet);
                    return genericComponentType == typeM95842 ? genericArrayType : new C4242(typeM95842);
                }
                if (type2 instanceof ParameterizedType) {
                    ParameterizedType parameterizedType = (ParameterizedType) type2;
                    Type ownerType = parameterizedType.getOwnerType();
                    Type typeM95843 = m9584(type, cls, ownerType, linkedHashSet);
                    boolean z = typeM95843 != ownerType;
                    Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
                    int length = actualTypeArguments.length;
                    while (i < length) {
                        Type typeM95844 = m9584(type, cls, actualTypeArguments[i], linkedHashSet);
                        if (typeM95844 != actualTypeArguments[i]) {
                            if (!z) {
                                actualTypeArguments = (Type[]) actualTypeArguments.clone();
                                z = true;
                            }
                            actualTypeArguments[i] = typeM95844;
                        }
                        i++;
                    }
                    return z ? new C2513(typeM95843, parameterizedType.getRawType(), actualTypeArguments) : parameterizedType;
                }
                boolean z2 = type2 instanceof WildcardType;
                Type type3 = type2;
                if (z2) {
                    WildcardType wildcardType = (WildcardType) type2;
                    Type[] lowerBounds = wildcardType.getLowerBounds();
                    Type[] upperBounds = wildcardType.getUpperBounds();
                    if (lowerBounds.length == 1) {
                        Type typeM95845 = m9584(type, cls, lowerBounds[0], linkedHashSet);
                        type3 = wildcardType;
                        if (typeM95845 != lowerBounds[0]) {
                            return new C0704(new Type[]{Object.class}, typeM95845 instanceof WildcardType ? ((WildcardType) typeM95845).getLowerBounds() : new Type[]{typeM95845});
                        }
                    } else {
                        type3 = wildcardType;
                        if (upperBounds.length == 1) {
                            Type typeM95846 = m9584(type, cls, upperBounds[0], linkedHashSet);
                            type3 = wildcardType;
                            if (typeM95846 != upperBounds[0]) {
                                return new C0704(typeM95846 instanceof WildcardType ? ((WildcardType) typeM95846).getUpperBounds() : new Type[]{typeM95846}, f17252);
                            }
                        }
                    }
                }
                return type3;
            }
            typeVariable = (TypeVariable) type2;
            if (linkedHashSet.contains(typeVariable)) {
                return type2;
            }
            linkedHashSet.add(typeVariable);
            GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
            Class cls3 = genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
            if (cls3 == null) {
                type2 = typeVariable;
            } else {
                Type typeM9577 = m9577(type, cls, cls3);
                if (typeM9577 instanceof ParameterizedType) {
                    TypeVariable[] typeParameters = cls3.getTypeParameters();
                    while (i < typeParameters.length) {
                        if (typeVariable.equals(typeParameters[i])) {
                            type2 = ((ParameterizedType) typeM9577).getActualTypeArguments()[i];
                        } else {
                            i++;
                        }
                    }
                    C4468.m9518();
                    return null;
                }
            }
        } while (type2 != typeVariable);
        return type2;
    }
}
