diff --git a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java index 939acd1d7..3a5613a67 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -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())) { @@ -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 uniqueComments1 = commentListDiff.getDeletedComments(); List uniqueComments2 = commentListDiff.getAddedComments();