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