Skip to content

Commit

Permalink
Avoid removal of mapping walker.sort(RevSort.TOPO); in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 28, 2024
1 parent 50c3705 commit 965c928
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ else if(parent1.getStatements().size() > 0 && containsMapping(parent1.getStateme
int indexOfChildInParent2 = parent2.getStatements().indexOf(child2);
if(indexOfChildInParent1 != indexOfChildInParent2 &&
!isElseBranch(child1, parent1) && !isElseBranch(child2, parent2) &&
!elseWithoutBlockBecomingElseWithBlock(parent1, parent2) &&
!isTryBlock(child1, parent1) && !isTryBlock(child2, parent2) &&
!isFinallyBlock(child1, parent1) && !isFinallyBlock(child2, parent2) &&
!ifAddingElseIf(parent1.getParent()) && !ifAddingElseIf(parent2.getParent())) {
Expand Down Expand Up @@ -987,6 +988,26 @@ else if(mapping instanceof CompositeStatementObjectMapping) {
checkUnmatchedStatementsBeingCommented();
}

private boolean elseWithoutBlockBecomingElseWithBlock(CompositeStatementObject parent1, CompositeStatementObject parent2) {
if(parent1.getLocationInfo().getCodeElementType().equals(CodeElementType.IF_STATEMENT) && parent2.getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK)) {
CompositeStatementObject grandParent2 = parent2.getParent();
for(AbstractCodeMapping mapping : this.mappings) {
if(mapping.getFragment1().equals(parent1) && mapping.getFragment2().equals(grandParent2)) {
return true;
}
}
}
else if(parent2.getLocationInfo().getCodeElementType().equals(CodeElementType.IF_STATEMENT) && parent1.getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK)) {
CompositeStatementObject grandParent1 = parent1.getParent();
for(AbstractCodeMapping mapping : this.mappings) {
if(mapping.getFragment1().equals(grandParent1) && mapping.getFragment2().equals(parent2)) {
return true;
}
}
}
return false;
}

private void checkUnmatchedStatementsBeingCommented() {
List<UMLComment> uniqueComments1 = commentListDiff.getDeletedComments();
List<UMLComment> uniqueComments2 = commentListDiff.getAddedComments();
Expand Down

0 comments on commit 965c928

Please sign in to comment.