Search in sources :

Example 36 with DiffFragment

use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.

the class UniteSameType method covertSequentialOneSideToChange.

@NotNull
private static DiffFragment[] covertSequentialOneSideToChange(@NotNull DiffFragment[] fragments) {
    if (fragments.length < 2)
        return fragments;
    DiffCorrection.FragmentsCollector collector = new DiffCorrection.FragmentsCollector();
    //    DiffFragment previous = fragments[0];
    DiffFragment previous = null;
    for (int i = 0; i < fragments.length; i++) {
        DiffFragment fragment = fragments[i];
        if (fragment.isOneSide()) {
            if (previous == null)
                previous = fragment;
            else {
                FragmentSide side = FragmentSide.chooseSide(fragment);
                DiffString previousText = side.getText(previous);
                if (previousText == null)
                    previousText = DiffString.EMPTY;
                previous = side.createFragment(DiffString.concatenateNullable(previousText, side.getText(fragment)), side.getOtherText(previous), true);
            }
        } else {
            if (previous != null)
                collector.add(previous);
            previous = null;
            collector.add(fragment);
        }
    }
    if (previous != null)
        collector.add(previous);
    return collector.toArray();
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with DiffFragment

use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.

the class DiffFragmentBuilder method delete.

private void delete(@NotNull TextRange range, int line) {
    LOG.debug("DiffFragmentBuilder.delete(" + range + "," + line + ")");
    DiffString text1 = null;
    DiffString text2 = null;
    int start = range.getStartOffset();
    int end = range.getEndOffset();
    if (myLastLine1 < start) {
        text1 = concatenate(mySource1, myLastLine1, start - 1);
    }
    if (myLastLine2 <= line) {
        text2 = concatenate(mySource2, myLastLine2, line);
    }
    if (text1 != null || text2 != null) {
        myData.add(DiffFragment.unchanged(text1, text2));
    }
    myData.add(new DiffFragment(concatenate(mySource1, start, end), null));
    myLastLine1 = end + 1;
    myLastLine2 = line + 1;
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString)

Example 38 with DiffFragment

use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.

the class DiffFragmentBuilder method append.

private void append(int line, @NotNull TextRange range) {
    LOG.debug("DiffFragmentBuilder.append(" + line + "," + range + "), modified:");
    DiffString text1 = null;
    DiffString text2 = null;
    int start = range.getStartOffset();
    int end = range.getEndOffset();
    if (myLastLine1 <= line) {
        text1 = concatenate(mySource1, myLastLine1, line);
    }
    if (myLastLine2 < start) {
        text2 = concatenate(mySource2, myLastLine2, start - 1);
    }
    if (text1 != null || text2 != null) {
        myData.add(DiffFragment.unchanged(text1, text2));
    }
    myData.add(new DiffFragment(null, concatenate(mySource2, start, end)));
    myLastLine1 = line + 1;
    myLastLine2 = end + 1;
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString)

Example 39 with DiffFragment

use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.

the class MergeList method processText.

@NotNull
private static List<MergeFragment> processText(@NotNull String leftText, @NotNull String baseText, @NotNull String rightText, @NotNull ContextLogger logger) throws FilesTooBigForDiffException {
    DiffFragment[] leftFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(leftText));
    DiffFragment[] rightFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(rightText));
    int[] leftOffsets = { 0, 0 };
    int[] rightOffsets = { 0, 0 };
    int leftIndex = 0;
    int rightIndex = 0;
    MergeBuilder builder = new MergeBuilder(logger);
    while (leftIndex < leftFragments.length || rightIndex < rightFragments.length) {
        FragmentSide side;
        TextRange[] equalRanges = new TextRange[2];
        if (leftOffsets[0] < rightOffsets[0] && leftIndex < leftFragments.length) {
            side = FragmentSide.SIDE1;
            getEqualRanges(leftFragments[leftIndex], leftOffsets, equalRanges);
            leftIndex++;
        } else if (rightIndex < rightFragments.length) {
            side = FragmentSide.SIDE2;
            getEqualRanges(rightFragments[rightIndex], rightOffsets, equalRanges);
            rightIndex++;
        } else
            break;
        if (equalRanges[0] != null && equalRanges[1] != null)
            builder.add(equalRanges[0], equalRanges[1], side);
        else
            logger.assertTrue(equalRanges[0] == null && equalRanges[1] == null);
    }
    return builder.finish(leftText.length(), baseText.length(), rightText.length());
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with DiffFragment

use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.

the class Util method splitByLines.

@NotNull
static DiffFragment[] splitByLines(@NotNull DiffFragment fragment) {
    DiffString[] lines1 = splitByLines(fragment.getText1());
    DiffString[] lines2 = splitByLines(fragment.getText2());
    if (lines1 != null && lines2 != null && lines1.length != lines2.length) {
        LOG.error("1:<" + fragment.getText1() + "> 2:<" + fragment.getText2() + ">");
    }
    int length = lines1 == null ? lines2.length : lines1.length;
    DiffFragment[] lines = new DiffFragment[length];
    for (int i = 0; i < lines.length; i++) {
        lines[i] = new DiffFragment(lines1 == null ? null : lines1[i], lines2 == null ? null : lines2[i]);
    }
    return lines;
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffFragment (com.intellij.openapi.diff.ex.DiffFragment)55 DiffString (com.intellij.openapi.diff.impl.string.DiffString)15 NotNull (org.jetbrains.annotations.NotNull)13 FragmentSide (com.intellij.openapi.diff.impl.highlighting.FragmentSide)3 LineFragment (com.intellij.openapi.diff.impl.fragments.LineFragment)2 TextRange (com.intellij.openapi.util.TextRange)2 FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)2 Fragment (com.intellij.openapi.diff.impl.fragments.Fragment)1 DiffCorrection (com.intellij.openapi.diff.impl.processing.DiffCorrection)1 DiffFragmentsProcessor (com.intellij.openapi.diff.impl.processing.DiffFragmentsProcessor)1 Document (com.intellij.openapi.editor.Document)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Diff (com.intellij.util.diff.Diff)1 ArrayList (java.util.ArrayList)1