package f5;

import android.content.Context;
import f5.r;

/* loaded from: classes.dex */
public final class q {

    /* renamed from: a, reason: collision with root package name */
    public static final q f17836a = new q();

    private q() {
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0020  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final r.a a(Context context, Class klass, String str) {
        boolean z10;
        boolean C;
        kotlin.jvm.internal.t.g(context, "context");
        kotlin.jvm.internal.t.g(klass, "klass");
        if (str != null) {
            C = kotlin.text.y.C(str);
            if (!C) {
                z10 = false;
                if (true ^ z10) {
                    throw new IllegalArgumentException("Cannot build a database with null or empty name. If you are trying to create an in memory database, use Room.inMemoryDatabaseBuilder".toString());
                }
                return new r.a(context, klass, str);
            }
        }
        z10 = true;
        if (true ^ z10) {
        }
    }

    public static final Object b(Class klass, String suffix) {
        String I;
        String str;
        kotlin.jvm.internal.t.g(klass, "klass");
        kotlin.jvm.internal.t.g(suffix, "suffix");
        Package r02 = klass.getPackage();
        kotlin.jvm.internal.t.d(r02);
        String fullPackage = r02.getName();
        String canonicalName = klass.getCanonicalName();
        kotlin.jvm.internal.t.d(canonicalName);
        kotlin.jvm.internal.t.f(fullPackage, "fullPackage");
        if (!(fullPackage.length() == 0)) {
            canonicalName = canonicalName.substring(fullPackage.length() + 1);
            kotlin.jvm.internal.t.f(canonicalName, "this as java.lang.String).substring(startIndex)");
        }
        String str2 = canonicalName;
        StringBuilder sb2 = new StringBuilder();
        I = kotlin.text.y.I(str2, '.', '_', false, 4, null);
        sb2.append(I);
        sb2.append(suffix);
        String sb3 = sb2.toString();
        try {
            if (fullPackage.length() == 0) {
                str = sb3;
            } else {
                str = fullPackage + '.' + sb3;
            }
            Class<?> cls = Class.forName(str, true, klass.getClassLoader());
            kotlin.jvm.internal.t.e(cls, "null cannot be cast to non-null type java.lang.Class<T of androidx.room.Room.getGeneratedImplementation>");
            return cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
        } catch (ClassNotFoundException unused) {
            throw new RuntimeException("Cannot find implementation for " + klass.getCanonicalName() + ". " + sb3 + " does not exist");
        } catch (IllegalAccessException unused2) {
            throw new RuntimeException("Cannot access the constructor " + klass.getCanonicalName());
        } catch (InstantiationException unused3) {
            throw new RuntimeException("Failed to create an instance of " + klass.getCanonicalName());
        }
    }

    public static final r.a c(Context context, Class klass) {
        kotlin.jvm.internal.t.g(context, "context");
        kotlin.jvm.internal.t.g(klass, "klass");
        return new r.a(context, klass, null);
    }
}
