use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class TextPatchBuilder method compareLines.
@NotNull
private static List<Range> compareLines(@NotNull List<String> beforeLines, @NotNull List<String> afterLines, boolean beforeNoNewlineAtEOF, boolean afterNoNewlineAtEOF) {
if (!beforeNoNewlineAtEOF && !afterNoNewlineAtEOF)
return doCompareLines(beforeLines, afterLines);
int beforeLastLine = beforeLines.size() - 1;
int afterLastLine = afterLines.size() - 1;
List<String> beforeComparedLines = beforeNoNewlineAtEOF ? beforeLines.subList(0, beforeLastLine) : beforeLines;
List<String> afterComparedLines = afterNoNewlineAtEOF ? afterLines.subList(0, afterLastLine) : afterLines;
List<Range> ranges = doCompareLines(beforeComparedLines, afterComparedLines);
if (beforeNoNewlineAtEOF && afterNoNewlineAtEOF) {
if (beforeLines.get(beforeLastLine).equals(afterLines.get(afterLastLine)))
return ranges;
Range range = new Range(beforeLastLine, beforeLastLine + 1, afterLastLine, afterLastLine + 1);
return appendRange(ranges, range);
} else if (beforeNoNewlineAtEOF) {
Range range = new Range(beforeLastLine, beforeLastLine + 1, afterLastLine + 1, afterLastLine + 1);
return appendRange(ranges, range);
} else {
Range range = new Range(beforeLastLine + 1, beforeLastLine + 1, afterLastLine, afterLastLine + 1);
return appendRange(ranges, range);
}
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class TextPatchBuilder method getAdjacentFragments.
@NotNull
private static List<Range> getAdjacentFragments(@NotNull List<Range> fragments, int hunkStart) {
int hunkEnd = hunkStart + 1;
while (hunkEnd < fragments.size()) {
Range lastFragment = fragments.get(hunkEnd - 1);
Range nextFragment = fragments.get(hunkEnd);
if (lastFragment.end1 + CONTEXT_LINES < nextFragment.start1 - CONTEXT_LINES && lastFragment.end2 + CONTEXT_LINES < nextFragment.start2 - CONTEXT_LINES) {
break;
}
hunkEnd++;
}
return fragments.subList(hunkStart, hunkEnd);
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class DiffIterableUtil method extractDataRanges.
//
// Debug
//
@SuppressWarnings("unused")
@NotNull
public static <T> List<LineRangeData> extractDataRanges(@NotNull List<T> objects1, @NotNull List<T> objects2, @NotNull DiffIterable iterable) {
List<LineRangeData> result = ContainerUtil.newArrayList();
for (Pair<Range, Boolean> pair : iterateAll(iterable)) {
Range range = pair.first;
boolean equals = pair.second;
List<T> data1 = new ArrayList<>();
List<T> data2 = new ArrayList<>();
for (int i = range.start1; i < range.end1; i++) {
data1.add(objects1.get(i));
}
for (int i = range.start2; i < range.end2; i++) {
data2.add(objects2.get(i));
}
result.add(new LineRangeData<>(data1, data2, equals));
}
return result;
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class ChangeCorrector method execute.
protected void execute() {
int last1 = 0;
int last2 = 0;
for (Range ch : myChanges.iterateUnchanged()) {
int count = ch.end1 - ch.start1;
for (int i = 0; i < count; i++) {
int index1 = getOriginalIndex1(ch.start1 + i);
int index2 = getOriginalIndex2(ch.start2 + i);
matchGap(last1, index1, last2, index2);
myBuilder.markEqual(index1, index2);
last1 = index1 + 1;
last2 = index2 + 1;
}
}
matchGap(last1, myLength1, last2, myLength2);
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class ComparisonManagerImpl method areIgnoredEqualLines.
private static boolean areIgnoredEqualLines(@NotNull Line line1, @NotNull Line line2, @NotNull BitSet ignored1, @NotNull BitSet ignored2) {
int start1 = line1.getOffset1();
int end1 = line1.getOffset2();
int start2 = line2.getOffset1();
int end2 = line2.getOffset2();
Range range = TrimUtil.trimExpandText(line1.getOriginalText(), line2.getOriginalText(), start1, start2, end1, end2, ignored1, ignored2);
if (!range.isEmpty())
return false;
List<ByWord.InlineChunk> words1 = getNonIgnoredWords(line1, ignored1);
List<ByWord.InlineChunk> words2 = getNonIgnoredWords(line2, ignored2);
if (words1.size() != words2.size())
return false;
for (int i = 0; i < words1.size(); i++) {
CharSequence word1 = getWordContent(line1, words1.get(i));
CharSequence word2 = getWordContent(line2, words2.get(i));
if (!StringUtil.equals(word1, word2))
return false;
}
return true;
}
Aggregations