void (@NotNull CompletionParameters parameters, @NotNull CompletionResultSet _result) { PsiElement position = parameters.getPosition(); if (!isInJavaContext(position)) { return; } if (AFTER_NUMBER_LITERAL.accepts(position) || UNEXPECTED_REFERENCE_AFTER_DOT.accepts(position) || AFTER_ENUM_CONSTANT.accepts(position)) { _result.stopHere(); return; } boolean smart = parameters.getCompletionType() == CompletionType.SMART; CompletionResultSet result = JavaCompletionSorting.addJavaSorting(parameters, _result); JavaCompletionSession session = new JavaCompletionSession(result); PrefixMatcher matcher = result.getPrefixMatcher(); PsiElement parent = position.getParent(); if (new JavaKeywordCompletion(parameters, session, smart).addWildcardExtendsSuper(result, position)) { result.stopHere(); return; } boolean mayCompleteReference = true; if (position instanceof PsiIdentifier) { addIdentifierVariants(parameters, position, result, session, matcher); Set<ExpectedTypeInfo> expectedInfos = ContainerUtil.newHashSet(JavaSmartCompletionContributor.getExpectedTypes(parameters)); boolean shouldAddExpressionVariants = shouldAddExpressionVariants(parameters); boolean hasTypeMatchingSuggestions = shouldAddExpressionVariants && addExpectedTypeMembers(parameters, false, expectedInfos, item -> session.registerBatchItems(Collections.singleton(item))); if (!smart) { PsiAnnotation anno = findAnnotationWhoseAttributeIsCompleted(position); if (anno != null) { PsiClass annoClass = anno.resolveAnnotationType(); mayCompleteReference = mayCompleteValueExpression(position, annoClass); if (annoClass != null) { completeAnnotationAttributeName(result, position, anno, annoClass); JavaKeywordCompletion.addPrimitiveTypes(result, position, session); } } } PsiReference ref = position.getContainingFile().findReferenceAt(parameters.getOffset()); if (ref instanceof PsiLabelReference) { session.registerBatchItems(processLabelReference((PsiLabelReference)ref)); result.stopHere(); } List<LookupElement> refSuggestions = Collections.emptyList(); if (parent instanceof PsiJavaCodeReferenceElement parentRef && mayCompleteReference) { if (IN_PERMITS_LIST.accepts(parent) && parameters.getInvocationCount() <= 1 && !parentRef.isQualified()) { refSuggestions = completePermitsListReference(parameters, parentRef, matcher); } else { if (parameters.getInvocationCount() >= 2 && Registry.is("java.completion.methods.use.tags")) { MethodTags.TagMatcher tagMatcher = new MethodTags.TagMatcher(matcher); List<LookupElement> proposedElements = completeReference(parameters, parentRef, session, expectedInfos, tagMatcher::prefixMatches); refSuggestions = ContainerUtil.map(proposedElements, element -> { LookupElement withTags = MethodTags.wrapLookupWithTags(element, matcher::prefixMatches, matcher.getPrefix(), parameters.getCompletionType()); return withTags != null ? withTags : element; }); } else { refSuggestions = completeReference(parameters, parentRef, session, expectedInfos, matcher::prefixMatches); } } List<LookupElement> filtered = filterReferenceSuggestions(parameters, expectedInfos, refSuggestions); hasTypeMatchingSuggestions |= ContainerUtil.exists(filtered, item -> ReferenceExpressionCompletionContributor.matchesExpectedType(item, expectedInfos)); session.registerBatchItems(filtered); result.stopHere(); } session.flushBatchItems(); if (smart) { hasTypeMatchingSuggestions |= smartCompleteExpression(parameters, result, expectedInfos); smartCompleteNonExpression(parameters, result); } else { if (!JavaKeywordCompletion.AFTER_DOT.accepts(position)) { for (ExpectedTypeInfo info : expectedInfos) { ClassLiteralGetter.addCompletions(new JavaSmartCompletionParameters(parameters, info), result, matcher); } } } if ((!hasTypeMatchingSuggestions || parameters.getInvocationCount() >= 2) && parent instanceof PsiJavaCodeReferenceElement && !expectedInfos.isEmpty() && JavaSmartCompletionContributor.INSIDE_EXPRESSION.accepts(position)) { List<LookupElement> base = ContainerUtil.concat( refSuggestions, completeReference(parameters, (PsiJavaCodeReferenceElement)parent, session, expectedInfos, s -> !matcher.prefixMatches(s))); SlowerTypeConversions.addChainedSuggestions(parameters, result, expectedInfos, base); } if (smart && parameters.getInvocationCount() > 1 && shouldAddExpressionVariants) { addExpectedTypeMembers(parameters, true, expectedInfos, result); } } if (!smart && psiElement().inside(PsiLiteralExpression.class).accepts(position)) { Set<String> usedWords = new HashSet<>(); result.runRemainingContributors(parameters, cr -> { usedWords.add(cr.getLookupElement().getLookupString()); result.passResult(cr); }); PsiReference reference = position.getContainingFile().findReferenceAt(parameters.getOffset()); if (reference == null || reference.isSoft()) { WordCompletionContributor.addWordCompletionVariants(result, parameters, usedWords); } } if (!smart && position instanceof PsiIdentifier) { JavaGenerateMemberCompletionContributor.fillCompletionVariants(parameters, result); } if (!smart && mayCompleteReference) { addAllClasses(parameters, result, session); } if (position instanceof PsiIdentifier) { FunctionalExpressionCompletionProvider.addFunctionalVariants(parameters, true, result.getPrefixMatcher(), result); } if (position instanceof PsiIdentifier && !smart && parent instanceof PsiReferenceExpression && !((PsiReferenceExpression)parent).isQualified() && parameters.isExtendedCompletion() && StringUtil.isNotEmpty(matcher.getPrefix())) { new JavaStaticMemberProcessor(parameters).processStaticMethodsGlobally(matcher, result); } if (!smart && parent instanceof PsiJavaModuleReferenceElement) { addModuleReferences(parent, parameters.getOriginalFile(), result); } }