Search in sources :

Example 1 with Fragment

use of com.intellij.openapi.diff.impl.fragments.Fragment in project intellij-community by JetBrains.

the class MergeOperations method getOperations.

@NotNull
public List<Operation> getOperations() {
    Fragment fragment = getCurrentFragment();
    if (fragment == null)
        return NO_OPERATIONS;
    ArrayList<Operation> operations = new ArrayList<>(3);
    TextRange range = fragment.getRange(mySide);
    if (range.getLength() > 0) {
        if (isWritable(mySide))
            operations.add(removeOperation(range, getDocument()));
        TextRange otherRange = fragment.getRange(mySide.otherSide());
        boolean otherIsWritable = isWritable(mySide.otherSide());
        if (otherIsWritable)
            operations.add(insertOperation(range, otherRange.getEndOffset(), getDocument(), getOtherDocument(), mySide));
        if (otherRange.getLength() > 0 && otherIsWritable)
            operations.add(replaceOperation(range, otherRange, getDocument(), getOtherDocument(), mySide));
    }
    return operations;
}
Also used : ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) Fragment(com.intellij.openapi.diff.impl.fragments.Fragment) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Fragment

use of com.intellij.openapi.diff.impl.fragments.Fragment in project intellij-community by JetBrains.

the class MergeOperations method selectSuggestion.

public void selectSuggestion() {
    Fragment fragment = getCurrentFragment();
    if (fragment == null)
        return;
    setSelection(fragment, mySide);
    setSelection(fragment, mySide.otherSide());
}
Also used : Fragment(com.intellij.openapi.diff.impl.fragments.Fragment)

Example 3 with Fragment

use of com.intellij.openapi.diff.impl.fragments.Fragment 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)

Aggregations

Fragment (com.intellij.openapi.diff.impl.fragments.Fragment)3 DiffFragment (com.intellij.openapi.diff.ex.DiffFragment)1 LineFragment (com.intellij.openapi.diff.impl.fragments.LineFragment)1 DiffString (com.intellij.openapi.diff.impl.string.DiffString)1 TextRange (com.intellij.openapi.util.TextRange)1 FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1