PatchHunk (@NotNull String content, boolean isInsertion, boolean isWithEmptyFile) { PatchLine.Type type = isInsertion ? PatchLine.Type.ADD : PatchLine.Type.REMOVE; List<String> lines = tokenize(content); boolean noNewlineAtEOF = !content.endsWith("\n"); int contentStart = 0; int contentEnd = lines.size(); int emptyStart = isWithEmptyFile ? 0 : -1; int emptyEnd = isWithEmptyFile ? 0 : -1; PatchHunk hunk = new PatchHunk(isInsertion ? emptyStart : contentStart, isInsertion ? emptyEnd : contentEnd, isInsertion ? contentStart : emptyStart, isInsertion ? contentEnd : emptyEnd); for (int i = 0; i < lines.size(); i++) { addLineToHunk(hunk, lines, type, i, noNewlineAtEOF); } return hunk; }