package kotlin.reflect.jvm.internal.impl.resolve;

import defpackage.cr4;
import defpackage.kp6;
import defpackage.pq6;
import defpackage.vx8;
import kotlin.reflect.jvm.internal.impl.descriptors.CallableDescriptor;
import kotlin.reflect.jvm.internal.impl.descriptors.ClassDescriptor;
import kotlin.reflect.jvm.internal.impl.descriptors.ClassifierDescriptor;
import kotlin.reflect.jvm.internal.impl.descriptors.DeclarationDescriptor;
import kotlin.reflect.jvm.internal.impl.descriptors.InlineClassRepresentation;
import kotlin.reflect.jvm.internal.impl.descriptors.MultiFieldValueClassRepresentation;
import kotlin.reflect.jvm.internal.impl.descriptors.PropertyDescriptor;
import kotlin.reflect.jvm.internal.impl.descriptors.PropertyGetterDescriptor;
import kotlin.reflect.jvm.internal.impl.descriptors.ValueClassRepresentation;
import kotlin.reflect.jvm.internal.impl.descriptors.VariableDescriptor;
import kotlin.reflect.jvm.internal.impl.name.ClassId;
import kotlin.reflect.jvm.internal.impl.name.FqName;
import kotlin.reflect.jvm.internal.impl.name.Name;
import kotlin.reflect.jvm.internal.impl.resolve.descriptorUtil.DescriptorUtilsKt;
import kotlin.reflect.jvm.internal.impl.types.KotlinType;
import kotlin.reflect.jvm.internal.impl.types.SimpleType;
import kotlin.reflect.jvm.internal.impl.types.TypeSubstitutor;
import kotlin.reflect.jvm.internal.impl.types.Variance;
import kotlin.reflect.jvm.internal.impl.types.checker.SimpleClassicTypeSystemContext;

/* JADX INFO: loaded from: classes3.dex */
@vx8
public final class InlineClassesUtilsKt {

    @kp6
    private static final ClassId JVM_INLINE_ANNOTATION_CLASS_ID;

    @kp6
    private static final FqName JVM_INLINE_ANNOTATION_FQ_NAME;

    static {
        FqName fqName = new FqName("kotlin.jvm.JvmInline");
        JVM_INLINE_ANNOTATION_FQ_NAME = fqName;
        JVM_INLINE_ANNOTATION_CLASS_ID = ClassId.Companion.topLevel(fqName);
    }

    public static final boolean isGetterOfUnderlyingPropertyOfValueClass(@kp6 CallableDescriptor callableDescriptor) {
        cr4.g(callableDescriptor, "<this>");
        if (!(callableDescriptor instanceof PropertyGetterDescriptor)) {
            return false;
        }
        PropertyDescriptor correspondingProperty = ((PropertyGetterDescriptor) callableDescriptor).getCorrespondingProperty();
        cr4.f(correspondingProperty, "getCorrespondingProperty(...)");
        return isUnderlyingPropertyOfValueClass(correspondingProperty);
    }

    public static final boolean isInlineClass(@kp6 DeclarationDescriptor declarationDescriptor) {
        cr4.g(declarationDescriptor, "<this>");
        return (declarationDescriptor instanceof ClassDescriptor) && (((ClassDescriptor) declarationDescriptor).getValueClassRepresentation() instanceof InlineClassRepresentation);
    }

    public static final boolean isInlineClassType(@kp6 KotlinType kotlinType) {
        cr4.g(kotlinType, "<this>");
        ClassifierDescriptor classifierDescriptorMo170getDeclarationDescriptor = kotlinType.getConstructor().mo170getDeclarationDescriptor();
        if (classifierDescriptorMo170getDeclarationDescriptor != null) {
            return isInlineClass(classifierDescriptorMo170getDeclarationDescriptor);
        }
        return false;
    }

    public static final boolean isMultiFieldValueClass(@kp6 DeclarationDescriptor declarationDescriptor) {
        cr4.g(declarationDescriptor, "<this>");
        return (declarationDescriptor instanceof ClassDescriptor) && (((ClassDescriptor) declarationDescriptor).getValueClassRepresentation() instanceof MultiFieldValueClassRepresentation);
    }

