Skip to content

Commit

Permalink
Fix comment mappings for commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 4, 2024
1 parent 90da06f commit 4b658cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/main/java/gr/uom/java/xmi/UMLComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.decomposition.CompositeStatementObject;
import gr.uom.java.xmi.decomposition.TryStatementObject;

import static gr.uom.java.xmi.Constants.JAVA;

Expand Down Expand Up @@ -94,4 +95,19 @@ public boolean isCommentedCode() {
}
return false;
}

public boolean nestedInCatchBlock() {
if(parent != null && parent.getLocationInfo().getCodeElementType().equals(CodeElementType.TRY_STATEMENT)) {
TryStatementObject tryParent = (TryStatementObject)parent;
for(CompositeStatementObject catchClause : tryParent.getCatchClauses()) {
if(catchClause.getLocationInfo().subsumes(this.getLocationInfo()))
return true;
}
if(tryParent.getFinallyClause() != null) {
if(tryParent.getFinallyClause().getLocationInfo().subsumes(this.getLocationInfo()))
return true;
}
}
return false;
}
}
4 changes: 2 additions & 2 deletions src/main/java/gr/uom/java/xmi/diff/UMLCommentListDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private void processRemainingComments(List<UMLComment> commentsBefore, List<UMLC
for(Pair<UMLComment, UMLComment> pair : commonComments) {
if(pair.getLeft().getText().equals(deletedComment.getText()) &&
pair.getRight().getText().equals(deletedComment.getText()) &&
!deletedComment.isCommentedCode()) {
!deletedComment.isCommentedCode() && !deletedComment.nestedInCatchBlock()) {
Pair<UMLComment, UMLComment> newPair = Pair.of(deletedComment, pair.getRight());
commonComments.add(newPair);
deletedComments.remove(deletedComment);
Expand All @@ -228,7 +228,7 @@ private void processRemainingComments(List<UMLComment> commentsBefore, List<UMLC
for(Pair<UMLComment, UMLComment> pair : commonComments) {
if(pair.getLeft().getText().equals(addedComment.getText()) &&
pair.getRight().getText().equals(addedComment.getText()) &&
!addedComment.isCommentedCode()) {
!addedComment.isCommentedCode() && !addedComment.nestedInCatchBlock()) {
Pair<UMLComment, UMLComment> newPair = Pair.of(pair.getLeft(), addedComment);
commonComments.add(newPair);
addedComments.remove(addedComment);
Expand Down

0 comments on commit 4b658cb

Please sign in to comment.