Skip to content

Commit

Permalink
Add MoveType to MoveCodeRefactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 17, 2024
1 parent 84bee75 commit f593403
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/main/java/gr/uom/java/xmi/diff/MoveCodeRefactoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractCodeFragment> movedCodeFragmentsFromSourceOperation;
private Set<AbstractCodeFragment> 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<AbstractCodeFragment>();
this.movedCodeFragmentsToTargetOperation = new LinkedHashSet<AbstractCodeFragment>();
for(AbstractCodeMapping mapping : mapper.getMappings()) {
Expand Down Expand Up @@ -56,6 +63,10 @@ public VariableDeclarationContainer getTargetContainer() {
return targetContainer;
}

public Type getMoveType() {
return moveType;
}

public Set<AbstractCodeMapping> getMappings() {
return bodyMapper.getMappings();
}
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f593403

Please sign in to comment.