Search in sources :

Example 1 with KtObjectDeclaration

use of org.jetbrains.kotlin.psi.KtObjectDeclaration in project kotlin by JetBrains.

the class ReferenceUtils method renderAsGotoImplementation.

public static String renderAsGotoImplementation(@NotNull PsiElement element) {
    PsiElement navigationElement = element.getNavigationElement();
    if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) {
        //default presenter return null for companion object
        KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class);
        assert containingClass != null;
        return "companion object of " + renderAsGotoImplementation(containingClass);
    }
    if (navigationElement instanceof KtStringTemplateExpression) {
        return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement);
    }
    Assert.assertTrue(navigationElement instanceof NavigationItem);
    ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
    if (presentation == null) {
        String elementText = element.getText();
        return elementText != null ? elementText : navigationElement.getText();
    }
    String presentableText = presentation.getPresentableText();
    String locationString = presentation.getLocationString();
    if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
        locationString = "<anonymous>";
    }
    return locationString == null || navigationElement instanceof PsiPackage ? // for PsiPackage, presentableText is FQ name of current package
    presentableText : locationString + "." + presentableText;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) KtClass(org.jetbrains.kotlin.psi.KtClass) KtStringTemplateExpression(org.jetbrains.kotlin.psi.KtStringTemplateExpression) ItemPresentation(com.intellij.navigation.ItemPresentation) KtObjectDeclaration(org.jetbrains.kotlin.psi.KtObjectDeclaration)

Aggregations

ItemPresentation (com.intellij.navigation.ItemPresentation)1 NavigationItem (com.intellij.navigation.NavigationItem)1 KtClass (org.jetbrains.kotlin.psi.KtClass)1 KtObjectDeclaration (org.jetbrains.kotlin.psi.KtObjectDeclaration)1 KtStringTemplateExpression (org.jetbrains.kotlin.psi.KtStringTemplateExpression)1