String (@NotNull PsiElement element, boolean useFullName) { if (element instanceof PsiDirectory) { return getPackageName((PsiDirectory)element, false); } if (element instanceof PsiPackage) { return getPackageName((PsiPackage)element); } if (element instanceof PsiFile) { return useFullName ? ((PsiFile)element).getVirtualFile().getPresentableUrl() : ((PsiFile)element).getName(); } if (element instanceof PsiLabeledStatement) { return ((PsiLabeledStatement)element).getLabelIdentifier().getText(); } if (ThrowSearchUtil.isSearchable(element)) { return ThrowSearchUtil.getSearchableTypeName(element); } if (element instanceof PsiClass) { String name = ((PsiClass)element).getQualifiedName(); if (name == null || !useFullName) { name = ((PsiClass)element).getName(); } if (name != null) return name; } if (element instanceof PsiMethod psiMethod) { if (useFullName) { int options = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS; String s = PsiFormatUtil.formatMethod((PsiMethod)element, PsiSubstitutor.EMPTY, options, PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME); return appendClassName(s, psiMethod.getContainingClass()); } else { int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS; return PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, options, PsiFormatUtilBase.SHOW_TYPE); } } if (element instanceof PsiParameter parameter && parameter.getDeclarationScope() instanceof PsiMethod method) { int varOptions = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME; int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS; String s = JavaBundle.message("java.terms.variable.of.method", PsiFormatUtil.formatVariable((PsiVariable)element, varOptions, PsiSubstitutor.EMPTY), PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE)); return appendClassName(s, method.getContainingClass()); } if (element instanceof PsiField psiField) { int options = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME; String s = PsiFormatUtil.formatVariable(psiField, options, PsiSubstitutor.EMPTY); return appendClassName(s, psiField.getContainingClass()); } if (element instanceof PsiVariable) { int options = PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME; return PsiFormatUtil.formatVariable((PsiVariable)element, options, PsiSubstitutor.EMPTY); } return ""; }