From 318661536ca1cf5156185eb2a0da96c2d5ee11c8 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sun, 16 Aug 2020 22:02:22 -0400 Subject: [PATCH] Final fix for issue #77 --- .../manipulators/ExtractClassRefactoring.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractClassRefactoring.java b/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractClassRefactoring.java index 073180be..f03f33c0 100644 --- a/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractClassRefactoring.java +++ b/src/gr/uom/java/jdeodorant/refactoring/manipulators/ExtractClassRefactoring.java @@ -761,7 +761,19 @@ else if(binding.getKind() == IBinding.VARIABLE) { Assignment fieldAssignment = finalFieldAssignmentMap.get(fieldFragment); Assignment newFieldAssignment = extractedClassAST.newAssignment(); extractedClassRewriter.set(newFieldAssignment, Assignment.LEFT_HAND_SIDE_PROPERTY, fieldAssignment.getLeftHandSide(), null); - extractedClassRewriter.set(newFieldAssignment, Assignment.RIGHT_HAND_SIDE_PROPERTY, fieldAssignment.getRightHandSide(), null); + if(fieldAssignment.getRightHandSide() instanceof MethodInvocation) { + MethodInvocation invocation = (MethodInvocation)fieldAssignment.getRightHandSide(); + SimpleName variableName = extractedClassAST.newSimpleName(invocation.resolveMethodBinding().getName()); + extractedClassRewriter.set(newFieldAssignment, Assignment.RIGHT_HAND_SIDE_PROPERTY, variableName, null); + } + else if(fieldAssignment.getRightHandSide() instanceof ClassInstanceCreation) { + ClassInstanceCreation creation = (ClassInstanceCreation)fieldAssignment.getRightHandSide(); + SimpleName variableName = extractedClassAST.newSimpleName(creation.resolveConstructorBinding().getName()); + extractedClassRewriter.set(newFieldAssignment, Assignment.RIGHT_HAND_SIDE_PROPERTY, variableName, null); + } + else { + extractedClassRewriter.set(newFieldAssignment, Assignment.RIGHT_HAND_SIDE_PROPERTY, fieldAssignment.getRightHandSide(), null); + } extractedClassRewriter.set(newFieldAssignment, Assignment.OPERATOR_PROPERTY, fieldAssignment.getOperator(), null); ExpressionStatement assignmentStatement = extractedClassAST.newExpressionStatement(newFieldAssignment); extractedClassConstructorBodyStatementsRewrite.insertLast(assignmentStatement, null);