Search in sources :

Example 11 with Range

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);
    }
}
Also used : Range(com.intellij.diff.util.Range) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with 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);
}
Also used : Range(com.intellij.diff.util.Range) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Range

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;
}
Also used : ArrayList(java.util.ArrayList) Range(com.intellij.diff.util.Range) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with Range

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);
}
Also used : Range(com.intellij.diff.util.Range)

Example 15 with Range

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;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) MergeRange(com.intellij.diff.util.MergeRange) Range(com.intellij.diff.util.Range)

Aggregations

Range (com.intellij.diff.util.Range)26 NotNull (org.jetbrains.annotations.NotNull)21 MergeRange (com.intellij.diff.util.MergeRange)8 ArrayList (java.util.ArrayList)7 TextRange (com.intellij.openapi.util.TextRange)5 FairDiffIterable (com.intellij.diff.comparison.iterables.FairDiffIterable)3 Iterator (java.util.Iterator)3 DiffTooBigException (com.intellij.diff.comparison.DiffTooBigException)2 DiffIterable (com.intellij.diff.comparison.iterables.DiffIterable)2 DiffIterableUtil (com.intellij.diff.comparison.iterables.DiffIterableUtil)2 DiffUtil (com.intellij.diff.util.DiffUtil)2 IntPair (com.intellij.diff.util.IntPair)2 TIntArrayList (gnu.trove.TIntArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 WordBlock (com.intellij.diff.comparison.LineFragmentSplitter.WordBlock)1 DiffIterableUtil.fair (com.intellij.diff.comparison.iterables.DiffIterableUtil.fair)1 com.intellij.diff.fragments (com.intellij.diff.fragments)1 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 Side (com.intellij.diff.util.Side)1 Logger (com.intellij.openapi.diagnostic.Logger)1