@NotNull public DiffFragment createFragment(@Nullable DiffString text1, @Nullable DiffString text2) { text1 = toNull(text1); text2 = toNull(text2); if (text1 == null && text2 == null) return new DiffFragment(DiffString.EMPTY, DiffString.EMPTY); DiffFragment result = new DiffFragment(text1, text2); if (text1 != null && text2 != null) { result.setModified(!getWrapper(text1).equals(getWrapper(text2))); } return result; }
public void execute() { for (DiffFragment fragment : myFragments) { myContext.myFragment = fragment; process(fragment); DiffString text1 = fragment.getText1(); DiffString text2 = fragment.getText2(); myContext.myStarts[0] += StringUtil.length(text1); myContext.myStarts[1] += StringUtil.length(text2); myContext.myLines[0] += countLines(text1); myContext.myLines[1] += countLines(text2); } }
@Override public void process( @NotNull DiffFragment fragment, @NotNull DiffCorrection.FragmentsCollector collector) { if (fragment.isEqual()) { collector.add(fragment); return; } if (fragment.isOneSide()) { FragmentSide side = FragmentSide.chooseSide(fragment); DiffString text = side.getText(fragment); DiffString trimed = text.trim(); if (trimed.isEmpty()) { collector.add(side.createFragment(text, DiffString.EMPTY, false)); return; } } collector.add(fragment); }
@NotNull @Override public DiffFragment createFragment(@NotNull Word word1, @NotNull Word word2) { DiffString text1 = word1.getText(); DiffString text2 = word2.getText(); return word1.isWhitespace() && word2.isWhitespace() ? DiffFragment.unchanged(text1, text2) : createFragment(text1, text2); }
@NotNull @Override public DiffFragment createFragment(DiffString text1, DiffString text2) { DiffString toCompare1 = toNotNull(text1); DiffString toCompare2 = toNotNull(text2); if (getWrapper(toCompare1).equals(getWrapper(toCompare2))) { return DiffFragment.unchanged(toCompare1, toCompare2); } return new DiffFragment(text1, text2); }
@NotNull @Override public DiffFragment createFragment(@NotNull Word word1, @NotNull Word word2) { DiffString text1 = word1.getText(); DiffString text2 = word2.getText(); if (word1.isWhitespace() && word2.isWhitespace() && word1.atEndOfLine() && word2.atEndOfLine()) { return DiffFragment.unchanged(text1, text2); } return createFragment(text1, text2); }
public boolean isEqual(@NotNull DiffFragment fragment) { if (fragment.isOneSide()) return false; Object[] wrappers = getLineWrappers(new DiffString[] {fragment.getText1(), fragment.getText2()}); return Comparing.equal(wrappers[0], wrappers[1]); }
public static boolean isEmpty(DiffFragment fragment) { return getTextLength(fragment.getText1()) == 0 && getTextLength(fragment.getText2()) == 0; }
static ChangeType fromDiffFragment(DiffFragment fragment) { if (fragment.getText1() == null) return INSERT; if (fragment.getText2() == null) return DELETED; return CHANGE; }