From f5934039b2bcfbf93f16c0ac3521e0bf447525ed Mon Sep 17 00:00:00 2001 From: tsantalis Date: Thu, 17 Oct 2024 09:24:15 -0400 Subject: [PATCH] Add MoveType to MoveCodeRefactoring --- .../java/xmi/diff/MoveCodeRefactoring.java | 13 ++++++++++- .../uom/java/xmi/diff/UMLClassBaseDiff.java | 23 ++++++++++--------- .../gr/uom/java/xmi/diff/UMLModelDiff.java | 3 ++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/diff/MoveCodeRefactoring.java b/src/main/java/gr/uom/java/xmi/diff/MoveCodeRefactoring.java index c27537db3..52f5541db 100644 --- a/src/main/java/gr/uom/java/xmi/diff/MoveCodeRefactoring.java +++ b/src/main/java/gr/uom/java/xmi/diff/MoveCodeRefactoring.java @@ -16,17 +16,24 @@ import gr.uom.java.xmi.decomposition.UMLOperationBodyMapper; public class MoveCodeRefactoring implements Refactoring { + public enum Type { + MOVE_FROM_REMOVED, + MOVE_TO_ADDED, + MOVE_BETWEEN_EXISTING; + } private VariableDeclarationContainer sourceContainer; private VariableDeclarationContainer targetContainer; private UMLOperationBodyMapper bodyMapper; private Set movedCodeFragmentsFromSourceOperation; private Set movedCodeFragmentsToTargetOperation; + private Type moveType; public MoveCodeRefactoring(VariableDeclarationContainer sourceContainer, - VariableDeclarationContainer targetContainer, UMLOperationBodyMapper mapper) { + VariableDeclarationContainer targetContainer, UMLOperationBodyMapper mapper, Type moveType) { this.sourceContainer = sourceContainer; this.targetContainer = targetContainer; this.bodyMapper = mapper; + this.moveType = moveType; this.movedCodeFragmentsFromSourceOperation = new LinkedHashSet(); this.movedCodeFragmentsToTargetOperation = new LinkedHashSet(); for(AbstractCodeMapping mapping : mapper.getMappings()) { @@ -56,6 +63,10 @@ public VariableDeclarationContainer getTargetContainer() { return targetContainer; } + public Type getMoveType() { + return moveType; + } + public Set getMappings() { return bodyMapper.getMappings(); } diff --git a/src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java b/src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java index 8a4635a29..56487e1f3 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java @@ -55,6 +55,7 @@ import gr.uom.java.xmi.decomposition.replacement.MethodInvocationReplacement; import gr.uom.java.xmi.decomposition.replacement.Replacement; import gr.uom.java.xmi.decomposition.replacement.Replacement.ReplacementType; +import gr.uom.java.xmi.diff.MoveCodeRefactoring.Type; import gr.uom.java.xmi.decomposition.replacement.CompositeReplacement; import gr.uom.java.xmi.decomposition.replacement.ConsistentReplacementDetector; @@ -213,7 +214,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu } } if(moveCodeMapper.getMappings().size() > invalidMappings) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); @@ -229,7 +230,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(!mapper.equals(setUpMapper)) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(mapper, setUpMapper, this); if(moveCodeMapper.getMappings().size() > 0) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); if(!moveCodeMappers.contains(mapper)) { @@ -247,7 +248,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(!mapper.equals(tearDownMapper)) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(mapper, tearDownMapper, this); if(moveCodeMapper.getMappings().size() > 0) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); if(!moveCodeMappers.contains(mapper)) { @@ -266,7 +267,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(mapper.nonMappedElementsT1() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(mapper, constructorMapper, this); if(moveCodeMapper.getExactMatchesWithoutLoggingStatements().size() > 0 && !mappingFoundInExtractedMethod(moveCodeMapper.getMappings())) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); @@ -275,7 +276,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(mapper.nonMappedElementsT2() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(constructorMapper, mapper, this); if(moveCodeMapper.getExactMatchesWithoutLoggingStatements().size() > 0 && !mappingFoundInExtractedMethod(moveCodeMapper.getMappings())) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); @@ -292,7 +293,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(mapper.nonMappedElementsT1() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(mapper, constructorMapper, this); if(moveCodeMapper.getExactMatchesWithoutLoggingStatements().size() > 0 && !mappingFoundInExtractedMethod(moveCodeMapper.getMappings())) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactoringsToBeAdded.add(ref); @@ -301,7 +302,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(mapper.nonMappedElementsT2() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(constructorMapper, mapper, this); if(moveCodeMapper.getExactMatchesWithoutLoggingStatements().size() > 0 && !mappingFoundInExtractedMethod(moveCodeMapper.getMappings())) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactoringsToBeAdded.add(ref); @@ -321,7 +322,7 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu if(mapper.nonMappedElementsT2() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(removedOperation, mapper, this); if(moveCodeMapper.getMappings().size() > 0) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_FROM_REMOVED); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); @@ -334,7 +335,7 @@ else if(removedOperation.isConstructor()) { if(mapper.nonMappedElementsT2() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(removedOperation, mapper, this); if(moveCodeMapper.mappingsWithoutBlocks() > 2) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_FROM_REMOVED); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); @@ -350,7 +351,7 @@ else if(removedOperation.isConstructor()) { if(mapper.nonMappedElementsT1() > 0) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(mapper, addedOperation, this); if(moveCodeMapper.getMappings().size() > 0) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_TO_ADDED); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); @@ -361,7 +362,7 @@ else if(removedOperation.isConstructor()) { } for(UMLOperationBodyMapper moveCodeMapper : potentialCodeMoveBetweenSetUpTearDownMethods) { if(moveCodeMapper.getMappings().size() > 0) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref); diff --git a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java index bf1e0ac2b..765d5cfc7 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java @@ -39,6 +39,7 @@ import gr.uom.java.xmi.decomposition.replacement.Replacement.ReplacementType; import gr.uom.java.xmi.decomposition.replacement.VariableReplacementWithMethodInvocation; import gr.uom.java.xmi.decomposition.replacement.VariableReplacementWithMethodInvocation.Direction; +import gr.uom.java.xmi.diff.MoveCodeRefactoring.Type; import static gr.uom.java.xmi.Constants.JAVA; import static gr.uom.java.xmi.diff.UMLClassBaseDiff.BUILDER_STATEMENT_RATIO_THRESHOLD; @@ -4676,7 +4677,7 @@ else if(r instanceof MoveOperationRefactoring) { for(UMLOperationBodyMapper mapper : mappersWithUnmatchedStatements) { UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper(mapper, firstMapper, mapper.getClassDiff()); if(moveCodeMapper.getMappings().size() > 0) { - MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper); + MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING); if(!moveCodeMappers.contains(moveCodeMapper)) moveCodeMappers.add(moveCodeMapper); refactorings.add(ref);