private static TargetPresentation calcPresentation(Object item, Function<? super PsiElement, ? extends TargetPresentation> psiPresentationCalculator,
                                                     @Nullable SearchEverywherePresentationProvider<Object> rendererPresentationProvider) {
    if (item instanceof PsiElement psi) {
      return psiPresentationCalculator.apply(psi);
    }

    if (item instanceof PsiElementNavigationItem psiElementNavigationItem) {
      var realElement = psiElementNavigationItem.getTargetElement();
      return psiPresentationCalculator.apply(realElement);
    }

    if (item instanceof NavigationItem navigationItem) {
      ItemPresentation itemPresentation = Objects.requireNonNull(navigationItem.getPresentation());
      return convertPresentation(itemPresentation);
    }

    if (item instanceof ItemPresentation itemPresentation) {
      return convertPresentation(itemPresentation);
    }

    if (rendererPresentationProvider != null) {
      return rendererPresentationProvider.getTargetPresentation(item);
    }

    LOG.error("Found items expected to be PsiItems or to have [com.intellij.navigation.ItemPresentation] field. But item [" + item.getClass() + "] is not");
    @NlsSafe String text = item.toString();
    return TargetPresentation.builder(text).icon(IconUtil.getEmptyIcon(false)).presentation();
  }
private static TargetPresentation calcPresentation(Object item, Function<? super PsiElement, ? extends TargetPresentation> psiPresentationCalculator,
                                                     @Nullable SearchEverywherePresentationProvider<Object> rendererPresentationProvider)