private static int fillGap(@Nullable Block parent,
                             List<? extends TextRange> originalRanges,
                             List<? extends Block> blocks,
                             List<? super Block> result,
                             int startOffset,
                             int endOffset,
                             int depth) throws
                                        FragmentedTemplateException {
    int lastOffset = startOffset;
    TextRange currRange = new TextRange(lastOffset, endOffset);
    for (Block block : blocks) {
      if (lastOffset == endOffset || block.getTextRange().getStartOffset() > endOffset) return lastOffset;
      if (currRange.contains(block.getTextRange())) {
        result.add(block);
        if (parent != null && block instanceof IndentInheritingBlock) {
          ((IndentInheritingBlock)block).setIndent(parent.getIndent());
        }
        lastOffset = block.getTextRange().getEndOffset();
        currRange = new TextRange(lastOffset, endOffset);
      }
      else if (currRange.intersects(block.getTextRange()) && TextRangeUtil.intersectsOneOf(block.getTextRange(), originalRanges)) {
        List<Block> subBlocks = block.getSubBlocks();
        if (block instanceof TemplateLanguageBlock && ((TemplateLanguageBlock)block).containsErrorElements()) {
          throw new FragmentedTemplateException();
        }
        lastOffset = fillGap(block, originalRanges, subBlocks, result, lastOffset, endOffset, depth + 1);
        currRange = new TextRange(lastOffset, endOffset);
      }
    }
    return lastOffset;
  }
private static int fillGap(@Nullable Block parent,
                             List<? extends TextRange> originalRanges,
                             List<? extends Block> blocks,
                             List<? super Block> result,
                             int startOffset,
                             int endOffset,
                             int depth)