void (@NotNull InsertionContext context) { context.commitDocument(); PsiReferenceParameterList list = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiReferenceParameterList.class, false); PsiTypeElement[] typeElements = list != null ? list.getTypeParameterElements() : PsiTypeElement.EMPTY_ARRAY; if (typeElements.length == 0) { return; } int listEnd = typeElements[typeElements.length - 1].getTextRange().getEndOffset(); context.setTailOffset(listEnd); context.getDocument().deleteString(context.getStartOffset(), listEnd); for (int i = 0; i < myTypeItems.size(); i++) { PsiTypeLookupItem typeItem = myTypeItems.get(i); CompletionUtil.emulateInsertion(context, context.getTailOffset(), typeItem); if (context.getTailOffset() < 0) { LOG.error("tail offset spoiled by " + typeItem); return; } context.setTailOffset(getTail(i == myTypeItems.size() - 1).processTail(context.getEditor(), context.getTailOffset())); } context.setAddCompletionChar(false); context.commitDocument(); PsiElement leaf = context.getFile().findElementAt(context.getTailOffset() - 1); if (psiElement().withParents(PsiReferenceParameterList.class, PsiJavaCodeReferenceElement.class, PsiNewExpression.class) .accepts(leaf)) { ParenthesesInsertHandler.getInstance(myHasParameters).handleInsert(context, this); myGlobalTail.processTail(context.getEditor(), context.getTailOffset()); } }