@Override
  public Result preprocessEnter(@NotNull final PsiFile file,
                                @NotNull final Editor editor,
                                @NotNull final Ref<Integer> caretOffsetRef,
                                final @NotNull Ref<Integer> caretAdvance,
                                @NotNull final DataContext dataContext,
                                final EditorActionHandler originalHandler) {
    CodeDocumentationAwareCommenter commenter = EnterInCommentUtil.getDocumentationAwareCommenter(dataContext);
    if (commenter == null) return Result.Continue;

    int caretOffset = caretOffsetRef.get();
    int blockCommentStartOffset = getBlockCommentStartOffset(editor, caretOffset, commenter);
    if (blockCommentStartOffset < 0) return Result.Continue;

    Document document = editor.getDocument();
    CharSequence text = document.getImmutableCharSequence();

    String docCommentPrefix = commenter.getDocumentationCommentPrefix();
    if (docCommentPrefix != null && StringUtil.startsWith(text.subSequence(blockCommentStartOffset, caretOffset), docCommentPrefix)) {
      return Result.Continue;
    }

    int beforeWhitespace = CharArrayUtil.shiftBackward(text, blockCommentStartOffset - 1, WHITESPACE);
    if (beforeWhitespace > 0 && text.charAt(beforeWhitespace) != '\n') return Result.Continue;

    PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
    PsiElement element = file.findElementAt(blockCommentStartOffset);
    if (!(element instanceof PsiComment) ||
        ((PsiComment)element).getTokenType() != commenter.getBlockCommentTokenType()) {
      return Result.Continue;
    }
    if (!EnterHandler.isCommentComplete((PsiComment)element, commenter, editor) && CodeInsightSettings.getInstance().CLOSE_COMMENT_ON_ENTER) {
      int currentEndOfLine = CharArrayUtil.shiftForwardUntil(text, caretOffset, "\n");
      document.insertString(currentEndOfLine,
                            "\n" +
                            text.subSequence(beforeWhitespace + 1, blockCommentStartOffset) + " " + commenter.getBlockCommentSuffix());
      return Result.Default;
    }

    int additionalIndent = 0;
    if (TodoConfiguration.getInstance().isMultiLine()) {
      int lineStartOffset = DocumentUtil.getLineStartOffset(caretOffset, document);
      int todoOffset = EnterInCommentUtil.getTodoTextOffset(text, lineStartOffset, caretOffset);
      if (todoOffset >= 0) {
        int lineEndOffset = DocumentUtil.getLineEndOffset(caretOffset, document);
        if (todoOffset == EnterInCommentUtil.getTodoTextOffset(text, lineStartOffset, lineEndOffset)) {
          int nonWsLineStart = CharArrayUtil.shiftForward(text, lineStartOffset, WHITESPACE);
          if (todoOffset >= nonWsLineStart) {
            additionalIndent = todoOffset - nonWsLineStart + 1;
            document.insertString(caretOffset, StringUtil.repeat(" ", additionalIndent));
          }
        }
      }
    }

    String linePrefix = commenter.getDocumentationCommentLinePrefix();
    if (linePrefix == null) return Result.Continue;

    int refOffset = document.getLineNumber(caretOffset) > document.getLineNumber(blockCommentStartOffset)
                    ? document.getLineStartOffset(document.getLineNumber(blockCommentStartOffset) + 1) : caretOffset;
    if (StringUtil.startsWith(text, CharArrayUtil.shiftForward(text, refOffset, WHITESPACE), linePrefix)) {
      int endOffset = CharArrayUtil.shiftForward(text, caretOffset, WHITESPACE);
      if (endOffset < text.length() && text.charAt(endOffset) != '\n') endOffset = caretOffset;
      int valueLength = linePrefix.length() + 1;
      int endOffsetToReplace = endOffset > caretOffset ? endOffset : caretOffset + Math.min(additionalIndent, valueLength);
      document.replaceString(caretOffset, endOffsetToReplace, linePrefix + " ");
      caretAdvance.set(Math.max(valueLength, additionalIndent));
      return Result.DefaultForceIndent;
    }
    return Result.Continue;
  }
@Override
  public Result preprocessEnter(@NotNull final PsiFile file,
                                @NotNull final Editor editor,
                                @NotNull final Ref<Integer> caretOffsetRef,
                                final @NotNull Ref<Integer> caretAdvance,
                                @NotNull final DataContext dataContext,
                                final EditorActionHandler originalHandler)