use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class ComparisonManagerImpl method trimIgnoredChanges.
@Nullable
private static LineFragment trimIgnoredChanges(@NotNull LineFragment fragment, @NotNull List<Line> lines1, @NotNull List<Line> lines2, @NotNull BitSet ignored1, @NotNull BitSet ignored2) {
// trim ignored lines
Range range = TrimUtil.trimExpandList(lines1, lines2, fragment.getStartLine1(), fragment.getStartLine2(), fragment.getEndLine1(), fragment.getEndLine2(), (line1, line2) -> areIgnoredEqualLines(line1, line2, ignored1, ignored2), line -> isIgnoredLine(line, ignored1), line -> isIgnoredLine(line, ignored2));
int startLine1 = range.start1;
int startLine2 = range.start2;
int endLine1 = range.end1;
int endLine2 = range.end2;
if (startLine1 == endLine1 && startLine2 == endLine2)
return null;
IntPair offsets1 = getOffsets(lines1, startLine1, endLine1);
IntPair offsets2 = getOffsets(lines2, startLine2, endLine2);
int startOffset1 = offsets1.val1;
int endOffset1 = offsets1.val2;
int startOffset2 = offsets2.val1;
int endOffset2 = offsets2.val2;
List<DiffFragment> newInner = null;
if (fragment.getInnerFragments() != null) {
int shift1 = startOffset1 - fragment.getStartOffset1();
int shift2 = startOffset2 - fragment.getStartOffset2();
int newCount1 = endOffset1 - startOffset1;
int newCount2 = endOffset2 - startOffset2;
newInner = ContainerUtil.mapNotNull(fragment.getInnerFragments(), it -> {
int start1 = DiffUtil.bound(it.getStartOffset1() - shift1, 0, newCount1);
int start2 = DiffUtil.bound(it.getStartOffset2() - shift2, 0, newCount2);
int end1 = DiffUtil.bound(it.getEndOffset1() - shift1, 0, newCount1);
int end2 = DiffUtil.bound(it.getEndOffset2() - shift2, 0, newCount2);
TextRange range1 = trimIgnoredRange(start1, end1, ignored1, startOffset1);
TextRange range2 = trimIgnoredRange(start2, end2, ignored2, startOffset2);
if (range1.isEmpty() && range2.isEmpty())
return null;
return new DiffFragmentImpl(range1.getStartOffset(), range1.getEndOffset(), range2.getStartOffset(), range2.getEndOffset());
});
if (newInner.isEmpty())
return null;
}
return new LineFragmentImpl(startLine1, endLine1, startLine2, endLine2, startOffset1, endOffset1, startOffset2, endOffset2, newInner);
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class ComparisonManagerImpl method convertIntoLineFragments.
@NotNull
public static List<LineFragment> convertIntoLineFragments(@NotNull List<Line> lines1, @NotNull List<Line> lines2, @NotNull FairDiffIterable changes) {
List<LineFragment> fragments = new ArrayList<>();
for (Range ch : changes.iterateChanges()) {
IntPair offsets1 = getOffsets(lines1, ch.start1, ch.end1);
IntPair offsets2 = getOffsets(lines2, ch.start2, ch.end2);
fragments.add(new LineFragmentImpl(ch.start1, ch.end1, ch.start2, ch.end2, offsets1.val1, offsets1.val2, offsets2.val1, offsets2.val2));
}
return fragments;
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class LineFragmentSplitter method run.
// indexes here are a bit tricky
// -1 - the beginning of file, words.size() - end of file, everything in between - InlineChunks (words or newlines)
@NotNull
public List<WordBlock> run() {
boolean hasEqualWords = false;
for (Range range : myIterable.iterateUnchanged()) {
int count = range.end1 - range.start1;
for (int i = 0; i < count; i++) {
int index1 = range.start1 + i;
int index2 = range.start2 + i;
if (isNewline(myWords1, index1) && isNewline(myWords2, index2)) {
// split by matched newlines
addLineChunk(index1, index2, hasEqualWords);
hasEqualWords = false;
} else {
if (isFirstInLine(myWords1, index1) && isFirstInLine(myWords2, index2)) {
// split by matched first word in line
addLineChunk(index1 - 1, index2 - 1, hasEqualWords);
hasEqualWords = false;
}
// TODO: split by 'last word in line' + 'last word in whole sequence' ?
hasEqualWords = true;
}
}
}
addLineChunk(myWords1.size(), myWords2.size(), hasEqualWords);
if (pendingChunk != null)
myResult.add(pendingChunk.block);
return myResult;
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class LineFragmentSplitter method createChunk.
@NotNull
private PendingChunk createChunk(int start1, int start2, int end1, int end2, boolean hasEqualWords) {
int startOffset1 = getOffset(myWords1, myText1, start1);
int startOffset2 = getOffset(myWords2, myText2, start2);
int endOffset1 = getOffset(myWords1, myText1, end1);
int endOffset2 = getOffset(myWords2, myText2, end2);
start1 = Math.max(0, start1 + 1);
start2 = Math.max(0, start2 + 1);
end1 = Math.min(end1 + 1, myWords1.size());
end2 = Math.min(end2 + 1, myWords2.size());
WordBlock block = new WordBlock(new Range(start1, end1, start2, end2), new Range(startOffset1, endOffset1, startOffset2, endOffset2));
return new PendingChunk(block, hasEqualWords, hasWordsInside(block), isEqualsIgnoreWhitespace(block));
}
use of com.intellij.diff.util.Range in project intellij-community by JetBrains.
the class ChangeDiffIterableBase method changes.
@NotNull
@Override
public Iterator<Range> changes() {
return new Iterator<Range>() {
@NotNull
private final ChangeIterable myIterable = createChangeIterable();
@Override
public boolean hasNext() {
return myIterable.valid();
}
@Override
public Range next() {
Range range = new Range(myIterable.getStart1(), myIterable.getEnd1(), myIterable.getStart2(), myIterable.getEnd2());
myIterable.next();
return range;
}
};
}
Aggregations