@Override
  public Document getDocument(@NotNull PsiFile file) {
    Document document = getCachedDocument(file);
    if (document != null) {
      if (!file.getViewProvider().isPhysical()) {
        PsiUtilCore.ensureValid(file);
        associatePsi(document, file);
      }
      return document;
    }

    FileViewProvider viewProvider = file.getViewProvider();
    if (!viewProvider.isEventSystemEnabled()) {
      return null;
    }

    VirtualFile virtualFile = viewProvider.getVirtualFile();
    document = FileDocumentManager.getInstance().getDocument(virtualFile, myProject);
    if (document != null) {
      if (document.getTextLength() != file.getTextLength()) {
        // We have internal state inconsistency, it might be a good idea to contact the core team if you are able to reproduce this error.
        String message = "Document/PSI mismatch: " + file + " of " + file.getClass() +
                         "; viewProvider=" + viewProvider +
                         "; uncommitted=" + Arrays.toString(getUncommittedDocuments());
        String documentText = document.getText();
        String fileText;
        try {
          fileText = file.getText();
        }
        catch (AssertionError e) {
          fileText = "file.getText() failed with an error: " + e;
        }
        throw new RuntimeExceptionWithAttachments(message,
                                                  new Attachment("document.txt", documentText),
                                                  new Attachment("psi.txt", fileText));
      }

      if (!viewProvider.isPhysical()) {
        PsiUtilCore.ensureValid(file);
        associatePsi(document, file);
        file.putUserData(HARD_REF_TO_DOCUMENT, document);
      }
    }

    return document;
  }
@Override
  public Document getDocument(@NotNull PsiFile file)