private static void validateModel(FormattingModel model) throws FormattingModelInconsistencyException {
    FormattingDocumentModel documentModel = model.getDocumentModel();
    Document document = documentModel.getDocument();
    Block rootBlock = model.getRootBlock();
    if (rootBlock instanceof ASTBlock) {
      PsiElement rootElement = ((ASTBlock)rootBlock).getNode().getPsi();
      if (!rootElement.isValid()) {
        throw new FormattingModelInconsistencyException("Invalid root block PSI element");
      }
      PsiFile file = rootElement.getContainingFile();
      Project project = file.getProject();
      PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
      if (documentManager.isUncommited(document)) {
        throw new FormattingModelInconsistencyException("Uncommitted document");
      }
      if (document.getTextLength() != file.getTextLength()) {
        throw new FormattingModelInconsistencyException(
          "Document length " + document.getTextLength() +
          " doesn't match PSI file length " + file.getTextLength() + ", language: " + file.getLanguage()
        );
      }
    }
  }
private static void validateModel(FormattingModel model)