From 713bf73212b13d2866e67e08803a09328284f604 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Wed, 2 Oct 2024 21:36:13 -0400 Subject: [PATCH] Improve comment diff in commit https://github.com/eclipse-jgit/jgit/commit/1b783d037 --- .../uom/java/xmi/diff/UMLCommentListDiff.java | 20 ++++++++++++++++++- ...783d037091266b035e1727db6b6ce7a397ef63.txt | 3 +-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/diff/UMLCommentListDiff.java b/src/main/java/gr/uom/java/xmi/diff/UMLCommentListDiff.java index ad9027e3e..1deb9e5e9 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLCommentListDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLCommentListDiff.java @@ -60,11 +60,29 @@ public UMLCommentListDiff(List commentsBefore, List comm deletedComments.remove(commentBefore); addedComments.remove(commentAfter); } + groupsBeforeToBeRemoved.add(groupBefore); + groupsAfterToBeRemoved.add(groupAfter); + break; + } + } + } + groupsBefore.removeAll(groupsBeforeToBeRemoved); + groupsAfter.removeAll(groupsAfterToBeRemoved); + if(!(allRemainingCommentsBelongToGroups(deletedComments, groupsBefore) && allRemainingCommentsBelongToGroups(addedComments, groupsAfter))) + processRemainingComments(deletedComments, addedComments); + } + + private boolean allRemainingCommentsBelongToGroups(List comments, List groups) { + int matches = 0; + for(UMLComment comment : comments) { + for(UMLCommentGroup group : groups) { + if(group.getGroup().contains(comment) && group.getGroup().size() > 1) { + matches++; break; } } } - processRemainingComments(deletedComments, addedComments); + return matches == comments.size(); } public UMLCommentListDiff(UMLCommentGroup groupBefore, UMLCommentGroup groupAfter) { diff --git a/src/test/resources/mappings/jgit-1b783d037091266b035e1727db6b6ce7a397ef63.txt b/src/test/resources/mappings/jgit-1b783d037091266b035e1727db6b6ce7a397ef63.txt index 482afa92f..20c97e489 100644 --- a/src/test/resources/mappings/jgit-1b783d037091266b035e1727db6b6ce7a397ef63.txt +++ b/src/test/resources/mappings/jgit-1b783d037091266b035e1727db6b6ce7a397ef63.txt @@ -29,5 +29,4 @@ line range:1008-1008==line range:1032-1032 line range:1009-1009==line range:1033-1033 line range:1054-1054==line range:1105-1105 line range:1055-1055==line range:1106-1106 -line range:1056-1056==line range:1107-1107 -line range:1042-1042==line range:1053-1053 \ No newline at end of file +line range:1056-1056==line range:1107-1107 \ No newline at end of file