public FormattingDocumentModelImpl(@NotNull final Document document, PsiFile file) {
   myDocument = document;
   myFile = file;
   if (file != null) {
     Language language = file.getLanguage();
     myWhiteSpaceStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy(language);
   } else {
     myWhiteSpaceStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy();
   }
   mySettings = CodeStyleSettingsManager.getSettings(file != null ? file.getProject() : null);
 }
  private static void addWhiteSpace(final ASTNode treePrev, final LeafElement whiteSpaceElement) {
    for (WhiteSpaceFormattingStrategy strategy :
        WhiteSpaceFormattingStrategyFactory.getAllStrategies()) {
      if (strategy.addWhitespace(treePrev, whiteSpaceElement)) {
        return;
      }
    }

    final ASTNode treeParent = treePrev.getTreeParent();
    treeParent.addChild(whiteSpaceElement, treePrev);
  }
  private static boolean spacesOnly(@Nullable TreeElement node) {
    if (node == null) return false;

    if (isWhitespaceOrEmpty(node)) return true;
    PsiElement psi = node.getPsi();
    if (psi == null) {
      return false;
    }
    Language language = psi.getLanguage();
    return WhiteSpaceFormattingStrategyFactory.getStrategy(language).containsWhitespacesOnly(node);
  }
 @Override
 public boolean containsWhiteSpaceSymbolsOnly(int startOffset, int endOffset) {
   WhiteSpaceFormattingStrategy strategy = myWhiteSpaceStrategy;
   if (strategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset) {
     return true;
   }
   PsiElement injectedElement =
       myFile != null ? InjectedLanguageUtil.findElementAtNoCommit(myFile, startOffset) : null;
   if (injectedElement != null) {
     Language injectedLanguage = injectedElement.getLanguage();
     if (!injectedLanguage.equals(myFile.getLanguage())) {
       WhiteSpaceFormattingStrategy localStrategy =
           WhiteSpaceFormattingStrategyFactory.getStrategy(injectedLanguage);
       if (localStrategy != null) {
         return localStrategy.check(myDocument.getCharsSequence(), startOffset, endOffset)
             >= endOffset;
       }
     }
   }
   return false;
 }