use of com.intellij.openapi.diff.impl.string.DiffString in project intellij-community by JetBrains.
the class DiffFragmentBuilder method finish.
private void finish() {
DiffString text1 = null;
DiffString text2 = null;
if (myLastLine1 <= mySource1.length) {
text1 = concatenate(mySource1, myLastLine1, mySource1.length);
}
if (myLastLine2 <= mySource2.length) {
text2 = concatenate((mySource2), myLastLine2, mySource2.length);
}
if (text1 != null || text2 != null) {
myData.add(DiffFragment.unchanged(text1, text2));
}
}
use of com.intellij.openapi.diff.impl.string.DiffString in project intellij-community by JetBrains.
the class DiffFragmentBuilder method change.
private void change(@NotNull TextRange range1, @NotNull TextRange range2) {
LOG.debug("DiffFragmentBuilder.change(" + range1 + "," + range2 + ")");
DiffString text1 = null, text2 = null;
int start1 = range1.getStartOffset();
int end1 = range1.getEndOffset();
int start2 = range2.getStartOffset();
int end2 = range2.getEndOffset();
if (myLastLine1 < start1) {
text1 = concatenate(mySource1, myLastLine1, start1 - 1);
}
if (myLastLine2 < start2) {
text2 = concatenate(mySource2, myLastLine2, start2 - 1);
}
if (text1 != null || text2 != null) {
myData.add(DiffFragment.unchanged(text1, text2));
}
myData.add(new DiffFragment(concatenate(mySource1, start1, end1), concatenate(mySource2, start2, end2)));
myLastLine1 = end1 + 1;
myLastLine2 = end2 + 1;
}
use of com.intellij.openapi.diff.impl.string.DiffString 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;
}
use of com.intellij.openapi.diff.impl.string.DiffString in project intellij-community by JetBrains.
the class ByWord method processOneside.
private static void processOneside(@NotNull FragmentBuilder.Version version, int wordCount) {
DiffString prefix = version.getCurrentWordPrefix();
version.addOneSide(prefix, wordCount);
}
use of com.intellij.openapi.diff.impl.string.DiffString 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