use of com.intellij.diff.comparison.iterables.FairDiffIterable in project intellij-community by JetBrains.
the class Block method createPreviousBlock.
@NotNull
public Block createPreviousBlock(@NotNull String[] prevContent) {
try {
FairDiffIterable iterable = ByLine.compare(Arrays.asList(prevContent), Arrays.asList(mySource), ComparisonPolicy.IGNORE_WHITESPACES, DumbProgressIndicator.INSTANCE);
// empty range should not be transferred to the non-empty range
boolean greedy = myStart != myEnd;
int start = myStart;
int end = myEnd;
int shift = 0;
for (Range range : iterable.iterateChanges()) {
int changeStart = range.start2 + shift;
int changeEnd = range.end2 + shift;
int changeShift = (range.end1 - range.start1) - (range.end2 - range.start2);
DiffUtil.UpdatedLineRange updatedRange = DiffUtil.updateRangeOnModification(start, end, changeStart, changeEnd, changeShift, greedy);
start = updatedRange.startLine;
end = updatedRange.endLine;
shift += changeShift;
}
if (start < 0 || end > prevContent.length || end < start) {
LOG.error("Invalid block range: [" + start + ", " + end + "); length - " + prevContent.length);
}
// intern strings, reducing memory usage
for (Range range : iterable.iterateUnchanged()) {
int count = range.end1 - range.start1;
for (int i = 0; i < count; i++) {
int prevIndex = range.start1 + i;
int sourceIndex = range.start2 + i;
if (prevContent[prevIndex].equals(mySource[sourceIndex])) {
prevContent[prevIndex] = mySource[sourceIndex];
}
}
}
return new Block(prevContent, start, end);
} catch (DiffTooBigException e) {
return new Block(prevContent, 0, 0);
}
}
use of com.intellij.diff.comparison.iterables.FairDiffIterable in project intellij-community by JetBrains.
the class ComparisonManagerImpl method compareLines.
@NotNull
@Override
public List<LineFragment> compareLines(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ComparisonPolicy policy, @NotNull ProgressIndicator indicator) throws DiffTooBigException {
List<Line> lines1 = getLines(text1);
List<Line> lines2 = getLines(text2);
List<CharSequence> lineTexts1 = ContainerUtil.map(lines1, Line::getContent);
List<CharSequence> lineTexts2 = ContainerUtil.map(lines2, Line::getContent);
FairDiffIterable iterable = ByLine.compare(lineTexts1, lineTexts2, policy, indicator);
return convertIntoLineFragments(lines1, lines2, iterable);
}
use of com.intellij.diff.comparison.iterables.FairDiffIterable in project intellij-community by JetBrains.
the class RangesBuilder method createRangesSimple.
@NotNull
private static List<Range> createRangesSimple(@NotNull List<String> current, @NotNull List<String> vcs, int currentShift, int vcsShift) throws FilesTooBigForDiffException {
FairDiffIterable iterable = ByLine.compare(vcs, current, ComparisonPolicy.DEFAULT, DumbProgressIndicator.INSTANCE);
List<Range> result = new ArrayList<>();
for (com.intellij.diff.util.Range range : iterable.iterateChanges()) {
int vcsLine1 = vcsShift + range.start1;
int vcsLine2 = vcsShift + range.end1;
int currentLine1 = currentShift + range.start2;
int currentLine2 = currentShift + range.end2;
result.add(new Range(currentLine1, currentLine2, vcsLine1, vcsLine2));
}
return result;
}
use of com.intellij.diff.comparison.iterables.FairDiffIterable in project intellij-community by JetBrains.
the class ByChar method compareTwoStep.
@NotNull
public static FairDiffIterable compareTwoStep(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ProgressIndicator indicator) {
indicator.checkCanceled();
CharOffsets chars1 = getNonSpaceChars(text1);
CharOffsets chars2 = getNonSpaceChars(text2);
FairDiffIterable nonSpaceChanges = diff(chars1.characters, chars2.characters, indicator);
return matchAdjustmentSpaces(chars1, chars2, text1, text2, nonSpaceChanges, indicator);
}
use of com.intellij.diff.comparison.iterables.FairDiffIterable in project intellij-community by JetBrains.
the class ByChar method comparePunctuation.
/*
* Compare punctuation chars only, all other characters are left unmatched
*/
@NotNull
public static FairDiffIterable comparePunctuation(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ProgressIndicator indicator) {
indicator.checkCanceled();
CharOffsets chars1 = getPunctuationChars(text1);
CharOffsets chars2 = getPunctuationChars(text2);
FairDiffIterable nonSpaceChanges = diff(chars1.characters, chars2.characters, indicator);
return transfer(chars1, chars2, text1, text2, nonSpaceChanges, indicator);
}
Aggregations