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;
}
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());
}
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;
}
Aggregations