Search in sources :

Example 1 with JavaMethod

use of org.jetbrains.kotlin.load.java.structure.JavaMethod in project kotlin by JetBrains.

the class SignaturesPropagationData method getSuperFunctionsForMethod.

private static List<FunctionDescriptor> getSuperFunctionsForMethod(@NotNull JavaMethod method, @NotNull JavaMethodDescriptor autoMethodDescriptor, @NotNull ClassDescriptor containingClass) {
    List<FunctionDescriptor> superFunctions = Lists.newArrayList();
    // TODO: Add propagation for other kotlin descriptors (KT-3621)
    Name name = method.getName();
    Method autoSignature = null;
    boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor);
    for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
        Collection<SimpleFunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
        if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates))
            continue;
        if (autoSignature == null) {
            autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
        }
        for (FunctionDescriptor candidate : superFunctionCandidates) {
            // TODO: remove this continue when KT-15747 is fixed
            if (candidate.isSuspend())
                continue;
            Method candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
            if (KotlinToJvmSignatureMapperKt.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) {
                superFunctions.add(candidate);
            }
        }
    }
    // sorting for diagnostic stability
    Collections.sort(superFunctions, new Comparator<FunctionDescriptor>() {

        @Override
        public int compare(@NotNull FunctionDescriptor fun1, @NotNull FunctionDescriptor fun2) {
            FqNameUnsafe fqName1 = getFqName(fun1.getContainingDeclaration());
            FqNameUnsafe fqName2 = getFqName(fun2.getContainingDeclaration());
            return fqName1.asString().compareTo(fqName2.asString());
        }
    });
    return superFunctions;
}
Also used : FqNameUnsafe(org.jetbrains.kotlin.name.FqNameUnsafe) KotlinType(org.jetbrains.kotlin.types.KotlinType) JavaMethod(org.jetbrains.kotlin.load.java.structure.JavaMethod) Method(org.jetbrains.org.objectweb.asm.commons.Method) DescriptorUtils.getFqName(org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName) Name(org.jetbrains.kotlin.name.Name)

Aggregations

JavaMethod (org.jetbrains.kotlin.load.java.structure.JavaMethod)1 FqNameUnsafe (org.jetbrains.kotlin.name.FqNameUnsafe)1 Name (org.jetbrains.kotlin.name.Name)1 DescriptorUtils.getFqName (org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1