TextRange (@Nullable List<? extends @NotNull TextRange> reduced, @NotNull TextRange fileRange) { if (reduced == null) return fileRange; if (reduced.size() == 1) { return reduced.get(0); } int startOffSet = fileRange.getEndOffset(); int endOffSet = fileRange.getStartOffset(); for (TextRange range : reduced) { startOffSet = Math.min(startOffSet, range.getStartOffset()); endOffSet = Math.max(endOffSet, range.getEndOffset()); } return TextRange.create(startOffSet, endOffSet); }