SplitHunk (final SplitHunk hunk) { final SplitHunk copy = copySplitHunk(hunk, new ArrayList<>(), new ArrayList<>()); final List<BeforeAfter<List<String>>> steps = copy.getPatchSteps(); if (steps.isEmpty()) { int contextSize = hunk.getContextBefore().size() + hunk.getContextAfter().size(); LOG.warn(constructHunkWarnMessage(hunk.getStartLineBefore(), hunk.getStartLineAfter(), contextSize, contextSize)); StringBuilder sb = new StringBuilder(); StringUtil.join(hunk.getContextBefore(), "\n", sb); StringUtil.join(hunk.getContextAfter(), "\n", sb); LOG.debug(sb.toString()); return copy; } final BeforeAfter<List<String>> first = steps.get(0); final int lastStepIndex = steps.size() - 1; final BeforeAfter<List<String>> last = steps.get(lastStepIndex); final BeforeAfter<List<String>> firstCopy = copyBeforeAfter(first); steps.set(0, firstCopy); firstCopy.getBefore().addAll(0, hunk.getContextBefore()); firstCopy.getAfter().addAll(0, hunk.getContextBefore()); if (first == last) { firstCopy.getBefore().addAll(hunk.getContextAfter()); firstCopy.getAfter().addAll(hunk.getContextAfter()); } else { final BeforeAfter<List<String>> lastCopy = copyBeforeAfter(last); lastCopy.getBefore().addAll(hunk.getContextAfter()); lastCopy.getAfter().addAll(hunk.getContextAfter()); steps.set(lastStepIndex, lastCopy); } return copy; }