Search in sources :

Example 6 with FairDiffIterable

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

Example 7 with FairDiffIterable

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

Example 8 with FairDiffIterable

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;
}
Also used : ArrayList(java.util.ArrayList) FairDiffIterable(com.intellij.diff.comparison.iterables.FairDiffIterable) InnerRange(com.intellij.openapi.vcs.ex.Range.InnerRange) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with FairDiffIterable

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

Example 10 with FairDiffIterable

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

Aggregations

FairDiffIterable (com.intellij.diff.comparison.iterables.FairDiffIterable)14 NotNull (org.jetbrains.annotations.NotNull)14 ArrayList (java.util.ArrayList)4 DiffIterable (com.intellij.diff.comparison.iterables.DiffIterable)2 MergeRange (com.intellij.diff.util.MergeRange)2 Range (com.intellij.diff.util.Range)2 MergingCharSequence (com.intellij.util.text.MergingCharSequence)2 List (java.util.List)2 DiffTooBigException (com.intellij.diff.comparison.DiffTooBigException)1 WordBlock (com.intellij.diff.comparison.LineFragmentSplitter.WordBlock)1 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 DiffUtil (com.intellij.diff.util.DiffUtil)1 InnerRange (com.intellij.openapi.vcs.ex.Range.InnerRange)1 TIntArrayList (gnu.trove.TIntArrayList)1 BitSet (java.util.BitSet)1