void (@NotNull Editor editor, @NotNull PsiFile file, char completionChar, Environment env) { int caretOffset = editor.getCaretModel().getOffset(); PsiElement leaf = file.findElementAt(TargetElementUtil.adjustOffset(file, getDocument(), caretOffset)); PsiReference ref = TargetElementUtil.findReference(editor); String expectedVariant = leaf == null || leaf instanceof PsiPlainText ? null : myPolicy.getExpectedVariant(editor, file, leaf, ref); boolean prefixEqualsExpected = isPrefixEqualToExpectedVariant(caretOffset, leaf, ref, expectedVariant); boolean shouldCheckDuplicates = myPolicy.shouldCheckDuplicates(editor, file, file.findElementAt(caretOffset)); long stampBefore = getDocument().getModificationStamp(); new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor); String notFound = ". Please either fix completion so that the variant is suggested, " + "or, if absolutely needed, tweak CompletionPolicy to exclude it."; LookupEx lookup = LookupManager.getActiveLookup(editor); if (lookup == null) { if (editor.getCaretModel().getOffset() != caretOffset || getDocument().getModificationStamp() != stampBefore) { env.logMessage("Completion item was auto-inserted"); return; } env.logMessage("No lookup"); if (expectedVariant == null || prefixEqualsExpected || !checkHighlightingErrorsAtCaret(editor, env, expectedVariant)) { return; } TestCase.fail("No lookup, but expected '" + expectedVariant + "' among completion variants" + notFound); } List<LookupElement> items = lookup.getItems(); if (expectedVariant != null) { LookupElement sameItem = ContainerUtil.find(items, e -> e.getAllLookupStrings().stream().anyMatch( s -> Comparing.equal(s, expectedVariant, e.isCaseSensitive()))); if (sameItem == null && !checkHighlightingErrorsAtCaret(editor, env, expectedVariant)) { return; } TestCase.assertNotNull("No variant '" + expectedVariant + "' among " + items + notFound, sameItem); } if (shouldCheckDuplicates) { checkNoDuplicates(items); } LookupElement item = env.generateValue(Generator.sampledFrom(items), null); env.logMessage("Select '" + item + "' with '" + StringUtil.escapeStringCharacters(String.valueOf(completionChar)) + "'"); lookup.setCurrentItem(item); if (LookupEvent.isSpecialCompletionChar(completionChar)) { ((LookupImpl)lookup).finishLookup(completionChar, item); } else { EditorActionManager.getInstance(); TypedAction.getInstance().actionPerformed(editor, completionChar, EditorUtil.getEditorDataContext(lookup.getTopLevelEditor())); } }