Skip to content

Commit 6ff6c97

Browse files
crosscross
authored andcommitted
Better handling of ignored comments in plugin
BEX Eclipse plugin scrolling improvements
1 parent e13b4ec commit 6ff6c97

File tree

11 files changed

+362
-39
lines changed

11 files changed

+362
-39
lines changed

BEXCodeCompare/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>info.codesaway</groupId>
66
<artifactId>bex</artifactId>
7-
<version>0.11.0</version>
7+
<version>0.12.0</version>
88
<name>Be Enhanced Code Compare (BEϽC)</name>
99
<description>An enhanced code compare, utilities, and code matching</description>
1010
<properties>

BEXCodeCompare/src/main/java/info/codesaway/bex/IntBEXRange.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public static IntBEXRange closedOpen(final int start, final int end) {
8080
return new IntBEXRange(start, end, false);
8181
}
8282

83+
/**
84+
* Closed range containing a single value
85+
* @param value the value
86+
* @return a closed range containing a single value
87+
* @since 0.12
88+
* @see #closed(int, int)
89+
*/
90+
public static IntBEXRange singleton(final int value) {
91+
return closed(value, value);
92+
}
93+
8394
@Override
8495
public boolean hasInclusiveStart() {
8596
return this.hasInclusiveStart;

BEXCodeCompare/src/main/java/info/codesaway/bex/diff/DiffHelper.java

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package info.codesaway.bex.diff;
22

3+
import static info.codesaway.bex.BEXPairs.bexPair;
34
import static info.codesaway.bex.BEXPairs.mapGet;
45
import static info.codesaway.bex.BEXSide.BEX_SIDES;
56
import static info.codesaway.bex.BEXSide.LEFT;
67
import static info.codesaway.bex.BEXSide.RIGHT;
8+
import static info.codesaway.bex.IntBEXRange.closed;
79
import static info.codesaway.bex.diff.BasicDiffType.REPLACEMENT_BLOCK;
810
import static info.codesaway.bex.util.BEXUtilities.firstNonNull;
911
import static info.codesaway.bex.util.BEXUtilities.not;
@@ -38,6 +40,7 @@
3840
import info.codesaway.bex.BEXPairValue;
3941
import info.codesaway.bex.BEXSide;
4042
import info.codesaway.bex.IntPair;
43+
import info.codesaway.bex.IntRange;
4144
import info.codesaway.bex.diff.patience.FrequencyCount;
4245
import info.codesaway.bex.diff.patience.PatienceMatch;
4346
import info.codesaway.bex.diff.substitution.RefactoringDiffType;
@@ -268,35 +271,35 @@ public static List<DiffEdit> handleImports(final List<DiffEdit> diff) {
268271
.filter(DiffWithIndex::isInsertOrDelete)
269272
.filter(d -> d.getDiffEdit().getText().trim().startsWith("import"))
270273
.collect(toList());
271-
274+
272275
// Group imports by classname
273276
Map<String, List<DiffWithIndex>> importsByClassName = new HashMap<>();
274277
Map<DiffWithIndex, MatchResult> matchResults = new HashMap<>();
275-
278+
276279
for (DiffWithIndex possibleImport : possibleImports) {
277280
Matcher matcher = IMPORT_MATCHER.get().reset(possibleImport.getDiffEdit().getText());
278-
281+
279282
if (!matcher.find()) {
280283
continue;
281284
}
282-
285+
283286
matchResults.put(possibleImport, matcher.toMatchResult());
284287
importsByClassName.computeIfAbsent(matcher.group("class"), k -> new ArrayList<>()).add(possibleImport);
285288
}
286-
289+
287290
// Check results
288291
for (Entry<String, List<DiffWithIndex>> entry : importsByClassName.entrySet()) {
289292
List<DiffWithIndex> list = entry.getValue();
290293
if (list.size() != 2) {
291294
continue;
292295
}
293-
296+
294297
DiffWithIndex firstDiff = list.get(0);
295298
DiffWithIndex secondDiff = list.get(1);
296-
299+
297300
DiffWithIndex left = null;
298301
DiffWithIndex right = null;
299-
302+
300303
if (firstDiff.hasLeftLine()) {
301304
if (secondDiff.hasRightLine()) {
302305
left = firstDiff;
@@ -306,21 +309,21 @@ public static List<DiffEdit> handleImports(final List<DiffEdit> diff) {
306309
left = secondDiff;
307310
right = firstDiff;
308311
}
309-
312+
310313
if (left != null && right != null) {
311314
ImportSameClassnameDiffType diffType = determineImportSameClassnameDiffType(matchResults.get(left),
312315
matchResults.get(right), true);
313-
316+
314317
// System.out.println(entry);
315-
318+
316319
if (diffType != null) {
317320
DiffEdit diffEdit = new DiffEdit(diffType, left.getLeftLine(), right.getRightLine());
318321
diff.set(left.getIndex(), diffEdit);
319322
diff.set(right.getIndex(), diffEdit);
320323
}
321324
}
322325
}
323-
326+
324327
return diff;
325328
}*/
326329

@@ -904,6 +907,58 @@ private static List<DiffEdit> sort(final List<DiffEdit> diff) {
904907
return results;
905908
}
906909

910+
/**
911+
* Determines the range which encloses all the lines of the specified DiffUnit
912+
*
913+
* <p>If the DiffUnit does not consist of sequential lines, the range will enclose all the lines,
914+
* even though each value in the range will not have a corresponding line in the DiffUnit</p>
915+
*
916+
* @param diffUnit the DiffUnit
917+
* @return the range of lines (left / right) in the specified DiffUnit
918+
* @since 0.12
919+
*/
920+
public static BEXPair<IntRange> determineEnclosedRange(final DiffUnit diffUnit) {
921+
return determineEnclosedRange(diffUnit.getEdits());
922+
}
923+
924+
/**
925+
* Determines the range which encloses all the lines of the specified edits
926+
*
927+
* <p>If the edits do not consist of sequential lines, the range will enclose all the lines,
928+
* even though each value in the range will not have a corresponding line in the edits</p>
929+
*
930+
* @param diffEdits the edits
931+
* @return the range of lines (left / right) in the specified edits
932+
* @since 0.12
933+
*/
934+
public static BEXPair<IntRange> determineEnclosedRange(final Collection<DiffEdit> diffEdits) {
935+
int minLeft = diffEdits.stream()
936+
.filter(DiffEdit::hasLeftLine)
937+
.mapToInt(DiffEdit::getLeftLineNumber)
938+
.min()
939+
.orElse(-1);
940+
941+
int maxLeft = diffEdits.stream()
942+
.filter(DiffEdit::hasLeftLine)
943+
.mapToInt(DiffEdit::getLeftLineNumber)
944+
.max()
945+
.orElse(-1);
946+
947+
int minRight = diffEdits.stream()
948+
.filter(DiffEdit::hasRightLine)
949+
.mapToInt(DiffEdit::getRightLineNumber)
950+
.min()
951+
.orElse(-1);
952+
953+
int maxRight = diffEdits.stream()
954+
.filter(DiffEdit::hasRightLine)
955+
.mapToInt(DiffEdit::getRightLineNumber)
956+
.max()
957+
.orElse(-1);
958+
959+
return bexPair(closed(minLeft, maxLeft), closed(minRight, maxRight));
960+
}
961+
907962
/**
908963
* Combines consecutive DiffEdit to form DiffBlock when possible
909964
*

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package info.codesaway.bex.diff;
22

33
import static com.google.common.collect.Maps.immutableEntry;
4+
import static info.codesaway.bex.BEXPairs.bexPair;
5+
import static info.codesaway.bex.IntBEXRange.closed;
46
import static info.codesaway.bex.diff.BasicDiffType.DELETE;
57
import static info.codesaway.bex.diff.BasicDiffType.EQUAL;
68
import static info.codesaway.bex.diff.BasicDiffType.INSERT;
79
import static info.codesaway.bex.diff.BasicDiffType.MOVE_LEFT;
810
import static info.codesaway.bex.diff.BasicDiffType.MOVE_RIGHT;
11+
import static org.assertj.core.api.Assertions.assertThat;
912
import static org.junit.jupiter.api.Assertions.assertEquals;
1013

1114
import java.util.Arrays;
1215
import java.util.List;
1316
import java.util.Map.Entry;
1417

18+
import org.junit.jupiter.api.Disabled;
1519
import org.junit.jupiter.api.Test;
1620
import org.junit.jupiter.params.ParameterizedTest;
1721
import org.junit.jupiter.params.provider.MethodSource;
@@ -20,6 +24,9 @@
2024
import com.google.common.collect.Streams;
2125
import com.google.common.primitives.ImmutableIntArray;
2226

27+
import info.codesaway.bex.BEXPair;
28+
import info.codesaway.bex.IntBEXPair;
29+
import info.codesaway.bex.IntRange;
2330
import info.codesaway.bex.diff.myers.MyersLinearDiff;
2431
import info.codesaway.bex.diff.patience.PatienceDiff;
2532
import info.codesaway.bex.diff.patience.PatienceMatch;
@@ -119,4 +126,38 @@ public void testCombineToDiffBlocks() {
119126

120127
assertEquals(expected, diffUnits);
121128
}
129+
130+
@Test
131+
public void testDetermineEnclosedRange() {
132+
List<DiffLine> leftLines = ImmutableList.of(new DiffLine(0, "a"), new DiffLine(1, "b"), new DiffLine(2, "c"));
133+
List<DiffLine> rightLines = ImmutableList.of(new DiffLine(3, "a"), new DiffLine(4, "b"), new DiffLine(5, "c"));
134+
135+
List<DiffEdit> diff = ImmutableList.of(
136+
new DiffEdit(MOVE_LEFT, leftLines.get(0), rightLines.get(0)),
137+
new DiffEdit(MOVE_LEFT, leftLines.get(1), rightLines.get(1)),
138+
new DiffEdit(MOVE_LEFT, leftLines.get(2), rightLines.get(2)));
139+
140+
List<DiffUnit> diffUnits = DiffHelper.combineToDiffBlocks(diff);
141+
142+
DiffUnit diffUnit = diffUnits.get(0);
143+
144+
BEXPair<IntRange> enclosedRange = DiffHelper.determineEnclosedRange(diffUnit);
145+
BEXPair<IntRange> expectedRange = bexPair(closed(0, 2), closed(3, 5));
146+
assertThat(enclosedRange).isEqualTo(expectedRange);
147+
}
148+
149+
@Test
150+
@Disabled("Not sure if I plan or need to add functionality for consecutive ranges")
151+
public void testHasConsecutiveRanges() {
152+
IntRange left1 = closed(0, 2);
153+
IntRange left2 = closed(3, 5);
154+
155+
IntRange right1 = closed(1, 5);
156+
IntRange right2 = closed(6, 10);
157+
158+
IntBEXPair line1 = IntBEXPair.of(left1.getEnd(), right1.getEnd());
159+
IntBEXPair line2 = IntBEXPair.of(left2.getStart(), right2.getStart());
160+
161+
System.out.println(DiffHelper.isConsecutive(line1, line2, false));
162+
}
122163
}

BEXCodeComparePlugin/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
55
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
66
<classpathentry kind="src" path="src"/>
7-
<classpathentry kind="lib" path="lib/bex.jar"/>
7+
<classpathentry kind="lib" path="lib/bex.jar" sourcepath="/BEXCodeCompare"/>
88
<classpathentry kind="output" path="bin"/>
99
</classpath>

0 commit comments

Comments
 (0)