String (@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) { if (location instanceof UsageViewShortNameLocation) { if (element instanceof PsiThrowStatement) { return JavaBundle.message("usage.target.exception"); } else if (element instanceof PsiAnonymousClass anonymousClass) { String name = anonymousClass.getBaseClassReference().getReferenceName(); return getAnonymousClassName(name); } else if (element instanceof PsiClassInitializer initializer) { boolean isStatic = initializer.hasModifierProperty(PsiModifier.STATIC); return isStatic ? CLINIT : INIT; } else if (element instanceof PsiUnnamedClass unnamedClass) { return unnamedClass.getContainingFile().getName(); } } if (location instanceof UsageViewLongNameLocation) { if (element instanceof PsiPackage) { return ((PsiPackage)element).getQualifiedName(); } else if (element instanceof PsiClass aClass) { if (element instanceof PsiAnonymousClass anonymousClass) { String name = anonymousClass.getBaseClassReference().getReferenceName(); return getAnonymousClassName(name); } else { String ret = aClass.getQualifiedName(); // It happens for local classes if (ret == null) { ret = aClass.getName(); } @NonNls String finalName = ObjectUtils.notNull(ret, NO_NAME_CLASS_VALUE); return finalName; } } else if (element instanceof PsiVariable var) { return var.getName(); } else if (element instanceof PsiMethod psiMethod) { return PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE); } } return null; }