Skip to content

Commit

Permalink
Fix failing test + improvements for anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jul 30, 2024
1 parent fea70d6 commit da55238
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 48 deletions.
27 changes: 25 additions & 2 deletions src/main/java/org/codetracker/AbstractTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.codetracker.element.Class;
import org.codetracker.element.Comment;
import org.codetracker.element.Method;
import org.refactoringminer.api.RefactoringMinerTimedOutException;
import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl;

import gr.uom.java.xmi.UMLAbstractClass;
Expand Down Expand Up @@ -151,7 +152,7 @@ private static UMLOperation matchesOperation(AbstractCall invocation, List<UMLOp
return null;
}

protected static UMLOperationBodyMapper findBodyMapper(UMLModelDiff umlModelDiff, Method method, Version currentVersion, Version parentVersion) {
protected static UMLOperationBodyMapper findBodyMapper(UMLModelDiff umlModelDiff, Method method, Version currentVersion, Version parentVersion) throws RefactoringMinerTimedOutException {
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiff, method.getUmlOperation().getClassName());
if (umlClassDiff != null) {
for (UMLOperationBodyMapper operationBodyMapper : umlClassDiff.getOperationBodyMapperList()) {
Expand All @@ -168,7 +169,7 @@ protected static UMLOperationBodyMapper findBodyMapper(UMLModelDiff umlModelDiff
return null;
}

protected static UMLAbstractClassDiff getUMLClassDiff(UMLModelDiff umlModelDiff, String className) {
protected static UMLAbstractClassDiff getUMLClassDiff(UMLModelDiff umlModelDiff, String className) throws RefactoringMinerTimedOutException {
int maxMatchedMembers = 0;
UMLAbstractClassDiff maxRenameDiff = null;
UMLAbstractClassDiff sameNameDiff = null;
Expand Down Expand Up @@ -218,6 +219,28 @@ else if (className.startsWith(classDiff.getOriginalClass() + ".") || className.s
}
}
}
for (Pair<UMLAttribute, UMLAttribute> pair : classDiff.getCommonAtrributes()) {
if (pair.getLeft().getAnonymousClassList().size() > 0 && pair.getRight().getAnonymousClassList().size() > 0) {
boolean match = false;
for (UMLAnonymousClass right : pair.getRight().getAnonymousClassList()) {
if (right.getCodePath().equals(className)) {
match = true;
break;
}
}
if (match) {
UMLOperationBodyMapper mapper = new UMLOperationBodyMapper(pair.getLeft(), pair.getRight(), classDiff, umlModelDiff);
Set<UMLAnonymousClassDiff> anonymousClassDiffs = mapper.getAnonymousClassDiffs();
for (UMLAnonymousClassDiff anonymousClassDiff : anonymousClassDiffs) {
UMLAbstractClassDiff result = searchRecursively(className, anonymousClassDiff);
if (result != null) {
sameNameDiff = result;
break;
}
}
}
}
}
}
}
return sameNameDiff != null ? sameNameDiff : maxRenameDiff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ public CodeElement locateWithoutName(Version version, UMLModel umlModel) throws
if (annotation != null) {
return annotation;
}
Attribute attribute = getAttribute(umlModel, version, filePath, this::attributePredicateWithoutName);
if (attribute != null && method.getLocation().subsumes(attribute.getLocation())) {
return attribute;
}
method.checkClosingBracket(lineNumber);
return method;
}
Expand Down
Loading

0 comments on commit da55238

Please sign in to comment.