use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class UniteSameType method covertSequentialOneSideToChange.
@NotNull
private static DiffFragment[] covertSequentialOneSideToChange(@NotNull DiffFragment[] fragments) {
if (fragments.length < 2)
return fragments;
DiffCorrection.FragmentsCollector collector = new DiffCorrection.FragmentsCollector();
// DiffFragment previous = fragments[0];
DiffFragment previous = null;
for (int i = 0; i < fragments.length; i++) {
DiffFragment fragment = fragments[i];
if (fragment.isOneSide()) {
if (previous == null)
previous = fragment;
else {
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString previousText = side.getText(previous);
if (previousText == null)
previousText = DiffString.EMPTY;
previous = side.createFragment(DiffString.concatenateNullable(previousText, side.getText(fragment)), side.getOtherText(previous), true);
}
} else {
if (previous != null)
collector.add(previous);
previous = null;
collector.add(fragment);
}
}
if (previous != null)
collector.add(previous);
return collector.toArray();
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class DiffFragmentBuilder method delete.
private void delete(@NotNull TextRange range, int line) {
LOG.debug("DiffFragmentBuilder.delete(" + range + "," + line + ")");
DiffString text1 = null;
DiffString text2 = null;
int start = range.getStartOffset();
int end = range.getEndOffset();
if (myLastLine1 < start) {
text1 = concatenate(mySource1, myLastLine1, start - 1);
}
if (myLastLine2 <= line) {
text2 = concatenate(mySource2, myLastLine2, line);
}
if (text1 != null || text2 != null) {
myData.add(DiffFragment.unchanged(text1, text2));
}
myData.add(new DiffFragment(concatenate(mySource1, start, end), null));
myLastLine1 = end + 1;
myLastLine2 = line + 1;
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class DiffFragmentBuilder method append.
private void append(int line, @NotNull TextRange range) {
LOG.debug("DiffFragmentBuilder.append(" + line + "," + range + "), modified:");
DiffString text1 = null;
DiffString text2 = null;
int start = range.getStartOffset();
int end = range.getEndOffset();
if (myLastLine1 <= line) {
text1 = concatenate(mySource1, myLastLine1, line);
}
if (myLastLine2 < start) {
text2 = concatenate(mySource2, myLastLine2, start - 1);
}
if (text1 != null || text2 != null) {
myData.add(DiffFragment.unchanged(text1, text2));
}
myData.add(new DiffFragment(null, concatenate(mySource2, start, end)));
myLastLine1 = line + 1;
myLastLine2 = end + 1;
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class MergeList method processText.
@NotNull
private static List<MergeFragment> processText(@NotNull String leftText, @NotNull String baseText, @NotNull String rightText, @NotNull ContextLogger logger) throws FilesTooBigForDiffException {
DiffFragment[] leftFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(leftText));
DiffFragment[] rightFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(rightText));
int[] leftOffsets = { 0, 0 };
int[] rightOffsets = { 0, 0 };
int leftIndex = 0;
int rightIndex = 0;
MergeBuilder builder = new MergeBuilder(logger);
while (leftIndex < leftFragments.length || rightIndex < rightFragments.length) {
FragmentSide side;
TextRange[] equalRanges = new TextRange[2];
if (leftOffsets[0] < rightOffsets[0] && leftIndex < leftFragments.length) {
side = FragmentSide.SIDE1;
getEqualRanges(leftFragments[leftIndex], leftOffsets, equalRanges);
leftIndex++;
} else if (rightIndex < rightFragments.length) {
side = FragmentSide.SIDE2;
getEqualRanges(rightFragments[rightIndex], rightOffsets, equalRanges);
rightIndex++;
} else
break;
if (equalRanges[0] != null && equalRanges[1] != null)
builder.add(equalRanges[0], equalRanges[1], side);
else
logger.assertTrue(equalRanges[0] == null && equalRanges[1] == null);
}
return builder.finish(leftText.length(), baseText.length(), rightText.length());
}
use of com.intellij.openapi.diff.ex.DiffFragment in project intellij-community by JetBrains.
the class Util method splitByLines.
@NotNull
static DiffFragment[] splitByLines(@NotNull DiffFragment fragment) {
DiffString[] lines1 = splitByLines(fragment.getText1());
DiffString[] lines2 = splitByLines(fragment.getText2());
if (lines1 != null && lines2 != null && lines1.length != lines2.length) {
LOG.error("1:<" + fragment.getText1() + "> 2:<" + fragment.getText2() + ">");
}
int length = lines1 == null ? lines2.length : lines1.length;
DiffFragment[] lines = new DiffFragment[length];
for (int i = 0; i < lines.length; i++) {
lines[i] = new DiffFragment(lines1 == null ? null : lines1[i], lines2 == null ? null : lines2[i]);
}
return lines;
}
Aggregations