Skip to content

Commit

Permalink
Handling moved methods to the blamed file
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 3, 2024
1 parent 9588881 commit 77e0bac
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 36 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.UMLAttribute;
import gr.uom.java.xmi.decomposition.UMLOperationBodyMapper;
import gr.uom.java.xmi.diff.MoveOperationRefactoring;
import gr.uom.java.xmi.diff.RenameAttributeRefactoring;
import gr.uom.java.xmi.diff.UMLAbstractClassDiff;
import gr.uom.java.xmi.diff.UMLAttributeDiff;
Expand Down Expand Up @@ -950,6 +951,17 @@ else if (key2 instanceof Annotation) {
}
}

private boolean isMoved(Method rightMethod, List<Refactoring> refactorings) {
for (Refactoring r : refactorings) {
if (r instanceof MoveOperationRefactoring) {
MoveOperationRefactoring move = (MoveOperationRefactoring) r;
if (move.getMovedOperation().equals(rightMethod.getUmlOperation()))
return true;
}
}
return false;
}

private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHistory> notFoundMethods, UMLModelDiff umlModelDiff, Version currentVersion, Version parentVersion, List<Refactoring> refactorings) throws RefactoringMinerTimedOutException {
Set<CodeElement> alreadyProcessed = new HashSet<>();
for (Method rightMethod : notFoundMethods.keySet()) {
Expand All @@ -960,6 +972,7 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
leftSideMethods.addAll(methodContainerChanged);
boolean refactored = !leftSideMethods.isEmpty();
if (refactored) {
boolean moved = isMoved(rightMethod, refactorings);
leftSideMethods.forEach(startMethodChangeHistory::addFirst);
if (leftSideMethods.size() == 1) {
startMethodChangeHistory.setCurrent(leftSideMethods.iterator().next());
Expand All @@ -983,6 +996,10 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
}
startBlockChangeHistory.poll();
alreadyProcessed.add(startBlock);
if (moved) {
startBlockChangeHistory.addedMethod(rightMethod, rightBlock, parentVersion);
continue;
}
boolean found = startBlockChangeHistory.isMergeMultiMapping(currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, rightBlock, refactorings);
if (found) {
continue;
Expand Down Expand Up @@ -1093,6 +1110,9 @@ else if (key2 instanceof Annotation) {
programElementMap.put(codeElement, changeHistory);
}
}
if (moved) {
startMethodChangeHistory.handleAddOperation(currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, rightMethod.getUmlOperation(), "moved method");
}
}
else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) {
for (CodeElement key2 : programElementMap.keySet()) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import gr.uom.java.xmi.VariableDeclarationContainer;
import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.decomposition.UMLOperationBodyMapper;
import gr.uom.java.xmi.diff.MoveOperationRefactoring;
import gr.uom.java.xmi.diff.RenameAttributeRefactoring;
import gr.uom.java.xmi.diff.UMLAbstractClassDiff;
import gr.uom.java.xmi.diff.UMLAttributeDiff;
Expand Down Expand Up @@ -957,6 +958,17 @@ else if (key2 instanceof Annotation) {
}
}

private boolean isMoved(Method rightMethod, List<Refactoring> refactorings) {
for (Refactoring r : refactorings) {
if (r instanceof MoveOperationRefactoring) {
MoveOperationRefactoring move = (MoveOperationRefactoring) r;
if (move.getMovedOperation().equals(rightMethod.getUmlOperation()))
return true;
}
}
return false;
}

private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHistory> notFoundMethods, UMLModelDiff umlModelDiff, Version currentVersion, Version parentVersion, List<Refactoring> refactorings) throws RefactoringMinerTimedOutException {
Set<CodeElement> alreadyProcessed = new HashSet<>();
for (Method rightMethod : notFoundMethods.keySet()) {
Expand All @@ -967,6 +979,7 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
leftSideMethods.addAll(methodContainerChanged);
boolean refactored = !leftSideMethods.isEmpty();
if (refactored) {
boolean moved = isMoved(rightMethod, refactorings);
leftSideMethods.forEach(startMethodChangeHistory::addFirst);
if (leftSideMethods.size() == 1) {
startMethodChangeHistory.setCurrent(leftSideMethods.iterator().next());
Expand All @@ -990,6 +1003,10 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
}
startBlockChangeHistory.poll();
alreadyProcessed.add(startBlock);
if (moved) {
startBlockChangeHistory.addedMethod(rightMethod, rightBlock, parentVersion);
continue;
}
boolean found = startBlockChangeHistory.isMergeMultiMapping(currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, rightBlock, refactorings);
if (found) {
continue;
Expand Down Expand Up @@ -1100,6 +1117,9 @@ else if (key2 instanceof Annotation) {
programElementMap.put(codeElement, changeHistory);
}
}
if (moved) {
startMethodChangeHistory.handleAddOperation(currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, rightMethod.getUmlOperation(), "moved method");
}
}
else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlOperation().getClassName(), currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getAllClassesDiff(umlModelDiff))) {
for (CodeElement key2 : programElementMap.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public boolean isMethodAdded(UMLModelDiff modelDiff, String className, Version c
return false;
}

private boolean handleAddOperation( Version currentVersion, Version parentVersion, Predicate<Method> equalOperator, VariableDeclarationContainer operation, String comment) {
public boolean handleAddOperation( Version currentVersion, Version parentVersion, Predicate<Method> equalOperator, VariableDeclarationContainer operation, String comment) {
Method rightMethod = Method.of(operation, currentVersion);
if (equalOperator.test(rightMethod)) {
Method leftMethod = Method.of(operation, parentVersion);
Expand Down
Loading

0 comments on commit 77e0bac

Please sign in to comment.