PsiFile (final Project project, final @NotNull PsiFile psiFile) { final String text = psiFile.getText(); final PsiDocumentManager manager = PsiDocumentManager.getInstance(project); final Document doc = manager.getDocument(psiFile); CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> { if (doc != null) { doc.replaceString(0, doc.getTextLength(), text); manager.commitDocument(doc); } try { super.doReformat(project, psiFile); } catch (IncorrectOperationException e) { LOG.error(e); } }), "", ""); if (doc != null) { manager.commitDocument(doc); } return psiFile; }