Search in sources :

Example 1 with DiffFragment

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

the class TextCompareProcessor method findSubFragments.

private ArrayList<LineFragment> findSubFragments(@NotNull DiffString text1, @NotNull DiffString text2) throws FilesTooBigForDiffException {
    DiffFragment[] fragments = new ByWord(myComparisonPolicy).buildFragments(text1, text2);
    fragments = DiffCorrection.ConnectSingleSideToChange.INSTANCE.correct(fragments);
    fragments = UniteSameType.INSTANCE.correct(fragments);
    fragments = PreferWholeLines.INSTANCE.correct(fragments);
    fragments = UniteSameType.INSTANCE.correct(fragments);
    DiffFragment[][] lines = Util.splitByUnchangedLines(fragments);
    lines = Util.uniteFormattingOnly(lines);
    LineFragmentsCollector collector = new LineFragmentsCollector();
    for (DiffFragment[] line : lines) {
        DiffFragment[][] subLines = LineBlockDivider.SINGLE_SIDE.divide(line);
        subLines = Util.uniteFormattingOnly(subLines);
        for (DiffFragment[] subLineFragments : subLines) {
            LineFragment subLine = collector.addDiffFragment(Util.concatenate(subLineFragments));
            if (!subLine.isOneSide()) {
                subLine.setChildren(processInlineFragments(subLineFragments));
            }
        }
    }
    return collector.getFragments();
}
Also used : LineFragment(com.intellij.openapi.diff.impl.fragments.LineFragment) DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

Example 2 with DiffFragment

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

the class TextCompareProcessor method process.

public List<LineFragment> process(@Nullable String text1, @Nullable String text2) throws FilesTooBigForDiffException {
    if (myHighlightMode == HighlightMode.NO_HIGHLIGHTING) {
        return Collections.emptyList();
    }
    text1 = StringUtil.notNullize(text1);
    text2 = StringUtil.notNullize(text2);
    if (text1.isEmpty() || text2.isEmpty()) {
        return new DummyDiffFragmentsProcessor().process(text1, text2);
    }
    DiffString diffText1 = DiffString.create(text1);
    DiffString diffText2 = DiffString.create(text2);
    DiffFragment[] woFormattingBlocks = myDiffPolicy.buildFragments(diffText1, diffText2);
    DiffFragment[] step1lineFragments = new DiffCorrection.TrueLineBlocks(myComparisonPolicy).correctAndNormalize(woFormattingBlocks);
    ArrayList<LineFragment> lineBlocks = new DiffFragmentsProcessor().process(step1lineFragments);
    int badLinesCount = 0;
    if (myHighlightMode == HighlightMode.BY_WORD) {
        for (LineFragment lineBlock : lineBlocks) {
            if (lineBlock.isOneSide() || lineBlock.isEqual())
                continue;
            try {
                DiffString subText1 = lineBlock.getText(diffText1, FragmentSide.SIDE1);
                DiffString subText2 = lineBlock.getText(diffText2, FragmentSide.SIDE2);
                ArrayList<LineFragment> subFragments = findSubFragments(subText1, subText2);
                lineBlock.setChildren(new ArrayList<Fragment>(subFragments));
                lineBlock.adjustTypeFromChildrenTypes();
            } catch (FilesTooBigForDiffException ignore) {
                // If we can't by-word compare two lines - this is not a reason to break entire diff.
                badLinesCount++;
                if (badLinesCount > FilesTooBigForDiffException.MAX_BAD_LINES)
                    break;
            }
        }
    }
    return lineBlocks;
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) Fragment(com.intellij.openapi.diff.impl.fragments.Fragment) LineFragment(com.intellij.openapi.diff.impl.fragments.LineFragment) LineFragment(com.intellij.openapi.diff.impl.fragments.LineFragment) DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) DiffString(com.intellij.openapi.diff.impl.string.DiffString)

Example 3 with DiffFragment

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

the class TextCompareProcessor method processInlineFragments.

private static ArrayList<Fragment> processInlineFragments(DiffFragment[] subLineFragments) {
    LOG.assertTrue(subLineFragments.length > 0);
    FragmentsCollector result = new FragmentsCollector();
    for (DiffFragment fragment : subLineFragments) {
        result.addDiffFragment(fragment);
    }
    return result.getFragments();
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

Example 4 with DiffFragment

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

the class UniteSameType method unitSameTypes.

@NotNull
private static DiffFragment[] unitSameTypes(@NotNull DiffFragment[] fragments) {
    if (fragments.length < 2)
        return fragments;
    DiffCorrection.FragmentsCollector collector = new DiffCorrection.FragmentsCollector();
    DiffFragment previous = fragments[0];
    for (int i = 1; i < fragments.length; i++) {
        DiffFragment fragment = fragments[i];
        if (!fragment.isOneSide() && fragment.getText1().isEmpty() && fragment.getText2().isEmpty())
            continue;
        if (Util.isSameType(previous, fragment)) {
            previous = Util.unite(previous, fragment);
        } else {
            collector.add(previous);
            previous = fragment;
        }
    }
    collector.add(previous);
    return collector.toArray();
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with DiffFragment

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

the class List2D method addAll.

public void addAll(DiffFragment[] line) {
    ensureRowExists();
    for (int i = 0; i < line.length; i++) {
        DiffFragment value = line[i];
        myCurrentRow.add(value);
    }
}
Also used : DiffFragment(com.intellij.openapi.diff.ex.DiffFragment)

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