Skip to content

Commit 7d5bf99

Browse files
committed
Fixes #103 by partitioning important and non-important changes
1 parent 54eed82 commit 7d5bf99

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

BEXCodeCompare/src/test/java/info/codesaway/bex/diff/DiffHelperTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import info.codesaway.bex.diff.myers.MyersLinearDiff;
3131
import info.codesaway.bex.diff.patience.PatienceDiff;
3232
import info.codesaway.bex.diff.patience.PatienceMatch;
33+
import info.codesaway.bex.diff.substitution.SubstitutionDiffTypeValue;
3334

3435
class DiffHelperTests {
3536

@@ -165,6 +166,34 @@ public void testNeverCombineToDiffBlocks() {
165166
assertEquals(expected, diffUnits);
166167
}
167168

169+
@Test
170+
// Issue #103
171+
public void testCombineToDiffBlocksPartitionImportantAndNonImportantChanges() {
172+
// Text doesn't matter, since combine focuses on DiffType
173+
List<DiffLine> leftLines = ImmutableList.of(new DiffLine(0, ""), new DiffLine(1, ""), new DiffLine(2, ""),
174+
new DiffLine(3, ""));
175+
List<DiffLine> rightLines = ImmutableList.of(new DiffLine(0, ""), new DiffLine(1, ""), new DiffLine(2, ""),
176+
new DiffLine(3, ""));
177+
178+
DiffType shouldTreatAsNormalizedEqual = new SubstitutionDiffTypeValue(' ', "", false, true);
179+
180+
DiffEdit first = new DiffEdit(INSERT, leftLines.get(0), rightLines.get(0));
181+
DiffEdit second = new DiffEdit(shouldTreatAsNormalizedEqual, leftLines.get(1), rightLines.get(1));
182+
DiffEdit third = new DiffEdit(shouldTreatAsNormalizedEqual, leftLines.get(2), rightLines.get(2));
183+
DiffEdit fourth = new DiffEdit(INSERT, leftLines.get(3), rightLines.get(3));
184+
185+
List<DiffEdit> diff = ImmutableList.of(first, second, third, fourth);
186+
187+
List<DiffUnit> diffUnits = DiffHelper.combineToDiffBlocks(diff, true,
188+
(x, y) -> x.shouldTreatAsNormalizedEqual() == y.shouldTreatAsNormalizedEqual());
189+
190+
List<DiffUnit> expected = ImmutableList.of(first,
191+
new DiffBlock(shouldTreatAsNormalizedEqual, diff.subList(1, 3)),
192+
fourth);
193+
194+
assertEquals(expected, diffUnits);
195+
}
196+
168197
@Test
169198
public void testDetermineEnclosedRange() {
170199
List<DiffLine> leftLines = ImmutableList.of(new DiffLine(0, "a"), new DiffLine(1, "b"), new DiffLine(2, "c"));

BEXCodeCompare/src/test/java/info/codesaway/bex/matching/BEXParseJSPTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import static info.codesaway.bex.IntBEXRange.closed;
44
import static info.codesaway.bex.IntBEXRange.closedOpen;
5+
import static info.codesaway.bex.IntBEXRange.singleton;
56
import static info.codesaway.bex.matching.BEXMatchingStateOption.IN_EXPRESSION_BLOCK;
67
import static info.codesaway.bex.matching.BEXMatchingStateOption.IN_STRING_LITERAL;
8+
import static info.codesaway.bex.matching.BEXMatchingStateOption.IN_TAG;
79
import static info.codesaway.bex.util.BEXUtilities.entry;
810
import static org.assertj.core.api.Assertions.assertThat;
911

@@ -16,10 +18,14 @@ void testExpressionEndsThenAnotherImmediatelyStarts() {
1618
BEXString bexString = new BEXString(text, BEXMatchingLanguage.JSP);
1719

1820
assertThat(bexString.getTextStateMap().asMapOfRanges())
19-
.containsExactly(entry(closedOpen(8, 9), IN_STRING_LITERAL),
21+
.containsExactly(
22+
entry(closedOpen(0, 8), IN_TAG),
23+
entry(closedOpen(8, 9), IN_STRING_LITERAL),
2024
entry(closed(9, 20), IN_EXPRESSION_BLOCK),
2125
entry(closed(21, 33), IN_EXPRESSION_BLOCK),
22-
entry(closed(34, 34), IN_STRING_LITERAL),
23-
entry(closed(36, 47), IN_EXPRESSION_BLOCK));
26+
entry(singleton(34), IN_STRING_LITERAL),
27+
entry(singleton(35), IN_TAG),
28+
entry(closed(36, 47), IN_EXPRESSION_BLOCK),
29+
entry(closed(48, 51), IN_TAG));
2430
}
2531
}

BEXCodeComparePlugin/src/info/codesaway/bex/compare/RangeComparatorBEX.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ private void computeDifferences(final SubMonitor newChild, final boolean updateV
234234
// (if true, okay to combine using existing logic)
235235
// (if false, should never combine, even if current logic would allow)
236236
// This way, can ensure we don't combine unimportant refactorings in the same change as important changes
237-
List<DiffUnit> diffBlocks = DiffHelper.combineToDiffBlocks(diff, true);
237+
List<DiffUnit> diffBlocks = DiffHelper.combineToDiffBlocks(diff, true,
238+
// Fixes issue #103 - only combine if both diffs either should or should not
239+
// (what was happening was it was combining non-important changes with important changes)
240+
// (this caused Eclipse to show more differences than expected)
241+
(x, y) -> x.shouldTreatAsNormalizedEqual() == y.shouldTreatAsNormalizedEqual());
238242
// List<DiffUnit> diffBlocks = DiffHelper.combineToDiffBlocks(diff, false);
239243

240244
// Handle ignoring blank lines or comments (if option is enabled)

0 commit comments

Comments
 (0)