From 8e8c08767caaa74f315f65c421cbfeaa10a10114 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sun, 5 Jan 2025 15:01:59 -0500 Subject: [PATCH] Fix for issue #88 --- .../cfg/mapping/PreconditionExaminer.java | 6 ++-- .../manipulators/ExtractCloneRefactoring.java | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gr/uom/java/ast/decomposition/cfg/mapping/PreconditionExaminer.java b/src/gr/uom/java/ast/decomposition/cfg/mapping/PreconditionExaminer.java index 43e59fd25..4eba66a7e 100644 --- a/src/gr/uom/java/ast/decomposition/cfg/mapping/PreconditionExaminer.java +++ b/src/gr/uom/java/ast/decomposition/cfg/mapping/PreconditionExaminer.java @@ -2419,8 +2419,10 @@ else if(methods1.size() == 1 && methods2.size() == 1) { checkIfStatementIsSuperConstructorInvocation(nodeMapping, nodeMapping.getNodeG2()); checkIfStatementIsThisConstructorInvocation(nodeMapping, nodeMapping.getNodeG1()); checkIfStatementIsThisConstructorInvocation(nodeMapping, nodeMapping.getNodeG2()); - checkIfStatementContainsSuperMethodInvocation(nodeMapping, nodeMapping.getNodeG1()); - checkIfStatementContainsSuperMethodInvocation(nodeMapping, nodeMapping.getNodeG2()); + if(!iCompilationUnit1.equals(iCompilationUnit2)) { + checkIfStatementContainsSuperMethodInvocation(nodeMapping, nodeMapping.getNodeG1()); + checkIfStatementContainsSuperMethodInvocation(nodeMapping, nodeMapping.getNodeG2()); + } //skip examining the conditional return precondition, if the number of examined nodes is equal to the number of PDG nodes if(getAllNodesInSubTreePDG1().size() != pdg1.getNodes().size()) { conditionalReturnStatement(nodeMapping, nodeMapping.getNodeG1()); diff --git a/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java b/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java index f6469b7c1..56b9a51ab 100644 --- a/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java +++ b/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractCloneRefactoring.java @@ -3825,15 +3825,28 @@ else if(oldASTNode instanceof Statement) { SuperMethodInvocation oldSuperMethodInvocation = (SuperMethodInvocation)oldExpression; SuperMethodInvocation newSuperMethodInvocation = (SuperMethodInvocation)newSuperMethodInvocations.get(j); if(oldSuperMethodInvocation.resolveMethodBinding().getDeclaringClass().isEqualTo(commonSuperTypeOfSourceTypeDeclarations)) { - MethodInvocation newMethodInvocation = ast.newMethodInvocation(); - sourceRewriter.set(newMethodInvocation, MethodInvocation.NAME_PROPERTY, oldSuperMethodInvocation.getName(), null); - ListRewrite argumentRewrite = sourceRewriter.getListRewrite(newMethodInvocation, MethodInvocation.ARGUMENTS_PROPERTY); - List oldArguments = oldSuperMethodInvocation.arguments(); - for(Expression oldArgument : oldArguments) { - argumentRewrite.insertLast(oldArgument, null); + if(typeBinding1.isEqualTo(typeBinding2)) { + SuperMethodInvocation newMethodInvocation = ast.newSuperMethodInvocation(); + sourceRewriter.set(newMethodInvocation, SuperMethodInvocation.NAME_PROPERTY, oldSuperMethodInvocation.getName(), null); + ListRewrite argumentRewrite = sourceRewriter.getListRewrite(newMethodInvocation, SuperMethodInvocation.ARGUMENTS_PROPERTY); + List oldArguments = oldSuperMethodInvocation.arguments(); + for(Expression oldArgument : oldArguments) { + argumentRewrite.insertLast(oldArgument, null); + } + sourceRewriter.replace(newSuperMethodInvocation, newMethodInvocation, null); + replacement = true; + } + else { + MethodInvocation newMethodInvocation = ast.newMethodInvocation(); + sourceRewriter.set(newMethodInvocation, MethodInvocation.NAME_PROPERTY, oldSuperMethodInvocation.getName(), null); + ListRewrite argumentRewrite = sourceRewriter.getListRewrite(newMethodInvocation, MethodInvocation.ARGUMENTS_PROPERTY); + List oldArguments = oldSuperMethodInvocation.arguments(); + for(Expression oldArgument : oldArguments) { + argumentRewrite.insertLast(oldArgument, null); + } + sourceRewriter.replace(newSuperMethodInvocation, newMethodInvocation, null); + replacement = true; } - sourceRewriter.replace(newSuperMethodInvocation, newMethodInvocation, null); - replacement = true; break; } j++;