use of com.intellij.openapi.diff.impl.string.DiffString 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.impl.string.DiffString 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.impl.string.DiffString in project intellij-community by JetBrains.
the class Util method getText.
@NotNull
public static DiffString getText(@NotNull DiffFragment[] fragments, @NotNull FragmentSide side) {
DiffString[] data = new DiffString[fragments.length];
for (int i = 0; i < fragments.length; i++) {
DiffFragment fragment = fragments[i];
data[i] = side.getText(fragment);
}
return DiffString.concatenate(data);
}
use of com.intellij.openapi.diff.impl.string.DiffString in project intellij-community by JetBrains.
the class Util method transformHeadInsert.
@NotNull
private static DiffFragment[] transformHeadInsert(@NotNull DiffFragment[] fragments, @NotNull FragmentSide side) {
// transforms {abc}abcd into a{bca}bcd
if (fragments.length >= 2) {
DiffFragment first = fragments[0];
DiffFragment second = fragments[1];
if (first == null || second == null) {
return fragments;
}
if (side.getText(first) != null) {
return fragments;
}
DiffString rightText = side.getOtherText(first);
DiffString secondText = side.getText(second);
if (!Comparing.equal(side.getOtherText(second), secondText)) {
return fragments;
}
if (secondText.charAt(0) == rightText.charAt(0)) {
List<DiffFragment> result = new ArrayList<DiffFragment>();
result.add(side.createFragment(rightText.substring(0, 1), rightText.substring(0, 1), false));
result.add(side.createFragment(null, DiffString.concatenate(rightText.substring(1), secondText.substring(0, 1)), true));
result.add(side.createFragment(secondText.substring(1), secondText.substring(1), second.isModified()));
result.addAll(Arrays.asList(fragments).subList(2, fragments.length));
return result.toArray(new DiffFragment[result.size()]);
}
}
return fragments;
}
use of com.intellij.openapi.diff.impl.string.DiffString in project intellij-community by JetBrains.
the class Util method concatenate.
@NotNull
public static DiffFragment concatenate(@NotNull DiffFragment[] line, int from, int to) {
DiffString[] data1 = new DiffString[to - from];
DiffString[] data2 = new DiffString[to - from];
boolean isEqual = true;
for (int i = 0; i < to - from; i++) {
DiffFragment fragment = line[from + i];
isEqual &= fragment.isEqual();
data1[i] = fragment.getText1();
data2[i] = fragment.getText2();
}
DiffString text1 = notEmptyContent(DiffString.concatenate(data1));
DiffString text2 = notEmptyContent(DiffString.concatenate(data2));
return isEqual ? DiffFragment.unchanged(text1, text2) : new DiffFragment(text1, text2);
}
Aggregations