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);
}
}
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);
}
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();
}
}
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);
}
};
}
Aggregations