diff --git a/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java b/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java index 42a6a6802..ff02c49e0 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java @@ -3268,6 +3268,22 @@ else if(creationCoveringTheEntireStatement2 != null && variableReturn1) { replacementInfo.addReplacement(replacement); } } + if(booleanLiterals1.size() == 1 && statement2.getInfixExpressions().size() == 1) { + boolean returnBoolean1 = statement1.getString().equals(JAVA.RETURN_SPACE + statement1.getBooleanLiterals().get(0).getString() + JAVA.STATEMENT_TERMINATION); + boolean returnInfix2 = statement2.getString().equals(JAVA.RETURN_SPACE + statement2.getInfixExpressions().get(0).getString() + JAVA.STATEMENT_TERMINATION); + if(returnBoolean1 && returnInfix2) { + Replacement replacement = new Replacement(statement1.getBooleanLiterals().get(0).getString(), statement2.getInfixExpressions().get(0).getString(), ReplacementType.BOOLEAN_REPLACED_WITH_INFIX_EXPRESSION); + replacementInfo.addReplacement(replacement); + } + } + if(booleanLiterals2.size() == 1 && statement1.getInfixExpressions().size() == 1) { + boolean returnBoolean2 = statement2.getString().equals(JAVA.RETURN_SPACE + statement2.getBooleanLiterals().get(0).getString() + JAVA.STATEMENT_TERMINATION); + boolean returnInfix1 = statement1.getString().equals(JAVA.RETURN_SPACE + statement1.getInfixExpressions().get(0).getString() + JAVA.STATEMENT_TERMINATION); + if(returnBoolean2 && returnInfix1) { + Replacement replacement = new Replacement(statement1.getInfixExpressions().get(0).getString(), statement2.getBooleanLiterals().get(0).getString(), ReplacementType.BOOLEAN_REPLACED_WITH_INFIX_EXPRESSION); + replacementInfo.addReplacement(replacement); + } + } return replacementInfo.getReplacements(); } } 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 a46e036eb..85c0f447d 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -517,7 +517,8 @@ else if(streamAPIStatements1.size() > 0 && streamAPIStatements2.size() == 0) { } } if(remainingUnmatchedIfStatements1 > 0 && mapping instanceof LeafMapping && mapping.getFragment1().getTernaryOperatorExpressions().size() == 0 && - mapping.getFragment2().getTernaryOperatorExpressions().size() > 0 && !leaves2.contains(mapping.getFragment2())) { + (mapping.getFragment2().getTernaryOperatorExpressions().size() > 0 || mapping.getFragment2().getString().contains(" == ") || mapping.getFragment2().getString().contains(" != ")) && + !leaves2.contains(mapping.getFragment2())) { leaves2.add(mapping.getFragment2()); //remove from hashCodes, so that it can be re-matched mappingHashcodesT2.remove(mapping.getFragment2().hashCode()); @@ -7481,7 +7482,8 @@ private boolean canBeAdded(LeafMapping minStatementMapping, Map for(AbstractCodeMapping mapping : mappings) { if(mapping.getFragment1().equals(minStatementMapping.getFragment1()) || mapping.getFragment2().equals(minStatementMapping.getFragment2())) { - conflictingMappingFound = true; + if(newMappingReplacents > 0) + conflictingMappingFound = true; int oldMappingReplacements = validReplacements(mapping, parameterToArgumentMap); if(newMappingReplacents < oldMappingReplacements) { mappingToBeRemoved = mapping; @@ -7503,6 +7505,9 @@ private int validReplacements(AbstractCodeMapping mapping, Map p for(Replacement r : mapping.getReplacements()) { if(parameterToArgumentMap.containsKey(r.getAfter()) && parameterToArgumentMap.get(r.getAfter()).equals(r.getBefore())) { + } + else if(r.getType().equals(ReplacementType.INFIX_OPERATOR)) { + } else { validReplacements++; diff --git a/src/main/java/gr/uom/java/xmi/decomposition/replacement/Replacement.java b/src/main/java/gr/uom/java/xmi/decomposition/replacement/Replacement.java index 5f08e50d4..acb62a2cd 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/replacement/Replacement.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/replacement/Replacement.java @@ -88,6 +88,7 @@ public enum ReplacementType { VARIABLE_DECLARATION_INITIALIZER, BOOLEAN_REPLACED_WITH_VARIABLE, BOOLEAN_REPLACED_WITH_PREFIX_EXPRESSION, + BOOLEAN_REPLACED_WITH_INFIX_EXPRESSION, BOOLEAN_REPLACED_WITH_ARGUMENT, TYPE_LITERAL_REPLACED_WITH_VARIABLE, STRING_LITERAL_REPLACED_WITH_CHAR_LITERAL,