use of com.intellij.openapi.diff.impl.util.ContextLogger in project intellij-community by JetBrains.
the class MergeList method create.
@NotNull
public static MergeList create(@Nullable Project project, @NotNull Document left, @NotNull Document base, @NotNull Document right) {
MergeList mergeList;
String leftText = left.getText();
String baseText = base.getText();
String rightText = right.getText();
@NonNls final Object[] data = { "Left\n", leftText, "\nBase\n", baseText, "\nRight\n", rightText };
ContextLogger logger = new ContextLogger(LOG, new ContextLogger.SimpleContext(data));
List<MergeFragment> fragmentList;
try {
fragmentList = processText(leftText, baseText, rightText, logger);
mergeList = new MergeList(project, left, base, right, null);
} catch (FilesTooBigForDiffException e) {
fragmentList = Collections.emptyList();
mergeList = new MergeList(project, left, base, right, e.getMessage());
}
ArrayList<Change> leftChanges = new ArrayList<>();
ArrayList<Change> rightChanges = new ArrayList<>();
for (MergeFragment mergeFragment : fragmentList) {
TextRange baseRange = mergeFragment.getBase();
TextRange leftRange = mergeFragment.getLeft();
TextRange rightRange = mergeFragment.getRight();
if (compareSubstring(leftText, leftRange, rightText, rightRange)) {
MergeNoConflict conflict = new MergeNoConflict(baseRange, leftRange, rightRange, mergeList);
assert conflict.getLeftChange() != null;
assert conflict.getRightChange() != null;
leftChanges.add(conflict.getLeftChange());
rightChanges.add(conflict.getRightChange());
} else if (compareSubstring(baseText, baseRange, leftText, leftRange)) {
rightChanges.add(SimpleChange.fromRanges(baseRange, rightRange, mergeList.myBaseToRightChangeList));
} else if (compareSubstring(baseText, baseRange, rightText, rightRange)) {
leftChanges.add(SimpleChange.fromRanges(baseRange, leftRange, mergeList.myBaseToLeftChangeList));
} else {
MergeConflict conflict = new MergeConflict(baseRange, leftRange, rightRange, mergeList);
assert conflict.getLeftChange() != null;
assert conflict.getRightChange() != null;
leftChanges.add(conflict.getLeftChange());
rightChanges.add(conflict.getRightChange());
}
}
mergeList.myBaseToLeftChangeList.setChanges(leftChanges);
mergeList.myBaseToRightChangeList.setChanges(rightChanges);
return mergeList;
}
Aggregations