MembersToImport<T> () { final List<Pair<T, ApplicableType>> list = new ArrayList<>(); final List<T> applicableList = new ArrayList<>(); for (Map.Entry<PsiClass, Collection<T>> methodEntry : mySuggestions.entrySet()) { registerMember(methodEntry.getKey(), methodEntry.getValue(), list, applicableList); } Comparator<T> comparator = CodeInsightUtil.createSortIdenticalNamedMembersComparator(myPlace); if (applicableList.isEmpty()) { list.sort(Comparator.<Pair<T, ApplicableType>, ApplicableType>comparing(t -> t.getSecond(), Comparator.naturalOrder()) .reversed() .thenComparing(t -> t.getFirst(), comparator)); } else { applicableList.sort(comparator); applicableList.addAll(list.stream() .filter(t -> t.getSecond() == ApplicableType.PARTLY) .map(t -> t.getFirst()) .sorted(comparator) .toList()); } return new MembersToImport<>(applicableList, ContainerUtil.map(list, t -> t.getFirst())); }