Skip to content

Commit

Permalink
Filter Move Method mappers based on source folders
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 29, 2024
1 parent 4629b0c commit c457b84
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -4864,7 +4864,8 @@ else if((mappings > 0 && mappedElementsMoreThanNonMappedT1AndT2(mappings, operat
firstMappers.clear();
firstMappers.add(bestMapper);
}
for(UMLOperationBodyMapper firstMapper : firstMappers) {
List<UMLOperationBodyMapper> filteredFirstMappers = promoteSameSourceFolderMoves(firstMappers);
for(UMLOperationBodyMapper firstMapper : filteredFirstMappers) {
UMLOperation removedOperation = firstMapper.getOperation1();
if(sameSourceAndTargetClass) {
removedOperations.remove(removedOperation);
Expand Down Expand Up @@ -4971,7 +4972,8 @@ else if((mappings > 0 && mappedElementsMoreThanNonMappedT1AndT2(mappings, operat
firstMappers.clear();
firstMappers.add(bestMapper);
}
for(UMLOperationBodyMapper firstMapper : firstMappers) {
List<UMLOperationBodyMapper> filteredFirstMappers = promoteSameSourceFolderMoves(firstMappers);
for(UMLOperationBodyMapper firstMapper : filteredFirstMappers) {
UMLOperation addedOperation = firstMapper.getOperation2();
if(sameSourceAndTargetClass) {
addedOperations.remove(addedOperation);
Expand All @@ -4984,6 +4986,42 @@ else if((mappings > 0 && mappedElementsMoreThanNonMappedT1AndT2(mappings, operat
}
}

private List<UMLOperationBodyMapper> promoteSameSourceFolderMoves(List<UMLOperationBodyMapper> firstMappers) {
List<UMLOperationBodyMapper> list = new ArrayList<UMLOperationBodyMapper>(firstMappers);
//filter based on source folder
for(int i=0; i<firstMappers.size(); i++) {
UMLOperationBodyMapper mapperI = firstMappers.get(i);
boolean sameSourceFolderI = mapperI.getContainer1().getLocationInfo().getSourceFolder().equals(mapperI.getContainer2().getLocationInfo().getSourceFolder());
if(sameSourceFolderI) {
for(int j=i+1; j<firstMappers.size(); j++) {
UMLOperationBodyMapper mapperJ = firstMappers.get(j);
boolean sameSourceFolderJ = mapperJ.getContainer1().getLocationInfo().getSourceFolder().equals(mapperJ.getContainer2().getLocationInfo().getSourceFolder());
if(mapperI.toString().equals(mapperJ.toString()) && !sameSourceFolderJ) {
list.remove(mapperJ);
}
}
}
}
List<UMLOperationBodyMapper> list2 = new ArrayList<UMLOperationBodyMapper>(list);
//filter based on signature
for(int i=0; i<list.size(); i++) {
UMLOperationBodyMapper mapperI = list.get(i);
boolean sameSignatureI = mapperI.getContainer1() instanceof UMLOperation && mapperI.getContainer2() instanceof UMLOperation ?
((UMLOperation)mapperI.getContainer1()).equalSignature((UMLOperation)mapperI.getContainer2()) : false;
if(sameSignatureI) {
for(int j=i+1; j<list.size(); j++) {
UMLOperationBodyMapper mapperJ = list.get(j);
boolean sameSignatureJ = mapperJ.getContainer1() instanceof UMLOperation && mapperJ.getContainer2() instanceof UMLOperation ?
((UMLOperation)mapperJ.getContainer1()).equalSignature((UMLOperation)mapperJ.getContainer2()) : false;
if(!sameSignatureJ) {
list2.remove(mapperJ);
}
}
}
}
return list2;
}

private void createRefactoring(UMLOperation removedOperation, UMLOperation addedOperation,
UMLOperationBodyMapper firstMapper, boolean multipleMappers)
throws RefactoringMinerTimedOutException {
Expand Down

0 comments on commit c457b84

Please sign in to comment.