    public static final boolean isUnderlyingPropertyOfInlineClass(@kp6 VariableDescriptor variableDescriptor) {
        InlineClassRepresentation<SimpleType> inlineClassRepresentation;
        cr4.g(variableDescriptor, "<this>");
        if (variableDescriptor.getExtensionReceiverParameter() != null) {
            return false;
        }
        DeclarationDescriptor containingDeclaration = variableDescriptor.getContainingDeclaration();
        Name underlyingPropertyName = null;
        ClassDescriptor classDescriptor = containingDeclaration instanceof ClassDescriptor ? (ClassDescriptor) containingDeclaration : null;
        if (classDescriptor != null && (inlineClassRepresentation = DescriptorUtilsKt.getInlineClassRepresentation(classDescriptor)) != null) {
            underlyingPropertyName = inlineClassRepresentation.getUnderlyingPropertyName();
        }
        return cr4.b(underlyingPropertyName, variableDescriptor.getName());
    }

    public static final boolean isUnderlyingPropertyOfValueClass(@kp6 VariableDescriptor variableDescriptor) {
        ValueClassRepresentation<SimpleType> valueClassRepresentation;
        cr4.g(variableDescriptor, "<this>");
        if (variableDescriptor.getExtensionReceiverParameter() != null) {
            return false;
        }
        DeclarationDescriptor containingDeclaration = variableDescriptor.getContainingDeclaration();
        ClassDescriptor classDescriptor = containingDeclaration instanceof ClassDescriptor ? (ClassDescriptor) containingDeclaration : null;
        if (classDescriptor == null || (valueClassRepresentation = classDescriptor.getValueClassRepresentation()) == null) {
            return false;
        }
        Name name = variableDescriptor.getName();
        cr4.f(name, "getName(...)");
        return valueClassRepresentation.containsPropertyWithName(name);
    }

    public static final boolean isValueClass(@kp6 DeclarationDescriptor declarationDescriptor) {
        cr4.g(declarationDescriptor, "<this>");
        return isInlineClass(declarationDescriptor) || isMultiFieldValueClass(declarationDescriptor);
    }

    public static final boolean isValueClassType(@kp6 KotlinType kotlinType) {
        cr4.g(kotlinType, "<this>");
        ClassifierDescriptor classifierDescriptorMo170getDeclarationDescriptor = kotlinType.getConstructor().mo170getDeclarationDescriptor();
        if (classifierDescriptorMo170getDeclarationDescriptor != null) {
            return isValueClass(classifierDescriptorMo170getDeclarationDescriptor);
        }
        return false;
    }

    public static final boolean needsMfvcFlattening(@kp6 KotlinType kotlinType) {
        cr4.g(kotlinType, "<this>");
        ClassifierDescriptor classifierDescriptorMo170getDeclarationDescriptor = kotlinType.getConstructor().mo170getDeclarationDescriptor();
        return (classifierDescriptorMo170getDeclarationDescriptor == null || !isMultiFieldValueClass(classifierDescriptorMo170getDeclarationDescriptor) || SimpleClassicTypeSystemContext.INSTANCE.isNullableType(kotlinType)) ? false : true;
    }

    @pq6
    public static final KotlinType substitutedUnderlyingType(@kp6 KotlinType kotlinType) {
        cr4.g(kotlinType, "<this>");
        KotlinType kotlinTypeUnsubstitutedUnderlyingType = unsubstitutedUnderlyingType(kotlinType);
        if (kotlinTypeUnsubstitutedUnderlyingType != null) {
            return TypeSubstitutor.create(kotlinType).substitute(kotlinTypeUnsubstitutedUnderlyingType, Variance.INVARIANT);
        }
        return null;
    }

    @pq6
    public static final KotlinType unsubstitutedUnderlyingType(@kp6 KotlinType kotlinType) {
        InlineClassRepresentation<SimpleType> inlineClassRepresentation;
        cr4.g(kotlinType, "<this>");
        ClassifierDescriptor classifierDescriptorMo170getDeclarationDescriptor = kotlinType.getConstructor().mo170getDeclarationDescriptor();
        ClassDescriptor classDescriptor = classifierDescriptorMo170getDeclarationDescriptor instanceof ClassDescriptor ? (ClassDescriptor) classifierDescriptorMo170getDeclarationDescriptor : null;
        if (classDescriptor == null || (inlineClassRepresentation = DescriptorUtilsKt.getInlineClassRepresentation(classDescriptor)) == null) {
            return null;
        }
        return (SimpleType) inlineClassRepresentation.getUnderlyingType();
    }
}
