Search in sources :

Example 1 with CallableMemberDescriptor

use of org.jetbrains.kotlin.descriptors.CallableMemberDescriptor in project kotlin by JetBrains.

the class KotlinOverridingDialog method formatElement.

private static String formatElement(PsiElement element) {
    element = KtPsiUtil.ascendIfPropertyAccessor(element);
    if (element instanceof KtNamedFunction || element instanceof KtProperty) {
        BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
        DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
        if (declarationDescriptor instanceof CallableMemberDescriptor) {
            DeclarationDescriptor containingDescriptor = declarationDescriptor.getContainingDeclaration();
            if (containingDescriptor instanceof ClassDescriptor) {
                return KotlinBundle.message("x.in.y", DescriptorRenderer.COMPACT.render(declarationDescriptor), IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(containingDescriptor));
            }
        }
    }
    assert element instanceof PsiMethod : "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found";
    return RenderingUtilsKt.formatPsiMethod((PsiMethod) element, true, false);
}
Also used : KtProperty(org.jetbrains.kotlin.psi.KtProperty) ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) PsiMethod(com.intellij.psi.PsiMethod) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) CallableMemberDescriptor(org.jetbrains.kotlin.descriptors.CallableMemberDescriptor)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)1 CallableMemberDescriptor (org.jetbrains.kotlin.descriptors.CallableMemberDescriptor)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)1 KtProperty (org.jetbrains.kotlin.psi.KtProperty)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1