void (@NotNull PsiElement position, Consumer<? super LookupElement> consumer) { PsiMethod method = PsiTreeUtil.getParentOfType(position, PsiMethod.class); assert method != null; final PsiTypeVisitor<PsiType> eachProcessor = new PsiTypeVisitor<>() { private final Set<PsiType> myProcessed = new HashSet<>(); @Override public PsiType visitType(@NotNull PsiType type) { if (!(type instanceof PsiPrimitiveType) && PsiTypesUtil.isDenotableType(type, position) && myProcessed.add(type)) { int priority = type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) ? 1 : 1000 - myProcessed.size(); consumer.consume(PrioritizedLookupElement.withPriority(PsiTypeLookupItem.createLookupItem(type, position), priority)); } return type; } }; for (PsiType type : getReturnTypeCandidates(method)) { eachProcessor.visitType(type); ExpectedTypesProvider.processAllSuperTypes(type, eachProcessor, position.getProject(), new HashSet<>(), new HashSet<>()); } }