From 2df6c3ee2e87a7eae0e306a1813697a8ecc57940 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Fri, 17 Jan 2025 09:27:53 -0500 Subject: [PATCH] Fix expansion of lambdas in assertTimeout scenarios async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java https://github.com/iluwatar/java-design-patterns/commit/6694d742a370e0f181530734481284de8d5dd8ef --- .../decomposition/UMLOperationBodyMapper.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 8811d4c76..8c1c7eb3a 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -274,6 +274,19 @@ public UMLOperationBodyMapper(UMLOperationBodyMapper mapper1, UMLOperation added } } + private static boolean containsAll(LambdaExpressionObject bigLambda, List small) { + int count = 0; + for(LambdaExpressionObject lambda : small) { + for(LambdaExpressionObject nestedLambda : bigLambda.getAllLambdas()) { + if(nestedLambda.getString().equals(lambda.getString())) { + count++; + break; + } + } + } + return count == small.size(); + } + public UMLOperationBodyMapper(UMLOperation operation1, UMLOperation operation2, UMLAbstractClassDiff classDiff) throws RefactoringMinerTimedOutException { this.classDiff = classDiff; this.modelDiff = classDiff != null ? classDiff.getModelDiff() : null; @@ -478,7 +491,7 @@ else if(statement1.getString().equals(list2.get(i))) { expandAnonymousAndLambdas(anonymousFragment, leaves1, innerNodes1, new LinkedHashSet<>(), new LinkedHashSet<>(), anonymousClassList1(), codeFragmentOperationMap1, operation1, true); } } - else if(lambdas1.size() == 1 && anonymous2.size() == 0 && lambdas2.size() == 0) { + else if(anonymous2.size() == 0 && ((lambdas1.size() == 1 && lambdas2.size() == 0) || (lambdas1.size() == 1 && containsAll(lambdas1.get(0), lambdas2)))) { AbstractCodeFragment lambdaFragment = null; for(AbstractCodeFragment leaf1 : leaves1) { if(leaf1.getLambdas().size() > 0) { @@ -505,7 +518,7 @@ else if((anonymous1.size() == 0 && anonymous2.size() == 1) || expandAnonymousAndLambdas(anonymousFragment, leaves2, innerNodes2, new LinkedHashSet<>(), new LinkedHashSet<>(), anonymousClassList2(), codeFragmentOperationMap2, operation2, true); } } - else if(anonymous1.size() == 0 && lambdas1.size() == 0 && lambdas2.size() == 1) { + else if(anonymous1.size() == 0 && ((lambdas1.size() == 0 && lambdas2.size() == 1) || (lambdas2.size() == 1 && containsAll(lambdas2.get(0), lambdas1)))) { AbstractCodeFragment lambdaFragment = null; for(AbstractCodeFragment leaf2 : leaves2) { if(leaf2.getLambdas().size() > 0) {