LookupElementBuilder (@NotNull PsiMethod annoMethod, @Nullable String value, @NotNull PsiElement position) { CommonCodeStyleSettings styleSettings = CodeStyle.getLanguageSettings(annoMethod.getContainingFile()); String space = ReferenceExpressionCompletionContributor.getSpace(styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS); String lookupString = annoMethod.getName() + (value == null ? "" : space + "=" + space + value); return LookupElementBuilder.create(annoMethod, lookupString).withIcon(annoMethod.getIcon(0)) .withStrikeoutness(JavaDeprecationUtils.isDeprecated(annoMethod, position)) .withInsertHandler((context, item) -> { Editor editor = context.getEditor(); if (value == null) { EqTailType.INSTANCE.processTail(editor, editor.getCaretModel().getOffset()); } context.setAddCompletionChar(false); context.commitDocument(); PsiAnnotationParameterList paramList = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiAnnotationParameterList.class, false); Document document = context.getDocument(); if (paramList != null && paramList.getAttributes().length > 0 && paramList.getAttributes()[0].getName() == null) { int valueOffset = paramList.getAttributes()[0].getTextRange().getStartOffset(); document.insertString(valueOffset, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME); EqTailType.INSTANCE.processTail(editor, valueOffset + PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.length()); } int offset = editor.getCaretModel().getOffset(); CharSequence sequence = document.getCharsSequence(); if (hasAttributeNameAt(sequence, offset)) { document.insertString(offset, styleSettings.SPACE_AFTER_COMMA ? ", " : ","); } }); }