@NotNull
  private static String getName(@NotNull UElement declaration) {
    PsiElement element = declaration.getJavaPsi();
    if (element instanceof PsiAnonymousClass anonymousClass) {
      PsiClass psiBaseClass = anonymousClass.getBaseClassType().resolve();
      if (psiBaseClass == null) {
        return JavaAnalysisBundle.message("inspection.reference.anonymous.class");
      }
      else {
        return JavaAnalysisBundle.message("inspection.reference.anonymous.name", psiBaseClass.getName());
      }
    }
    if (element instanceof PsiImplicitClass) {
      PsiFile file = element.getContainingFile();
      return JavaAnalysisBundle.message("inspection.reference.implicit.class", file.getName());
    }

    if (element instanceof PsiSyntheticClass jspClass) {
      final PsiFile jspxFile = jspClass.getContainingFile();
      return "<" + jspxFile.getName() + ">";
    }

    if (element instanceof PsiMethod) {
      if (element instanceof SyntheticElement) {
        Language language = element.getLanguage();
        if (language.isKindOf("JSP") || language.isKindOf("JSPX")) {
          return JavaAnalysisBundle.message("inspection.reference.jsp.holder.method.anonymous.name");
        }
      }
      return PsiFormatUtil.formatMethod((PsiMethod)element,
                                        PsiSubstitutor.EMPTY,
                                        PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
                                        PsiFormatUtilBase.SHOW_TYPE);
    }

    if (declaration instanceof ULambdaExpression || declaration instanceof UCallableReferenceExpression) {
      UDeclaration elementDeclaration = UDeclarationKt.getContainingDeclaration(declaration);
      boolean isMethodReference = declaration instanceof UCallableReferenceExpression;
      if (elementDeclaration != null) {
        UAnnotated pDeclaration =
          UastUtils.getParentOfType(elementDeclaration, false, UMethod.class, UClass.class, ULambdaExpression.class, UField.class);
        if (pDeclaration != null && pDeclaration.getSourcePsi() instanceof PsiNamedElement) {
          String name = ((PsiNamedElement)pDeclaration.getSourcePsi()).getName();
          return JavaAnalysisBundle.message(
            isMethodReference ? "inspection.reference.method.reference.name" : "inspection.reference.lambda.name", name);
        }
      }
      return JavaAnalysisBundle.message(
        isMethodReference ? "inspection.reference.default.method.reference.name" : "inspection.reference.default.lambda.name");
    }

    String name = null;
    if (element instanceof PsiNamedElement) {
      name = ((PsiNamedElement)element).getName();
    }
    return name == null ? AnalysisBundle.message("inspection.reference.anonymous") : name;
  }
@NotNull
  private static String getName(@NotNull UElement declaration)