Search in sources :

Example 1 with NOT_APPLIED

use of com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.HunkStatus.NOT_APPLIED in project intellij-community by JetBrains.

the class AppliedTextPatch method create.

public static AppliedTextPatch create(@NotNull List<AppliedSplitPatchHunk> splitPatchHunkList) {
    List<AppliedSplitPatchHunk> hunks = new ArrayList<>(splitPatchHunkList);
    // ensure, that `appliedTo` ranges do not overlap
    BitSet appliedLines = new BitSet();
    for (int i = 0; i < hunks.size(); i++) {
        AppliedSplitPatchHunk hunk = hunks.get(i);
        LineRange appliedTo = hunk.getAppliedTo();
        if (appliedTo == null)
            continue;
        int nextAppliedLine = appliedLines.nextSetBit(appliedTo.start);
        if (nextAppliedLine != -1 && nextAppliedLine < appliedTo.end) {
            hunks.set(i, new AppliedSplitPatchHunk(hunk, -1, -1, NOT_APPLIED));
        } else {
            appliedLines.set(appliedTo.start, appliedTo.end, true);
        }
    }
    ContainerUtil.sort(hunks, Comparator.comparingInt(o -> o.getLineRangeBefore().start));
    return new AppliedTextPatch(hunks);
}
Also used : GenericPatchApplier(com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier) List(java.util.List) BeforeAfter(com.intellij.util.BeforeAfter) BitSet(java.util.BitSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) LineRange(com.intellij.diff.util.LineRange) NOT_APPLIED(com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.HunkStatus.NOT_APPLIED) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) LineRange(com.intellij.diff.util.LineRange)

Aggregations

LineRange (com.intellij.diff.util.LineRange)1 GenericPatchApplier (com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier)1 NOT_APPLIED (com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.HunkStatus.NOT_APPLIED)1 BeforeAfter (com.intellij.util.BeforeAfter)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Comparator (java.util.Comparator)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1