Search in sources :

Example 1 with KotlinLookupLocation

use of org.jetbrains.kotlin.incremental.KotlinLookupLocation in project kotlin by JetBrains.

the class DataFlowAnalyzer method typeHasOverriddenEquals.

private static boolean typeHasOverriddenEquals(@NotNull KotlinType type, @NotNull KtElement lookupElement) {
    Collection<SimpleFunctionDescriptor> members = type.getMemberScope().getContributedFunctions(OperatorNameConventions.EQUALS, new KotlinLookupLocation(lookupElement));
    for (FunctionDescriptor member : members) {
        KotlinType returnType = member.getReturnType();
        if (returnType == null || !KotlinBuiltIns.isBoolean(returnType))
            continue;
        if (member.getValueParameters().size() != 1)
            continue;
        KotlinType parameterType = member.getValueParameters().iterator().next().getType();
        if (!KotlinBuiltIns.isNullableAny(parameterType))
            continue;
        FunctionDescriptor fromSuperClass = getOverriddenDescriptorFromClass(member);
        if (fromSuperClass == null)
            return false;
        ClassifierDescriptor superClassDescriptor = (ClassifierDescriptor) fromSuperClass.getContainingDeclaration();
        // We should have override fun in class other than Any (to prove unknown behaviour)
        return !KotlinBuiltIns.isAnyOrNullableAny(superClassDescriptor.getDefaultType());
    }
    return false;
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) KotlinLookupLocation(org.jetbrains.kotlin.incremental.KotlinLookupLocation)

Aggregations

KotlinLookupLocation (org.jetbrains.kotlin.incremental.KotlinLookupLocation)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1