protected void doEnter(@NotNull PsiElement atCaret, @NotNull PsiFile psiFile, @NotNull Editor editor, boolean afterCompletion)
    throws IncorrectOperationException {
    if (myFirstErrorOffset != Integer.MAX_VALUE) {
      editor.getCaretModel().moveToOffset(myFirstErrorOffset);
      reformat(atCaret);
      return;
    }

    final RangeMarker rangeMarker = createRangeMarker(atCaret);

    if (reformatBeforeEnter(atCaret)) {
      reformat(atCaret);
    }
    commit(editor);
    PsiElement actualAtCaret = restoreElementAtCaret(psiFile, atCaret, rangeMarker);
    int endOffset = rangeMarker.getEndOffset();

    rangeMarker.dispose();

    if (actualAtCaret != null) {
      for (FixEnterProcessor enterProcessor : myEnterProcessors) {
        if (enterProcessor.doEnter(actualAtCaret, psiFile, editor, isModified(editor))) {
          return;
        }
      }
    }

    if (!isModified(editor) && !afterCompletion) {
      if (actualAtCaret != null) {
        plainEnter(editor);
      }
    }
    else {
      editor.getCaretModel().moveToOffset(myFirstErrorOffset == Integer.MAX_VALUE
                                          ? (actualAtCaret != null
                                             ? actualAtCaret.getTextRange().getEndOffset()
                                             : endOffset)
                                          : myFirstErrorOffset);
    }
  }
protected void doEnter(@NotNull PsiElement atCaret, @NotNull PsiFile psiFile, @NotNull Editor editor, boolean afterCompletion)