Skip to content

Commit

Permalink
Improved isMoved() to handle anonymous methods whose parent container…
Browse files Browse the repository at this point in the history
… is moved
  • Loading branch information
tsantalis committed Oct 4, 2024
1 parent 43338b4 commit baad546
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
15 changes: 11 additions & 4 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl;

import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.UMLAnonymousClass;
import gr.uom.java.xmi.UMLAttribute;
import gr.uom.java.xmi.decomposition.UMLOperationBodyMapper;
import gr.uom.java.xmi.diff.ExtractClassRefactoring;
Expand Down Expand Up @@ -967,10 +968,16 @@ else if (key2 instanceof Annotation) {
}

private boolean isMoved(Method rightMethod, List<Refactoring> refactorings) {
Set<VariableDeclarationContainer> parentContainers = new LinkedHashSet<>();
parentContainers.add(rightMethod.getUmlOperation());
if (rightMethod.getUmlOperation().getAnonymousClassContainer() != null && rightMethod.getUmlOperation().getAnonymousClassContainer().isPresent()) {
UMLAnonymousClass anonymous = rightMethod.getUmlOperation().getAnonymousClassContainer().get();
parentContainers.addAll(anonymous.getParentContainers());
}
for (Refactoring r : refactorings) {
if (r instanceof MoveOperationRefactoring) {
MoveOperationRefactoring move = (MoveOperationRefactoring) r;
if (move.getMovedOperation().equals(rightMethod.getUmlOperation()))
if (parentContainers.contains(move.getMovedOperation()))
return true;
}
}
Expand Down Expand Up @@ -998,12 +1005,12 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
for (Method rightMethod : notFoundMethods.keySet()) {
MethodTrackerChangeHistory startMethodChangeHistory = notFoundMethods.get(rightMethod);
Method startMethod = startMethodChangeHistory.getStart();
boolean moved = isMoved(rightMethod, refactorings);
Set<Method> leftSideMethods = startMethodChangeHistory.analyseMethodRefactorings(refactorings, currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
Set<Method> methodContainerChanged = startMethodChangeHistory.isMethodContainerChanged(umlModelDiff, refactorings, currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getClassMoveDiffList(umlModelDiff));
leftSideMethods.addAll(methodContainerChanged);
boolean refactored = !leftSideMethods.isEmpty();
if (refactored) {
boolean moved = isMoved(rightMethod, refactorings);
if (refactored || moved) {
leftSideMethods.forEach(startMethodChangeHistory::addFirst);
if (leftSideMethods.size() == 1) {
startMethodChangeHistory.setCurrent(leftSideMethods.iterator().next());
Expand Down Expand Up @@ -1116,7 +1123,7 @@ else if (key2 instanceof Annotation) {
}
}
}
if (startMethodChangeHistory.peek().isAdded() && startMethodChangeHistory.getSourceOperation() != null) {
if (startMethodChangeHistory.peek() != null && startMethodChangeHistory.peek().isAdded() && startMethodChangeHistory.getSourceOperation() != null) {
Method codeElement = startMethodChangeHistory.getSourceOperation();
boolean found = false;
for (CodeElement key2 : programElementMap.keySet()) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import gr.uom.java.xmi.UMLType;
import gr.uom.java.xmi.VariableDeclarationContainer;
import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.UMLAnonymousClass;
import gr.uom.java.xmi.decomposition.UMLOperationBodyMapper;
import gr.uom.java.xmi.diff.ExtractClassRefactoring;
import gr.uom.java.xmi.diff.ExtractSuperclassRefactoring;
Expand Down Expand Up @@ -974,10 +975,16 @@ else if (key2 instanceof Annotation) {
}

private boolean isMoved(Method rightMethod, List<Refactoring> refactorings) {
Set<VariableDeclarationContainer> parentContainers = new LinkedHashSet<>();
parentContainers.add(rightMethod.getUmlOperation());
if (rightMethod.getUmlOperation().getAnonymousClassContainer() != null && rightMethod.getUmlOperation().getAnonymousClassContainer().isPresent()) {
UMLAnonymousClass anonymous = rightMethod.getUmlOperation().getAnonymousClassContainer().get();
parentContainers.addAll(anonymous.getParentContainers());
}
for (Refactoring r : refactorings) {
if (r instanceof MoveOperationRefactoring) {
MoveOperationRefactoring move = (MoveOperationRefactoring) r;
if (move.getMovedOperation().equals(rightMethod.getUmlOperation()))
if (parentContainers.contains(move.getMovedOperation()))
return true;
}
}
Expand Down Expand Up @@ -1005,12 +1012,12 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
for (Method rightMethod : notFoundMethods.keySet()) {
MethodTrackerChangeHistory startMethodChangeHistory = notFoundMethods.get(rightMethod);
Method startMethod = startMethodChangeHistory.getStart();
boolean moved = isMoved(rightMethod, refactorings);
Set<Method> leftSideMethods = startMethodChangeHistory.analyseMethodRefactorings(refactorings, currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
Set<Method> methodContainerChanged = startMethodChangeHistory.isMethodContainerChanged(umlModelDiff, refactorings, currentVersion, parentVersion, rightMethod::equalIdentifierIgnoringVersion, getClassMoveDiffList(umlModelDiff));
leftSideMethods.addAll(methodContainerChanged);
boolean refactored = !leftSideMethods.isEmpty();
if (refactored) {
boolean moved = isMoved(rightMethod, refactorings);
if (refactored || moved) {
leftSideMethods.forEach(startMethodChangeHistory::addFirst);
if (leftSideMethods.size() == 1) {
startMethodChangeHistory.setCurrent(leftSideMethods.iterator().next());
Expand Down Expand Up @@ -1123,7 +1130,7 @@ else if (key2 instanceof Annotation) {
}
}
}
if (startMethodChangeHistory.peek().isAdded() && startMethodChangeHistory.getSourceOperation() != null) {
if (startMethodChangeHistory.peek() != null && startMethodChangeHistory.peek().isAdded() && startMethodChangeHistory.getSourceOperation() != null) {
Method codeElement = startMethodChangeHistory.getSourceOperation();
boolean found = false;
for (CodeElement key2 : programElementMap.keySet()) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/blame/blameTestWithLocalRepo15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ bd5b90f75 src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java (
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 304) Object test;
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 305) try {
bd5b90f75 src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java (Peter Wright 2014-12-07 14:18:17 +0000 306) test = new ReflectiveCallable() {
307) @Override
308) protected Object runReflectiveCall() throws Throwable {
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 307) @Override
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 308) protected Object runReflectiveCall() throws Throwable {
bd5b90f75 src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java (Peter Wright 2014-12-07 14:18:17 +0000 309) return createTest(method);
310) }
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 310) }
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 311) }.run();
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 312) } catch (Throwable e) {
078e45bd3 src/main/java/org/junit/internal/runners/BlockJUnit4ClassRunner.java (kbeck 2008-06-16 17:52:02 +0000 313) return new Fail(e);
Expand Down

0 comments on commit baad546

Please sign in to comment.