diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java index 94014c8ed..857c873b9 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java @@ -53,6 +53,7 @@ public abstract class AbstractCodeMapping implements LeafMappingProvider { private int matchingArgumentsWithOperationInvocation; private boolean matchedWithNullReplacements; private Set anonymousClassDiffs = new LinkedHashSet(); + private List lambdaMappers = new ArrayList(); public AbstractCodeMapping(AbstractCodeFragment fragment1, AbstractCodeFragment fragment2, VariableDeclarationContainer operation1, VariableDeclarationContainer operation2) { @@ -106,6 +107,14 @@ public Set getAnonymousClassDiffs() { return anonymousClassDiffs; } + public void addLambdaMappers(List mappers) { + lambdaMappers.addAll(mappers); + } + + public List getLambdaMappers() { + return lambdaMappers; + } + public boolean containsRefactoringOfType(RefactoringType type) { for(Refactoring r : refactorings) { if(r.getRefactoringType().equals(type)) { 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 aff7c7c6a..f5f76b223 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -4140,6 +4140,14 @@ public Set getReplacementsOfType(ReplacementType type) { return replacements; } + public boolean containsLambdaMapper() { + for(AbstractCodeMapping mapping : getMappings()) { + if(mapping.getLambdaMappers().size() > 0 && !mapping.getFragment1().getString().equals(mapping.getFragment2().getString())) + return true; + } + return false; + } + public boolean containsCompositeMappingWithoutReplacements() { for(AbstractCodeMapping mapping : getMappings()) { if(mapping instanceof CompositeStatementObjectMapping && !mapping.getFragment1().equalFragment(mapping.getFragment2()) && mapping.getReplacements().isEmpty()) { @@ -4793,6 +4801,7 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT if(score2 > 0) { CompositeStatementObjectMapping mapping = createCompositeMapping(matchingInnerNode1, statement2, parameterToArgumentMap, score2); mapping.addReplacements(replacements2); + mapping.addLambdaMappers(replacementInfo2.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo2.getSubExpressionMappings()); mappingSet.add(mapping); } @@ -4804,6 +4813,7 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT (score > 0 || Math.max(statement1.getStatements().size(), statement2.getStatements().size()) == 0)) { CompositeStatementObjectMapping mapping = createCompositeMapping(statement1, statement2, parameterToArgumentMap, score); mapping.addReplacements(replacements); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); UMLAbstractClassDiff classDiff = this.classDiff != null ? this.classDiff : parentMapper != null ? parentMapper.classDiff : null; for(AbstractCodeFragment leaf : leaves2) { @@ -4849,6 +4859,7 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT } else if(replacements == null && !containsCallToExtractedMethod && statement1.getLocationInfo().getCodeElementType().equals(statement2.getLocationInfo().getCodeElementType()) && score > 0 && mappingSet.size() > 0 && score >= 2.0*mappingSet.first().getCompositeChildMatchingScore()) { CompositeStatementObjectMapping mapping = createCompositeMapping(statement1, statement2, parameterToArgumentMap, score); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); mappingSet.add(mapping); } @@ -5148,6 +5159,7 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT if(score2 > 0) { CompositeStatementObjectMapping mapping = createCompositeMapping(statement1, matchingInnerNode2, parameterToArgumentMap, score2); mapping.addReplacements(replacements2); + mapping.addLambdaMappers(replacementInfo2.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo2.getSubExpressionMappings()); mappingSet.add(mapping); } @@ -5159,6 +5171,7 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT (score > 0 || Math.max(statement1.getStatements().size(), statement2.getStatements().size()) == 0)) { CompositeStatementObjectMapping mapping = createCompositeMapping(statement1, statement2, parameterToArgumentMap, score); mapping.addReplacements(replacements); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); UMLAbstractClassDiff classDiff = this.classDiff != null ? this.classDiff : parentMapper != null ? parentMapper.classDiff : null; for(AbstractCodeFragment leaf : leaves2) { @@ -5195,6 +5208,7 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT } else if(replacements == null && !containsCallToExtractedMethod && statement1.getLocationInfo().getCodeElementType().equals(statement2.getLocationInfo().getCodeElementType()) && score > 0 && mappingSet.size() > 0 && score >= 2.0*mappingSet.first().getCompositeChildMatchingScore()) { CompositeStatementObjectMapping mapping = createCompositeMapping(statement1, statement2, parameterToArgumentMap, score); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); mappingSet.add(mapping); } @@ -5363,6 +5377,7 @@ else if(comp.getLocationInfo().getCodeElementType().equals(CodeElementType.IF_ST if(score > 0) { CompositeStatementObjectMapping newMapping = createCompositeMapping((CompositeStatementObject)mapping.getFragment1(), innerNode2, parameterToArgumentMap, score); newMapping.addReplacements(replacementInfo.getReplacements()); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); newMapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); addMapping(newMapping); mappingsToBeRemoved.add(mapping); @@ -6221,6 +6236,7 @@ else if(mapping.getFragment1().getLocationInfo().getStartLine() > endMapping.get if (replacements != null) { LeafMapping mapping = createLeafMapping(leaf1, leaf2, parameterToArgumentMap, equalNumberOfAssertions); mapping.addReplacements(replacements); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); extractInlineVariableAnalysis(leaves1, leaves2, leaf1, leaf2, mapping, replacementInfo); mappingSet.add(mapping); @@ -6688,6 +6704,7 @@ else if(mapping.getFragment1().getLocationInfo().getStartLine() > endMapping.get if (replacements != null) { LeafMapping mapping = createLeafMapping(leaf1, leaf2, parameterToArgumentMap, equalNumberOfAssertions); mapping.addReplacements(replacements); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); extractInlineVariableAnalysis(leaves1, leaves2, leaf1, leaf2, mapping, replacementInfo); mappingSet.add(mapping); @@ -7174,6 +7191,7 @@ else if(r1 instanceof MethodInvocationReplacement && r2 instanceof MethodInvocat if(matchingMappings == mappingSet.size() || matchWithLessReplacements || differentVariableDeclarationNumber) { LeafMapping mapping = createLeafMapping(leaf, leaf2, parameterToArgumentMap, equalNumberOfAssertions); mapping.addReplacements(replacements); + mapping.addLambdaMappers(replacementInfo.getLambdaMappers()); mapping.addSubExpressionMappings(replacementInfo.getSubExpressionMappings()); extractInlineVariableAnalysis(leaves1, leaves2, leaf, leaf2, mapping, replacementInfo); mappingSet.add(mapping); @@ -7244,6 +7262,7 @@ private void checkForOtherPossibleMatchesForFragment1(List check(UMLOperation addedOperation) thro return refactorings; } if(!mapper.getNonMappedLeavesT1().isEmpty() || !mapper.getNonMappedInnerNodesT1().isEmpty() || - !mapper.getReplacementsInvolvingMethodInvocation().isEmpty() || mapper.containsCompositeMappingWithoutReplacements()) { + !mapper.getReplacementsInvolvingMethodInvocation().isEmpty() || mapper.containsCompositeMappingWithoutReplacements() || mapper.containsLambdaMapper()) { List addedOperationInvocations = callCountMap != null ? callCountMap.get(addedOperation) : matchingInvocations(addedOperation, operationInvocations, mapper.getContainer2()); if(addedOperationInvocations.size() > 0) { int otherAddedMethodsCalled = 0;