}
private void formatWhenEditorIsClosed(PsiFile psiFile) throws FileDoesNotExistsException {
LOG.debug("#formatWhenEditorIsClosed " + psiFile.getName());
VirtualFile virtualFile = psiFile.getVirtualFile();
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(virtualFile);
fileDocumentManager.saveDocument(document); // when file is edited and editor is closed, it is needed to save
// the text
String text = document.getText();
String reformat = reformat(0, text.length(), text);
document.setText(reformat);
postProcess(document, psiFile, new Range(-1, -1, true));
fileDocumentManager.saveDocument(document);
}