Skip to content

Commit fae5c6a

Browse files
committed
Fix for failing tests. Improve comment mappings (#976)
JabRef/jabref-koppor#716 jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java within method addSelectedEntries()
1 parent 394affa commit fae5c6a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/gr/uom/java/xmi/UMLCommentGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public UMLCommentListDiff modifiedMatchingText(UMLCommentGroup other) {
7474
}
7575
else if(this.group.size() != other.group.size() && this.group.size() > 1) {
7676
UMLCommentListDiff diff = new UMLCommentListDiff(this, other);
77-
if(diff.isManyToManyReformat()) {
77+
if(diff.isManyToManyReformat() && diff.getDeletedComments().isEmpty() && diff.getAddedComments().isEmpty()) {
7878
return diff;
7979
}
8080
}

src/main/java/gr/uom/java/xmi/diff/UMLCommentListDiff.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,16 @@ private void processRemainingComments(List<UMLComment> commentsBefore, List<UMLC
280280
List<Integer> matchingIndices = findAllMatchingIndices(commentsAfter, comment);
281281
List<Boolean> mappedParent = new ArrayList<Boolean>();
282282
List<Boolean> mappedPreviousStatement = new ArrayList<Boolean>();
283+
List<Boolean> identicalNextComment = new ArrayList<Boolean>();
283284
if(matchingIndices.size() > 1) {
284285
for(Integer index : matchingIndices) {
285286
mappedParent.add(mappedParent(comment, commentsAfter.get(index)));
286287
mappedPreviousStatement.add(mappedPreviousStatement(comment, commentsAfter.get(index)));
288+
if(commentsBefore.indexOf(comment) < commentsBefore.size() - 1 && index < commentsAfter.size() - 1) {
289+
UMLComment commentAfterLeft = commentsBefore.get(commentsBefore.indexOf(comment)+1);
290+
UMLComment commentAfterRight = commentsAfter.get(index + 1);
291+
identicalNextComment.add(commentAfterLeft.getFullText().equals(commentAfterRight.getFullText()));
292+
}
287293
}
288294
}
289295
int i = -1;
@@ -296,6 +302,9 @@ private void processRemainingComments(List<UMLComment> commentsBefore, List<UMLC
296302
if(mappedPreviousStatement.contains(true) && mappedPreviousStatement.get(i) == false) {
297303
continue;
298304
}
305+
if(identicalNextComment.contains(true) && identicalNextComment.get(i) == false) {
306+
continue;
307+
}
299308
Pair<UMLComment, UMLComment> pair = Pair.of(comment, commentsAfter.get(index));
300309
commonComments.add(pair);
301310
deletedComments.remove(comment);
@@ -310,10 +319,16 @@ private void processRemainingComments(List<UMLComment> commentsBefore, List<UMLC
310319
List<Integer> matchingIndices = findAllMatchingIndices(commentsBefore, comment);
311320
List<Boolean> mappedParent = new ArrayList<Boolean>();
312321
List<Boolean> mappedPreviousStatement = new ArrayList<Boolean>();
322+
List<Boolean> identicalNextComment = new ArrayList<Boolean>();
313323
if(matchingIndices.size() > 1) {
314324
for(Integer index : matchingIndices) {
315325
mappedParent.add(mappedParent(commentsBefore.get(index), comment));
316326
mappedPreviousStatement.add(mappedPreviousStatement(commentsBefore.get(index), comment));
327+
if(commentsAfter.indexOf(comment) < commentsAfter.size() - 1 && index < commentsBefore.size() - 1) {
328+
UMLComment commentAfterLeft = commentsBefore.get(index + 1);
329+
UMLComment commentAfterRight = commentsAfter.get(commentsAfter.indexOf(comment)+1);
330+
identicalNextComment.add(commentAfterLeft.getFullText().equals(commentAfterRight.getFullText()));
331+
}
317332
}
318333
}
319334
int i = -1;
@@ -326,6 +341,9 @@ private void processRemainingComments(List<UMLComment> commentsBefore, List<UMLC
326341
if(mappedPreviousStatement.contains(true) && mappedPreviousStatement.get(i) == false) {
327342
continue;
328343
}
344+
if(identicalNextComment.contains(true) && identicalNextComment.get(i) == false) {
345+
continue;
346+
}
329347
Pair<UMLComment, UMLComment> pair = Pair.of(commentsBefore.get(index), comment);
330348
commonComments.add(pair);
331349
deletedComments.remove(commentsBefore.get(index));

0 commit comments

Comments
 (0)