Search in sources :

Example 11 with DiffFragment

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

the class Util method unite.

@NotNull
public static DiffFragment unite(@NotNull DiffFragment fragment1, @NotNull DiffFragment fragment2) {
    LOG.assertTrue(isSameType(fragment1, fragment2));
    if (!fragment1.isOneSide()) {
        DiffString unitedText1 = DiffString.concatenateNullable(fragment1.getText1(), fragment2.getText1());
        DiffString unitedText2 = DiffString.concatenateNullable(fragment1.getText2(), fragment2.getText2());
        LOG.assertTrue(fragment1.isEqual() == fragment2.isEqual());
        return fragment1.isEqual() ? DiffFragment.unchanged(unitedText1, unitedText2) : new DiffFragment(unitedText1, unitedText2);
    }
    FragmentSide side = FragmentSide.chooseSide(fragment1);
    return side.createFragment(DiffString.concatenateNullable(side.getText(fragment1), side.getText(fragment2)), null, fragment1.isModified());
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with DiffFragment

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

the class ByWord method buildFragments.

@NotNull
@Override
public DiffFragment[] buildFragments(@NotNull DiffString text1, @NotNull DiffString text2) throws FilesTooBigForDiffException {
    Word[] words1 = buildWords(text1, myComparisonPolicy);
    Word[] words2 = buildWords(text2, myComparisonPolicy);
    Diff.Change change = Diff.buildChanges(words1, words2);
    change = Util.concatEquals(change, words1, words2);
    if (Math.max(countNotWhitespaces(words1), countNotWhitespaces(words2)) > 0 && countEqual(change, words1, words2) == 0)
        return new DiffFragment[] { myComparisonPolicy.createFragment(text1, text2) };
    FragmentBuilder result = new FragmentBuilder(words1, words2, myComparisonPolicy, text1, text2);
    FragmentBuilder.Version version1 = result.getVersion1();
    FragmentBuilder.Version version2 = result.getVersion2();
    while (change != null) {
        if (change.line0 > version1.getCurrentWordIndex()) {
            processEquals(change.line0, change.line1, result);
        }
        if (change.inserted == 0) {
            processOneside(version1, change.deleted);
        } else if (change.deleted == 0) {
            processOneside(version2, change.inserted);
        } else {
            DiffString prefix1 = version1.getCurrentWordPrefix();
            DiffString prefix2 = version2.getCurrentWordPrefix();
            if (!prefix1.isEmpty() || !prefix2.isEmpty())
                result.add(myComparisonPolicy.createFragment(prefix1, prefix2));
            result.addChangedWords(change.deleted, change.inserted);
        }
        change = change.link;
    }
    processEquals(words1.length, words2.length, result);
    result.addTails();
    DiffFragment[] fragments = result.getFragments();
    DiffFragment firstFragment = fragments[0];
    if (firstFragment.isEmpty()) {
        DiffFragment[] newFragments = new DiffFragment[fragments.length - 1];
        System.arraycopy(fragments, 1, newFragments, 0, newFragments.length);
        fragments = newFragments;
    }
    return fragments;
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) Diff(com.intellij.util.diff.Diff) DiffString(com.intellij.openapi.diff.impl.string.DiffString) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with DiffFragment

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

the class DiffFragmentsProcessor method process.

public ArrayList<LineFragment> process(DiffFragment[] fragments) {
    LineFragmentsCollector collector = new LineFragmentsCollector();
    for (int i = 0; i < fragments.length; i++) {
        DiffFragment fragment = fragments[i];
        collector.addDiffFragment(fragment);
    }
    return collector.getFragments();
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

Example 14 with DiffFragment

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

the class ComparisonPolicy method createFragment.

@NotNull
public DiffFragment createFragment(@Nullable DiffString text1, @Nullable DiffString text2) {
    text1 = toNull(text1);
    text2 = toNull(text2);
    if (text1 == null && text2 == null)
        return new DiffFragment(DiffString.EMPTY, DiffString.EMPTY);
    DiffFragment result = new DiffFragment(text1, text2);
    if (text1 != null && text2 != null) {
        result.setModified(!getWrapper(text1).equals(getWrapper(text2)));
    }
    return result;
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DiffFragment

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

the class DiffFragmentBuilder method buildFragments.

@NotNull
public DiffFragment[] buildFragments(@Nullable Diff.Change change) {
    while (change != null) {
        if (change.inserted > 0 && change.deleted > 0) {
            change(new TextRange(change.line0 + 1, change.line0 + change.deleted), new TextRange(change.line1 + 1, change.line1 + change.inserted));
        } else if (change.inserted > 0) {
            append(change.line0, new TextRange(change.line1 + 1, change.line1 + change.inserted));
        } else if (change.deleted > 0) {
            delete(new TextRange(change.line0 + 1, change.line0 + change.deleted), change.line1);
        }
        change = change.link;
    }
    finish();
    final List<DiffFragment> fragments = getFragments();
    return fragments.toArray(new DiffFragment[myData.size()]);
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) TextRange(com.intellij.openapi.util.TextRange) 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