Skip to content

Commit

Permalink
Support the detection of moved code from/to main method (issue #725)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed May 28, 2024
1 parent 82bbcad commit cf030c9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu
if(mapper.getContainer1().isConstructor() && mapper.getContainer2().isConstructor()) {
constructorMappers.add(mapper);
}
if(mapper.getContainer1().getName().equals("main") && mapper.getContainer2().getName().equals("main")) {
constructorMappers.add(mapper);
}
if(mapper.getAnonymousClassDiffs().size() > 0 && mapper.nonMappedElementsT1() > 0) {
for(UMLAnonymousClassDiff anonymousClassDiff : mapper.getAnonymousClassDiffs()) {
for(UMLOperationBodyMapper anonymousMapper : anonymousClassDiff.getOperationBodyMapperList()) {
Expand Down Expand Up @@ -235,6 +238,35 @@ private void checkForMovedCodeBetweenOperations() throws RefactoringMinerTimedOu
}
}
}
Set<Refactoring> refactoringsToBeAdded = new LinkedHashSet<Refactoring>();
for(Refactoring r : refactorings) {
if(r instanceof MergeOperationRefactoring) {
MergeOperationRefactoring merge = (MergeOperationRefactoring)r;
for(UMLOperationBodyMapper mapper : merge.getMappers()) {
if(!mapper.equals(constructorMapper)) {
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);
if(!moveCodeMappers.contains(moveCodeMapper))
moveCodeMappers.add(moveCodeMapper);
refactoringsToBeAdded.add(ref);
}
}
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);
if(!moveCodeMappers.contains(moveCodeMapper))
moveCodeMappers.add(moveCodeMapper);
refactoringsToBeAdded.add(ref);
}
}
}
}
}
}
refactorings.addAll(refactoringsToBeAdded);
}
}
for(UMLOperation removedOperation : removedOperations) {
Expand Down

0 comments on commit cf030c9

Please sign in to comment.