String (@NotNull final PsiElement element) { if (ThrowSearchUtil.isSearchable(element)) { return ThrowSearchUtil.getSearchableTypeName(element); } if (element instanceof PsiDirectory) { return getPackageName((PsiDirectory)element, false); } if (element instanceof PsiPackage) { return getPackageName((PsiPackage)element); } if (element instanceof PsiFile) { return ((PsiFile)element).getVirtualFile().getPresentableUrl(); } if (element instanceof PsiLabeledStatement) { return ((PsiLabeledStatement)element).getLabelIdentifier().getText(); } if (element instanceof PsiClass) { if (element instanceof PsiAnonymousClass) { String name = ((PsiAnonymousClass)element).getBaseClassReference().getReferenceName(); return name != null ? JavaPsiBundle.message("java.terms.anonymous.class.base.ref", name) : JavaElementKind.ANONYMOUS_CLASS.subject(); } else { PsiClass aClass = (PsiClass)element; String qName = aClass.getQualifiedName(); @Nullable String value = aClass.getName(); return qName != null ? qName : value == null ? "" : value; } } if (element instanceof PsiMethod psiMethod) { String formatted = PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE); PsiClass psiClass = psiMethod.getContainingClass(); if (psiClass != null) { return getContainingClassDescription(psiClass, formatted); } return formatted; } if (element instanceof PsiField psiField) { String formatted = PsiFormatUtil.formatVariable(psiField, PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY); PsiClass psiClass = psiField.getContainingClass(); if (psiClass != null) { return getContainingClassDescription(psiClass, formatted); } return formatted; } if (element instanceof PsiVariable) { return PsiFormatUtil.formatVariable((PsiVariable)element, PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY); } if (element instanceof PsiLiteralExpression) { return element.getText(); } if (element instanceof PsiJavaModule) { return ((PsiJavaModule)element).getName(); } return ""; }