use of com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.AppliedSplitPatchHunk in project intellij-community by JetBrains.
the class PatchChangeBuilder method exec.
public void exec(@NotNull List<AppliedSplitPatchHunk> splitHunks) {
int lastBeforeLine = -1;
for (AppliedSplitPatchHunk hunk : splitHunks) {
List<String> contextBefore = hunk.getContextBefore();
List<String> contextAfter = hunk.getContextAfter();
LineRange beforeRange = hunk.getLineRangeBefore();
LineRange afterRange = hunk.getLineRangeAfter();
int overlappedContext = 0;
if (lastBeforeLine != -1) {
if (lastBeforeLine >= beforeRange.start) {
overlappedContext = lastBeforeLine - beforeRange.start + 1;
} else if (lastBeforeLine < beforeRange.start - 1) {
appendSeparator();
}
}
List<String> trimContext = contextBefore.subList(overlappedContext, contextBefore.size());
addContext(trimContext, beforeRange.start + overlappedContext, afterRange.start + overlappedContext);
int deletion = totalLines;
appendLines(hunk.getDeletedLines());
int insertion = totalLines;
appendLines(hunk.getInsertedLines());
int hunkEnd = totalLines;
myConvertor1.put(deletion, beforeRange.start + contextBefore.size(), insertion - deletion);
myConvertor2.put(insertion, afterRange.start + contextBefore.size(), hunkEnd - insertion);
addContext(contextAfter, beforeRange.end - contextAfter.size(), afterRange.end - contextAfter.size());
lastBeforeLine = beforeRange.end - 1;
LineRange deletionRange = new LineRange(deletion, insertion);
LineRange insertionRange = new LineRange(insertion, hunkEnd);
myHunks.add(new Hunk(hunk.getInsertedLines(), deletionRange, insertionRange, hunk.getAppliedTo(), hunk.getStatus()));
}
}
Aggregations