Search in sources :

Example 1 with ContextLogger

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;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) ContextLogger(com.intellij.openapi.diff.impl.util.ContextLogger) ArrayList(java.util.ArrayList) DiffString(com.intellij.openapi.diff.impl.string.DiffString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffString (com.intellij.openapi.diff.impl.string.DiffString)1 ContextLogger (com.intellij.openapi.diff.impl.util.ContextLogger)1 FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)1 ArrayList (java.util.ArrayList)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1