Skip to content

Commit 394affa

Browse files
committed
Improved matching of re-formatted group-comments (#976)
JabRef/jabref-koppor#716 jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
1 parent e8d8205 commit 394affa

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ else if(other.group.size() < this.group.size() && other.group.size() > 1) {
6565
return false;
6666
}
6767

68-
public boolean modifiedMatchingText(UMLCommentGroup other) {
68+
public UMLCommentListDiff modifiedMatchingText(UMLCommentGroup other) {
6969
if(this.group.size() == other.group.size() && this.group.size() > 1) {
7070
UMLCommentListDiff diff = new UMLCommentListDiff(this, other);
7171
if(diff.getCommonComments().size() == this.group.size()) {
72-
return true;
72+
return diff;
7373
}
7474
}
75-
return false;
75+
else if(this.group.size() != other.group.size() && this.group.size() > 1) {
76+
UMLCommentListDiff diff = new UMLCommentListDiff(this, other);
77+
if(diff.isManyToManyReformat()) {
78+
return diff;
79+
}
80+
}
81+
return null;
7682
}
7783
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ private void init(List<UMLComment> commentsBefore, List<UMLComment> commentsAfte
102102
groupsAfter.removeAll(groupsAfterToBeRemoved);
103103
for(UMLCommentGroup groupBefore : groupsBefore) {
104104
for(UMLCommentGroup groupAfter : groupsAfter) {
105-
if(groupBefore.modifiedMatchingText(groupAfter) && !groupsAfterToBeRemoved.contains(groupAfter)) {
106-
for(int i=0; i<groupBefore.getGroup().size(); i++) {
107-
UMLComment commentBefore = groupBefore.getGroup().get(i);
108-
UMLComment commentAfter = groupAfter.getGroup().get(i);
109-
Pair<UMLComment, UMLComment> pair = Pair.of(commentBefore, commentAfter);
110-
commonComments.add(pair);
111-
deletedComments.remove(commentBefore);
112-
addedComments.remove(commentAfter);
105+
if(!groupsAfterToBeRemoved.contains(groupAfter)) {
106+
UMLCommentListDiff diff = groupBefore.modifiedMatchingText(groupAfter);
107+
if(diff != null) {
108+
for(Pair<UMLComment, UMLComment> pair : diff.getCommonComments()) {
109+
commonComments.add(pair);
110+
deletedComments.remove(pair.getLeft());
111+
addedComments.remove(pair.getRight());
112+
}
113+
groupsBeforeToBeRemoved.add(groupBefore);
114+
groupsAfterToBeRemoved.add(groupAfter);
115+
break;
113116
}
114-
groupsBeforeToBeRemoved.add(groupBefore);
115-
groupsAfterToBeRemoved.add(groupAfter);
116-
break;
117117
}
118118
}
119119
}

0 commit comments

Comments
 (0)