package com.google.gson.internal.bind;

import com.google.gson.h;
import com.google.gson.p;
import com.google.gson.u;
import com.google.gson.v;

/* loaded from: classes3.dex */
public final class JsonAdapterAnnotationTypeAdapterFactory implements v {

    /* renamed from: p, reason: collision with root package name */
    private final uk.c f14887p;

    public JsonAdapterAnnotationTypeAdapterFactory(uk.c cVar) {
        this.f14887p = cVar;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public u a(uk.c cVar, com.google.gson.d dVar, com.google.gson.reflect.a aVar, tk.b bVar) {
        u treeTypeAdapter;
        Object a10 = cVar.a(com.google.gson.reflect.a.get(bVar.value())).a();
        if (a10 instanceof u) {
            treeTypeAdapter = (u) a10;
        } else if (a10 instanceof v) {
            treeTypeAdapter = ((v) a10).create(dVar, aVar);
        } else {
            boolean z10 = a10 instanceof p;
            if (!z10 && !(a10 instanceof h)) {
                throw new IllegalArgumentException("Invalid attempt to bind an instance of " + a10.getClass().getName() + " as a @JsonAdapter for " + aVar.toString() + ". @JsonAdapter value must be a TypeAdapter, TypeAdapterFactory, JsonSerializer or JsonDeserializer.");
            }
            treeTypeAdapter = new TreeTypeAdapter(z10 ? (p) a10 : null, a10 instanceof h ? (h) a10 : null, dVar, aVar, null);
        }
        return (treeTypeAdapter == null || !bVar.nullSafe()) ? treeTypeAdapter : treeTypeAdapter.nullSafe();
    }

    @Override // com.google.gson.v
    public u create(com.google.gson.d dVar, com.google.gson.reflect.a aVar) {
        tk.b bVar = (tk.b) aVar.getRawType().getAnnotation(tk.b.class);
        if (bVar == null) {
            return null;
        }
        return a(this.f14887p, dVar, aVar, bVar);
    }
}
