FoundItemDescriptor<Object> (FoundItemDescriptor<Object> elementDescriptor, Function<? super PsiElement, ? extends TargetPresentation> presentationCalculator) { if (elementDescriptor.getItem() instanceof PsiItemWithSimilarity<?> itemWithSimilarity) { var newDescriptor = new FoundItemDescriptor<Object>(itemWithSimilarity.getValue(), elementDescriptor.getWeight()); var descriptorWithPresentation = element2presentation(newDescriptor, presentationCalculator); return new FoundItemDescriptor<>(new PsiItemWithSimilarity<>(descriptorWithPresentation.getItem(), itemWithSimilarity.getSimilarityScore()), elementDescriptor.getWeight()); } if (elementDescriptor.getItem() instanceof PsiElement psi) { TargetPresentation presentation = presentationCalculator.apply(psi); return new FoundItemDescriptor<>(new PsiItemWithPresentation(psi, presentation), elementDescriptor.getWeight()); } return elementDescriptor; }