use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class CorrectionTest method testConcatinateSingleSide.
public void testConcatinateSingleSide() throws FilesTooBigForDiffException {
DiffCorrection correction = new DiffCorrection.ConcatenateSingleSide();
DiffFragment[] corrected = correction.correct(new DiffFragment[] { new DiffFragment(null, "a"), new DiffFragment("b", null), new DiffFragment("c", "d"), new DiffFragment(null, "a"), new DiffFragment("b", null), new DiffFragment("1", null), new DiffFragment("x", "x"), new DiffFragment(null, "a") });
CHECK.compareAll(new DiffFragment[] { new DiffFragment("b", "a"), new DiffFragment("c", "d"), new DiffFragment("b1", "a"), new DiffFragment("x", "x"), new DiffFragment(null, "a") }, corrected);
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class CorrectionTest method testChangedSpaceCorrection.
public void testChangedSpaceCorrection() throws FilesTooBigForDiffException {
DiffCorrection correction = new DiffCorrection.ChangedSpace(ComparisonPolicy.DEFAULT);
DiffFragment[] fragments = correction.correct(new DiffFragment[] { new DiffFragment("x", "y"), new DiffFragment(" ", " "), new DiffFragment("ab", "ab"), new DiffFragment(" ", " "), new DiffFragment(" ", " w o r d"), new DiffFragment(" ", " w o r d") });
CHECK.compareAll(new DiffFragment[] { new DiffFragment("x", "y"), new DiffFragment(null, " "), new DiffFragment(" ", " "), new DiffFragment("ab", "ab"), new DiffFragment(" ", " "), new DiffFragment(" ", " "), new DiffFragment(null, "w o r d"), new DiffFragment(" ", null), new DiffFragment(" ", " "), new DiffFragment(null, "w o r d") }, fragments);
fragments = correction.correct(new DiffFragment[] { new DiffFragment("\n ", "\n ") });
CHECK.compareAll(new DiffFragment[] { new DiffFragment("\n", "\n"), new DiffFragment(" ", null), new DiffFragment(" ", " ") }, fragments);
fragments = correction.correct(new DiffFragment[] { new DiffFragment("\n", "\n\n") });
CHECK.compareAll(new DiffFragment[] { new DiffFragment("\n", "\n"), new DiffFragment(null, "\n") }, fragments);
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class UniteSameTypeTest method testUnitDifferentOnesides.
public void testUnitDifferentOnesides() throws FilesTooBigForDiffException {
DiffFragment[] fragments = UniteSameType.INSTANCE.correct(new DiffFragment[] { new DiffFragment("a", "b"), new DiffFragment(null, " "), new DiffFragment("\n ", null), new DiffFragment("x", "x") });
CHECK.compareAll(new DiffFragment[] { new DiffFragment("a\n ", "b "), new DiffFragment("x", "x") }, fragments);
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class ChangeList method buildChanges.
private ArrayList<Change> buildChanges() throws FilesTooBigForDiffException {
Document base = getDocument(FragmentSide.SIDE1);
DiffString[] baseLines = DiffUtil.convertToLines(base.getText());
Document version = getDocument(FragmentSide.SIDE2);
DiffString[] versionLines = DiffUtil.convertToLines(version.getText());
DiffFragment[] fragments = ComparisonPolicy.DEFAULT.buildDiffFragmentsFromLines(baseLines, versionLines);
final ArrayList<Change> result = new ArrayList<>();
new DiffFragmentsEnumerator(fragments) {
@Override
protected void process(DiffFragment fragment) {
if (fragment.isEqual())
return;
Context context = getContext();
TextRange range1 = context.createRange(FragmentSide.SIDE1);
TextRange range2 = context.createRange(FragmentSide.SIDE2);
result.add(new SimpleChange(ChangeType.fromDiffFragment(context.getFragment()), range1, range2, ChangeList.this));
}
}.execute();
return result;
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class PreferWholeLines method correct.
public DiffFragment[] correct(DiffFragment[] fragments) {
for (int i = 1; i < fragments.length - 1; i++) {
DiffFragment fragment = fragments[i];
if (!fragment.isOneSide())
continue;
DiffFragment nextFragment = fragments[i + 1];
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString fragmentText = side.getText(fragment);
DiffString otherNextFragmentText = side.getOtherText(nextFragment);
DiffString nextFragmentText = side.getText(nextFragment);
if (nextFragment.isOneSide()) {
LOG.error("<" + fragmentText + "> <" + otherNextFragmentText + ">");
}
if (StringUtil.startsWithChar(fragmentText, '\n') && StringUtil.startsWithChar(nextFragmentText, '\n') && StringUtil.startsWithChar(otherNextFragmentText, '\n')) {
DiffFragment previous = fragments[i - 1];
DiffString previousText = side.getText(previous);
DiffString otherPreciousText = side.getOtherText(previous);
assert previous != null;
assert previousText != null;
assert otherPreciousText != null;
assert fragmentText != null;
assert nextFragmentText != null;
assert otherNextFragmentText != null;
previous = side.createFragment(previousText.append('\n'), otherPreciousText.append('\n'), previous.isModified());
fragments[i - 1] = previous;
fragment = side.createFragment(fragmentText.substring(1).append('\n'), side.getOtherText(fragment), fragment.isModified());
fragments[i] = fragment;
nextFragment = side.createFragment(nextFragmentText.substring(1), otherNextFragmentText.substring(1), nextFragment.isModified());
fragments[i + 1] = nextFragment;
}
}
return fragments;
}
Aggregations