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