Search in sources :

Example 1 with ComparisonManager

use of com.intellij.diff.comparison.ComparisonManager in project android by JetBrains.

the class DefaultRecipeExecutor method compareFile.

/**
   * Return true if the content of {@code targetFile} is the same as the content of {@code sourceVFile}.
   */
public boolean compareFile(@NotNull VirtualFile sourceVFile, @NotNull File targetFile) throws IOException {
    VirtualFile targetVFile = findFileByIoFile(targetFile, true);
    if (targetVFile == null) {
        return false;
    }
    if (sourceVFile.getFileType().isBinary()) {
        byte[] source = sourceVFile.contentsToByteArray();
        byte[] target = targetVFile.contentsToByteArray();
        return Arrays.equals(source, target);
    } else {
        String source = readTextFile(sourceVFile);
        String target = readTextFile(targetVFile);
        ComparisonManager comparisonManager = ComparisonManager.getInstance();
        return comparisonManager.isEquals(source, target, ComparisonPolicy.IGNORE_WHITESPACES);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ComparisonManager(com.intellij.diff.comparison.ComparisonManager)

Example 2 with ComparisonManager

use of com.intellij.diff.comparison.ComparisonManager in project android by JetBrains.

the class DefaultRecipeExecutor method compareTextFile.

/**
   * Return true if the content of {@code targetFile} is the same as {@code content}.
   */
public boolean compareTextFile(@NotNull File targetFile, @NotNull String content) {
    String target = readTextFile(targetFile);
    ComparisonManager comparisonManager = ComparisonManager.getInstance();
    return comparisonManager.isEquals(content, target, ComparisonPolicy.IGNORE_WHITESPACES);
}
Also used : ComparisonManager(com.intellij.diff.comparison.ComparisonManager)

Example 3 with ComparisonManager

use of com.intellij.diff.comparison.ComparisonManager in project intellij-community by JetBrains.

the class ChangesDiffCalculator method calculateDiff.

public static List<TextRange> calculateDiff(@NotNull Document beforeDocument, @NotNull Document currentDocument) {
    CharSequence beforeText = beforeDocument.getCharsSequence();
    CharSequence currentText = currentDocument.getCharsSequence();
    try {
        ComparisonManager manager = ComparisonManager.getInstance();
        List<LineFragment> lineFragments = manager.compareLinesInner(beforeText, currentText, ComparisonPolicy.DEFAULT, DumbProgressIndicator.INSTANCE);
        List<TextRange> modifiedRanges = new ArrayList<>();
        for (LineFragment lineFragment : lineFragments) {
            int fragmentStartOffset = lineFragment.getStartOffset2();
            int fragmentEndOffset = lineFragment.getEndOffset2();
            List<DiffFragment> innerFragments = lineFragment.getInnerFragments();
            if (innerFragments != null) {
                for (DiffFragment innerFragment : innerFragments) {
                    int innerFragmentStartOffset = fragmentStartOffset + innerFragment.getStartOffset2();
                    int innerFragmentEndOffset = fragmentStartOffset + innerFragment.getEndOffset2();
                    modifiedRanges.add(calculateChangeHighlightRange(currentText, innerFragmentStartOffset, innerFragmentEndOffset));
                }
            } else {
                modifiedRanges.add(calculateChangeHighlightRange(currentText, fragmentStartOffset, fragmentEndOffset));
            }
        }
        return modifiedRanges;
    } catch (DiffTooBigException e) {
        LOG.info(e);
        return Collections.emptyList();
    }
}
Also used : ComparisonManager(com.intellij.diff.comparison.ComparisonManager) LineFragment(com.intellij.diff.fragments.LineFragment) DiffFragment(com.intellij.diff.fragments.DiffFragment) ArrayList(java.util.ArrayList) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) TextRange(com.intellij.openapi.util.TextRange)

Example 4 with ComparisonManager

use of com.intellij.diff.comparison.ComparisonManager in project intellij-community by JetBrains.

the class SvnPropertiesDiffViewer method performRediff.

@NotNull
@Override
protected Runnable performRediff(@NotNull ProgressIndicator indicator) {
    if (!myFirstRediff)
        return new EmptyRunnable();
    myFirstRediff = false;
    for (DiffChange change : myDiffChanges) {
        PropertyRecord record = change.getRecord();
        String before = record.getBefore();
        String after = record.getAfter();
        assert before != null || after != null;
        if (before == null) {
            change.setFragments(createEverythingChanged(0, after.length(), 0, StringUtil.countNewLines(after) + 1));
            continue;
        }
        if (after == null) {
            change.setFragments(createEverythingChanged(before.length(), 0, StringUtil.countNewLines(before) + 1, 0));
            continue;
        }
        try {
            ComparisonManager manager = ComparisonManager.getInstance();
            change.setFragments(manager.squash(manager.compareLinesInner(before, after, ComparisonPolicy.DEFAULT, indicator)));
        } catch (DiffTooBigException e) {
            change.setFragments(createEverythingChanged(before.length(), after.length(), StringUtil.countNewLines(before) + 1, StringUtil.countNewLines(after) + 1));
        }
    }
    return () -> {
        for (DiffChange change : myDiffChanges) {
            setupHighlighting(change, Side.LEFT);
            setupHighlighting(change, Side.RIGHT);
        }
    };
}
Also used : ComparisonManager(com.intellij.diff.comparison.ComparisonManager) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ComparisonManager (com.intellij.diff.comparison.ComparisonManager)4 DiffTooBigException (com.intellij.diff.comparison.DiffTooBigException)2 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 LineFragment (com.intellij.diff.fragments.LineFragment)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1