package kotlin.reflect.jvm.internal.impl.serialization.deserialization;

import androidx.media3.extractor.text.ttml.TtmlNode;
import defpackage.cr4;
import defpackage.ik2;
import defpackage.kp6;
import defpackage.vx8;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.reflect.jvm.internal.impl.metadata.ProtoBuf;
import kotlin.reflect.jvm.internal.impl.metadata.deserialization.NameResolver;
import kotlin.reflect.jvm.internal.impl.protobuf.GeneratedMessageLite;
import kotlin.reflect.jvm.internal.impl.protobuf.MessageLite;
import kotlin.reflect.jvm.internal.impl.serialization.SerializerExtensionProtocol;
import kotlin.reflect.jvm.internal.impl.serialization.deserialization.ProtoContainer;

/* JADX INFO: loaded from: classes3.dex */
@vx8
public abstract class AbstractAnnotationLoader<A> implements AnnotationLoader<A> {

    @kp6
    private final SerializerExtensionProtocol protocol;

    public /* synthetic */ class WhenMappings {
        public static final /* synthetic */ int[] $EnumSwitchMapping$0;

        static {
            int[] iArr = new int[AnnotatedCallableKind.values().length];
            try {
                iArr[AnnotatedCallableKind.PROPERTY.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[AnnotatedCallableKind.PROPERTY_GETTER.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[AnnotatedCallableKind.PROPERTY_SETTER.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    public AbstractAnnotationLoader(@kp6 SerializerExtensionProtocol serializerExtensionProtocol) {
        cr4.g(serializerExtensionProtocol, "protocol");
        this.protocol = serializerExtensionProtocol;
    }

    @kp6
    public final SerializerExtensionProtocol getProtocol() {
        return this.protocol;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadCallableAnnotations(@kp6 ProtoContainer protoContainer, @kp6 MessageLite messageLite, @kp6 AnnotatedCallableKind annotatedCallableKind) {
        List list;
        cr4.g(protoContainer, TtmlNode.RUBY_CONTAINER);
        cr4.g(messageLite, "proto");
        cr4.g(annotatedCallableKind, "kind");
        if (messageLite instanceof ProtoBuf.Constructor) {
            list = (List) ((ProtoBuf.Constructor) messageLite).getExtension(this.protocol.getConstructorAnnotation());
        } else if (messageLite instanceof ProtoBuf.Function) {
            list = (List) ((ProtoBuf.Function) messageLite).getExtension(this.protocol.getFunctionAnnotation());
        } else {
            if (!(messageLite instanceof ProtoBuf.Property)) {
                throw new IllegalStateException(("Unknown message: " + messageLite).toString());
            }
            int i = WhenMappings.$EnumSwitchMapping$0[annotatedCallableKind.ordinal()];
            if (i == 1) {
                list = (List) ((ProtoBuf.Property) messageLite).getExtension(this.protocol.getPropertyAnnotation());
            } else if (i == 2) {
                list = (List) ((ProtoBuf.Property) messageLite).getExtension(this.protocol.getPropertyGetterAnnotation());
            } else {
                if (i != 3) {
                    throw new IllegalStateException("Unsupported callable kind with property proto");
                }
                list = (List) ((ProtoBuf.Property) messageLite).getExtension(this.protocol.getPropertySetterAnnotation());
            }
        }
        if (list == null) {
            list = ik2.a;
        }
        List list2 = list;
        ArrayList arrayList = new ArrayList(y41.p(list2, 10));
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), protoContainer.getNameResolver()));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadClassAnnotations(@kp6 ProtoContainer.Class r5) {
        cr4.g(r5, TtmlNode.RUBY_CONTAINER);
        Iterable iterable = (List) r5.getClassProto().getExtension(this.protocol.getClassAnnotation());
        if (iterable == null) {
            iterable = ik2.a;
        }
        Iterable iterable2 = iterable;
        ArrayList arrayList = new ArrayList(y41.p(iterable2, 10));
        Iterator it = iterable2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), r5.getNameResolver()));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadEnumEntryAnnotations(@kp6 ProtoContainer protoContainer, @kp6 ProtoBuf.EnumEntry enumEntry) {
        cr4.g(protoContainer, TtmlNode.RUBY_CONTAINER);
        cr4.g(enumEntry, "proto");
        Iterable iterable = (List) enumEntry.getExtension(this.protocol.getEnumEntryAnnotation());
        if (iterable == null) {
            iterable = ik2.a;
        }
        Iterable iterable2 = iterable;
        ArrayList arrayList = new ArrayList(y41.p(iterable2, 10));
        Iterator it = iterable2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), protoContainer.getNameResolver()));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadExtensionReceiverParameterAnnotations(@kp6 ProtoContainer protoContainer, @kp6 MessageLite messageLite, @kp6 AnnotatedCallableKind annotatedCallableKind) {
        cr4.g(protoContainer, TtmlNode.RUBY_CONTAINER);
        cr4.g(messageLite, "proto");
        cr4.g(annotatedCallableKind, "kind");
        List list = null;
        if (messageLite instanceof ProtoBuf.Function) {
            GeneratedMessageLite.GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>> functionExtensionReceiverAnnotation = this.protocol.getFunctionExtensionReceiverAnnotation();
            if (functionExtensionReceiverAnnotation != null) {
                list = (List) ((ProtoBuf.Function) messageLite).getExtension(functionExtensionReceiverAnnotation);
            }
        } else {
            if (!(messageLite instanceof ProtoBuf.Property)) {
                throw new IllegalStateException(("Unknown message: " + messageLite).toString());
            }
            int i = WhenMappings.$EnumSwitchMapping$0[annotatedCallableKind.ordinal()];
            if (i != 1 && i != 2 && i != 3) {
                throw new IllegalStateException(("Unsupported callable kind with property proto for receiver annotations: " + annotatedCallableKind).toString());
            }
            GeneratedMessageLite.GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>> propertyExtensionReceiverAnnotation = this.protocol.getPropertyExtensionReceiverAnnotation();
            if (propertyExtensionReceiverAnnotation != null) {
                list = (List) ((ProtoBuf.Property) messageLite).getExtension(propertyExtensionReceiverAnnotation);
            }
        }
        if (list == null) {
            list = ik2.a;
        }
        List list2 = list;
        ArrayList arrayList = new ArrayList(y41.p(list2, 10));
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), protoContainer.getNameResolver()));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadPropertyBackingFieldAnnotations(@kp6 ProtoContainer protoContainer, @kp6 ProtoBuf.Property property) {
        cr4.g(protoContainer, TtmlNode.RUBY_CONTAINER);
        cr4.g(property, "proto");
        GeneratedMessageLite.GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>> propertyBackingFieldAnnotation = this.protocol.getPropertyBackingFieldAnnotation();
        List list = propertyBackingFieldAnnotation != null ? (List) property.getExtension(propertyBackingFieldAnnotation) : null;
        if (list == null) {
            list = ik2.a;
        }
        List list2 = list;
        ArrayList arrayList = new ArrayList(y41.p(list2, 10));
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), protoContainer.getNameResolver()));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadPropertyDelegateFieldAnnotations(@kp6 ProtoContainer protoContainer, @kp6 ProtoBuf.Property property) {
        cr4.g(protoContainer, TtmlNode.RUBY_CONTAINER);
        cr4.g(property, "proto");
        GeneratedMessageLite.GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>> propertyDelegatedFieldAnnotation = this.protocol.getPropertyDelegatedFieldAnnotation();
        List list = propertyDelegatedFieldAnnotation != null ? (List) property.getExtension(propertyDelegatedFieldAnnotation) : null;
        if (list == null) {
            list = ik2.a;
        }
        List list2 = list;
        ArrayList arrayList = new ArrayList(y41.p(list2, 10));
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), protoContainer.getNameResolver()));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadTypeAnnotations(@kp6 ProtoBuf.Type type, @kp6 NameResolver nameResolver) {
        cr4.g(type, "proto");
        cr4.g(nameResolver, "nameResolver");
        Iterable iterable = (List) type.getExtension(this.protocol.getTypeAnnotation());
        if (iterable == null) {
            iterable = ik2.a;
        }
        Iterable iterable2 = iterable;
        ArrayList arrayList = new ArrayList(y41.p(iterable2, 10));
        Iterator it = iterable2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), nameResolver));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadTypeParameterAnnotations(@kp6 ProtoBuf.TypeParameter typeParameter, @kp6 NameResolver nameResolver) {
        cr4.g(typeParameter, "proto");
        cr4.g(nameResolver, "nameResolver");
        Iterable iterable = (List) typeParameter.getExtension(this.protocol.getTypeParameterAnnotation());
        if (iterable == null) {
            iterable = ik2.a;
        }
        Iterable iterable2 = iterable;
        ArrayList arrayList = new ArrayList(y41.p(iterable2, 10));
        Iterator it = iterable2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), nameResolver));
        }
        return arrayList;
    }

    @Override // kotlin.reflect.jvm.internal.impl.serialization.deserialization.AnnotationLoader
    @kp6
    public List<A> loadValueParameterAnnotations(@kp6 ProtoContainer protoContainer, @kp6 MessageLite messageLite, @kp6 AnnotatedCallableKind annotatedCallableKind, int i, @kp6 ProtoBuf.ValueParameter valueParameter) {
        cr4.g(protoContainer, TtmlNode.RUBY_CONTAINER);
        cr4.g(messageLite, "callableProto");
        cr4.g(annotatedCallableKind, "kind");
        cr4.g(valueParameter, "proto");
        Iterable iterable = (List) valueParameter.getExtension(this.protocol.getParameterAnnotation());
        if (iterable == null) {
            iterable = ik2.a;
        }
        Iterable iterable2 = iterable;
        ArrayList arrayList = new ArrayList(y41.p(iterable2, 10));
        Iterator it = iterable2.iterator();
        while (it.hasNext()) {
            arrayList.add(loadAnnotation((ProtoBuf.Annotation) it.next(), protoContainer.getNameResolver()));
        }
        return arrayList;
    }
}
