List<SplitHunk> (final PatchHunk hunk) { final List<SplitHunk> result = new ArrayList<>(); final List<PatchLine> lines = hunk.getLines(); int i = 0; List<String> contextBefore = new ArrayList<>(); int newSize = 0; int oldSize = 0; while (i < lines.size()) { final int inheritedContext = contextBefore.size(); final List<String> contextAfter = new ArrayList<>(); final List<BeforeAfter<List<String>>> steps = new ArrayList<>(); final int endIdx = readOne(lines, contextBefore, contextAfter, steps, i); int startLineBefore = hunk.getStartLineBefore(); int startLineAfter = hunk.getStartLineAfter(); if (steps.isEmpty()) { // skip empty chunk, but warn LOG.warn(constructHunkWarnMessage(startLineBefore, startLineAfter, hunk.getEndLineBefore() - startLineBefore, hunk.getEndLineAfter() - startLineAfter)); LOG.debug("Wrong chunk text: " + hunk.getText()); } else { result.add(new SplitHunk(startLineBefore + i - inheritedContext - newSize, startLineAfter + i - inheritedContext - oldSize, steps, contextAfter, contextBefore)); } for (BeforeAfter<List<String>> step : steps) { newSize += step.getAfter().size(); oldSize += step.getBefore().size(); } i = endIdx; if (i < lines.size()) { contextBefore = new ArrayList<>(contextAfter); } } return result; }