Search in sources :

Example 31 with DiffFragment

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

the class CorrectionTest method testConcatinateSingleSide.

public void testConcatinateSingleSide() throws FilesTooBigForDiffException {
    DiffCorrection correction = new DiffCorrection.ConcatenateSingleSide();
    DiffFragment[] corrected = correction.correct(new DiffFragment[] { new DiffFragment(null, "a"), new DiffFragment("b", null), new DiffFragment("c", "d"), new DiffFragment(null, "a"), new DiffFragment("b", null), new DiffFragment("1", null), new DiffFragment("x", "x"), new DiffFragment(null, "a") });
    CHECK.compareAll(new DiffFragment[] { new DiffFragment("b", "a"), new DiffFragment("c", "d"), new DiffFragment("b1", "a"), new DiffFragment("x", "x"), new DiffFragment(null, "a") }, corrected);
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

Example 32 with DiffFragment

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

the class CorrectionTest method testChangedSpaceCorrection.

public void testChangedSpaceCorrection() throws FilesTooBigForDiffException {
    DiffCorrection correction = new DiffCorrection.ChangedSpace(ComparisonPolicy.DEFAULT);
    DiffFragment[] fragments = correction.correct(new DiffFragment[] { new DiffFragment("x", "y"), new DiffFragment(" ", "   "), new DiffFragment("ab", "ab"), new DiffFragment(" ", " "), new DiffFragment(" ", " w o r d"), new DiffFragment("   ", " w o r d") });
    CHECK.compareAll(new DiffFragment[] { new DiffFragment("x", "y"), new DiffFragment(null, "  "), new DiffFragment(" ", " "), new DiffFragment("ab", "ab"), new DiffFragment(" ", " "), new DiffFragment(" ", " "), new DiffFragment(null, "w o r d"), new DiffFragment("  ", null), new DiffFragment(" ", " "), new DiffFragment(null, "w o r d") }, fragments);
    fragments = correction.correct(new DiffFragment[] { new DiffFragment("\n  ", "\n ") });
    CHECK.compareAll(new DiffFragment[] { new DiffFragment("\n", "\n"), new DiffFragment(" ", null), new DiffFragment(" ", " ") }, fragments);
    fragments = correction.correct(new DiffFragment[] { new DiffFragment("\n", "\n\n") });
    CHECK.compareAll(new DiffFragment[] { new DiffFragment("\n", "\n"), new DiffFragment(null, "\n") }, fragments);
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

Example 33 with DiffFragment

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

the class UniteSameTypeTest method testUnitDifferentOnesides.

public void testUnitDifferentOnesides() throws FilesTooBigForDiffException {
    DiffFragment[] fragments = UniteSameType.INSTANCE.correct(new DiffFragment[] { new DiffFragment("a", "b"), new DiffFragment(null, " "), new DiffFragment("\n ", null), new DiffFragment("x", "x") });
    CHECK.compareAll(new DiffFragment[] { new DiffFragment("a\n ", "b "), new DiffFragment("x", "x") }, fragments);
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

Example 34 with DiffFragment

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

the class ChangeList method buildChanges.

private ArrayList<Change> buildChanges() throws FilesTooBigForDiffException {
    Document base = getDocument(FragmentSide.SIDE1);
    DiffString[] baseLines = DiffUtil.convertToLines(base.getText());
    Document version = getDocument(FragmentSide.SIDE2);
    DiffString[] versionLines = DiffUtil.convertToLines(version.getText());
    DiffFragment[] fragments = ComparisonPolicy.DEFAULT.buildDiffFragmentsFromLines(baseLines, versionLines);
    final ArrayList<Change> result = new ArrayList<>();
    new DiffFragmentsEnumerator(fragments) {

        @Override
        protected void process(DiffFragment fragment) {
            if (fragment.isEqual())
                return;
            Context context = getContext();
            TextRange range1 = context.createRange(FragmentSide.SIDE1);
            TextRange range2 = context.createRange(FragmentSide.SIDE2);
            result.add(new SimpleChange(ChangeType.fromDiffFragment(context.getFragment()), range1, range2, ChangeList.this));
        }
    }.execute();
    return result;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString)

Example 35 with DiffFragment

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

the class PreferWholeLines method correct.

public DiffFragment[] correct(DiffFragment[] fragments) {
    for (int i = 1; i < fragments.length - 1; i++) {
        DiffFragment fragment = fragments[i];
        if (!fragment.isOneSide())
            continue;
        DiffFragment nextFragment = fragments[i + 1];
        FragmentSide side = FragmentSide.chooseSide(fragment);
        DiffString fragmentText = side.getText(fragment);
        DiffString otherNextFragmentText = side.getOtherText(nextFragment);
        DiffString nextFragmentText = side.getText(nextFragment);
        if (nextFragment.isOneSide()) {
            LOG.error("<" + fragmentText + "> <" + otherNextFragmentText + ">");
        }
        if (StringUtil.startsWithChar(fragmentText, '\n') && StringUtil.startsWithChar(nextFragmentText, '\n') && StringUtil.startsWithChar(otherNextFragmentText, '\n')) {
            DiffFragment previous = fragments[i - 1];
            DiffString previousText = side.getText(previous);
            DiffString otherPreciousText = side.getOtherText(previous);
            assert previous != null;
            assert previousText != null;
            assert otherPreciousText != null;
            assert fragmentText != null;
            assert nextFragmentText != null;
            assert otherNextFragmentText != null;
            previous = side.createFragment(previousText.append('\n'), otherPreciousText.append('\n'), previous.isModified());
            fragments[i - 1] = previous;
            fragment = side.createFragment(fragmentText.substring(1).append('\n'), side.getOtherText(fragment), fragment.isModified());
            fragments[i] = fragment;
            nextFragment = side.createFragment(nextFragmentText.substring(1), otherNextFragmentText.substring(1), nextFragment.isModified());
            fragments[i + 1] = nextFragment;
        }
    }
    return fragments;
}
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)

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