private Document getDocumentBeforeChanges(@NotNull Project project, @NotNull PsiFile file) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    if (documentManager != null) {
      Document document = documentManager.getDocument(file);
      if (document != null) return document;
    }
    if (myDocumentBeforeChanges == null) {
      myDocumentBeforeChanges = new DocumentImpl(file.getText());
    }
    else {
      myDocumentBeforeChanges.replaceString(0, myDocumentBeforeChanges.getTextLength(), file.getText());
    }
    return myDocumentBeforeChanges;
  }
private Document getDocumentBeforeChanges(@NotNull Project project, @NotNull PsiFile file)