CompletionResultSet (final CompletionParameters parameters, CompletionResultSet result) { PsiElement position = parameters.getPosition(); ExpectedTypeInfo[] expectedTypes = getExpectedTypesWithDfa(parameters, position); CompletionType type = parameters.getCompletionType(); boolean smart = type == CompletionType.SMART; boolean afterNew = JavaSmartCompletionContributor.AFTER_NEW.accepts(position); Project project = parameters.getOriginalFile().getProject(); List<LookupElementWeigher> afterProximity = new ArrayList<>(); ContainerUtil.addIfNotNull(afterProximity, PreferMostUsedWeigher.create(position)); afterProximity.add(new PreferContainingSameWords(project, expectedTypes)); afterProximity.add(new PreferShorter(project, expectedTypes)); afterProximity.add(new DispreferTechnicalOverloads(position)); CompletionSorter sorter = CompletionSorter.defaultSorter(parameters, result.getPrefixMatcher()); if (!smart && afterNew) { sorter = sorter.weighBefore("liftShorter", new PreferExpected(true, expectedTypes, position)); } else if (PsiTreeUtil.getParentOfType(position, PsiReferenceList.class) == null) { sorter = ((CompletionSorterImpl)sorter).withClassifier("liftShorterClasses", true, new LiftShorterClasses(position)); } PsiClassType serviceType = getServiceType(position); if (serviceType != null) { sorter = sorter.weighBefore("liftShorter", new PreferImplementor(serviceType)); } PsiElement parent = position.getParent(); if (parent instanceof PsiReferenceExpression && !(parent instanceof PsiMethodReferenceExpression)) { PsiExpression context = (PsiReferenceExpression)parent; if (context.getParent() instanceof PsiMethodCallExpression) { context = (PsiExpression)context.getParent(); } if (!ExpressionUtils.isVoidContext(context)) { sorter = sorter.weighBefore("middleMatching", new PreferNonVoid()); } } List<LookupElementWeigher> afterPriority = new ArrayList<>(); ContainerUtil.addIfNotNull(afterPriority, dispreferPreviousChainCalls(position)); if (smart) { afterPriority.add(new PreferDefaultTypeWeigher(expectedTypes, parameters, false)); } sorter = sorter.weighAfter("priority", afterPriority.toArray(new LookupElementWeigher[0])); List<LookupElementWeigher> afterStats = new ArrayList<>(); afterStats.add(new PreferByKindWeigher(type, position, expectedTypes)); if (smart) { afterStats.add(new PreferDefaultTypeWeigher(expectedTypes, parameters, true)); } else { if (!afterNew) { PsiExpression instanceOfOperand = JavaCompletionUtil.getInstanceOfOperand(position); PsiType instanceOfOperandType = instanceOfOperand == null ? null : instanceOfOperand.getType(); if (instanceOfOperandType != null) { afterStats.add(new PreferConvertible(instanceOfOperandType)); } else { afterStats.add(new PreferExpected(false, expectedTypes, position)); } } ContainerUtil.addIfNotNull(afterStats, preferStatics(position, expectedTypes)); } ContainerUtil.addIfNotNull(afterStats, recursion(parameters, expectedTypes)); afterStats.add(new PreferSimilarlyEnding(project, expectedTypes)); if (ContainerUtil.or(expectedTypes, info -> !info.getType().equals(PsiTypes.voidType()))) { afterStats.add(new PreferNonGeneric()); } afterStats.add(new PreferSimple()); sorter = sorter.weighAfter("stats", afterStats.toArray(new LookupElementWeigher[0])); sorter = sorter.weighAfter("proximity", afterProximity.toArray(new LookupElementWeigher[0])); return result.withRelevanceSorter(sorter); }