private static @Nullable PsiFile getPsiFile(@Nullable Project project, @NotNull Document document) {
    if (project != null) {
      PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
      if (documentManager.isCommitted(document)) {
        return documentManager.getCachedPsiFile(document);
      }
    }
    else {
      VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
      LOG.warn(
        "No current project is given, trailing spaces will be stripped later (postponed). File: " +
        (virtualFile != null ? virtualFile.getCanonicalPath() : "undefined"));
    }
    return null;
  }
private static @Nullable PsiFile getPsiFile(@Nullable Project project, @NotNull Document document)