void (@NotNull InsertionContext context, @NotNull LookupElement item) { if (!(item.getObject() instanceof PsiMethod method)) { return; } PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument()); final Editor editor = context.getEditor(); final PsiParameter[] parameters = method.getParameterList().getParameters(); final StringBuilder buffer = new StringBuilder(); final CharSequence chars = editor.getDocument().getCharsSequence(); int endOffset = editor.getCaretModel().getOffset(); final Project project = context.getProject(); int afterSharp = CharArrayUtil.shiftBackwardUntil(chars, endOffset - 1, "#") + 1; int signatureOffset = afterSharp; PsiElement element = context.getFile().findElementAt(signatureOffset - 1); final CommonCodeStyleSettings styleSettings = CodeStyle.getLanguageSettings(context.getFile(), GroovyLanguage.INSTANCE); PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class); if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) { final PsiDocTagValue value = tag.getValueElement(); endOffset = value.getTextRange().getEndOffset(); } editor.getDocument().deleteString(afterSharp, endOffset); editor.getCaretModel().moveToOffset(signatureOffset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); buffer.append(method.getName()).append("("); final int afterParenth = afterSharp + buffer.length(); for (int i = 0; i < parameters.length; i++) { final PsiType type = TypeConversionUtil.erasure(parameters[i].getType()); buffer.append(type.getCanonicalText()); if (i < parameters.length - 1) { buffer.append(","); if (styleSettings.SPACE_AFTER_COMMA) buffer.append(" "); } } buffer.append(")"); if (!(tag instanceof PsiInlineDocTag)) { buffer.append(" "); } else { final int currentOffset = editor.getCaretModel().getOffset(); if (chars.charAt(currentOffset) == '}') { afterSharp++; } else { buffer.append("} "); }