private @Nullable String replaceWithPSI(final TextRange textRange, final String whiteSpace) {
    final int offset = textRange.getEndOffset();
    ASTNode leafElement = findElementAt(offset);

    if (leafElement != null) {
      PsiFile hostFile = myASTNode.getPsi().getContainingFile();
      TextRange effectiveRange = textRange;
      List<DocumentWindow> injections =
        InjectedLanguageManager.getInstance(hostFile.getProject()).getCachedInjectedDocumentsInRange(hostFile, TextRange.from(offset, 0));
      if (!injections.isEmpty()) {
        PsiElement injectedElement = PsiDocumentManager.getInstance(myProject).getPsiFile(injections.get(0));
        PsiLanguageInjectionHost host = InjectedLanguageUtilBase.findInjectionHost(injectedElement);
        TextRange corrected = host == null ? null : correctRangeByInjection(textRange, host);
        if (corrected != null) {
          effectiveRange = corrected;
        }
      }

      if (leafElement.getPsi() instanceof PsiFile) {
        return null;
      } else {
        LOG.assertTrue(leafElement.getPsi().isValid());
        return replaceWithPsiInLeaf(effectiveRange, whiteSpace, leafElement);
      }
    }
    else if (textRange.getEndOffset() == myASTNode.getTextLength()){
      CodeStyleManager.getInstance(myProject).performActionWithFormatterDisabled(
        (Runnable)() -> FormatterUtil.replaceLastWhiteSpace(myASTNode, whiteSpace, textRange)
      );
      return whiteSpace;
    }
    else {
      return null;
    }
  }
private @Nullable String replaceWithPSI(final TextRange textRange, final String whiteSpace)