Skip to content

Commit

Permalink
FileTracker fix for issue #198
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Nov 27, 2024
1 parent e890e37 commit 459fa25
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 31 deletions.
12 changes: 9 additions & 3 deletions src/main/java/org/codetracker/AbstractTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static UMLOperation matchesOperation(AbstractCall invocation, List<UMLOp
}

protected static UMLOperationBodyMapper findBodyMapper(UMLModelDiff umlModelDiff, Method method, Version currentVersion, Version parentVersion) throws RefactoringMinerTimedOutException {
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiff, method.getUmlOperation().getClassName());
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiff, method.getUmlOperation().getLocationInfo().getSourceFolder(), method.getUmlOperation().getClassName());
if (umlClassDiff != null) {
for (UMLOperationBodyMapper operationBodyMapper : umlClassDiff.getOperationBodyMapperList()) {
Method methodLeft = Method.of(operationBodyMapper.getContainer1(), parentVersion);
Expand All @@ -200,12 +200,12 @@ protected static UMLOperationBodyMapper findBodyMapper(UMLModelDiff umlModelDiff
return null;
}

protected static UMLAbstractClassDiff getUMLClassDiff(UMLModelDiff umlModelDiff, String className) throws RefactoringMinerTimedOutException {
protected static UMLAbstractClassDiff getUMLClassDiff(UMLModelDiff umlModelDiff, String sourceFolder, String className) throws RefactoringMinerTimedOutException {
int maxMatchedMembers = 0;
UMLAbstractClassDiff maxRenameDiff = null;
UMLAbstractClassDiff sameNameDiff = null;
for (UMLClassBaseDiff classDiff : getAllClassesDiff(umlModelDiff)) {
if (classDiff.getOriginalClass().getName().equals(className) || classDiff.getNextClass().getName().equals(className)) {
if (matchCondition(sourceFolder, className, classDiff)) {
if (classDiff instanceof UMLClassRenameDiff) {
UMLClassMatcher.MatchResult matchResult = ((UMLClassRenameDiff) classDiff).getMatchResult();
int matchedMembers = matchResult.getMatchedOperations() + matchResult.getMatchedAttributes();
Expand Down Expand Up @@ -277,6 +277,12 @@ else if (className.startsWith(classDiff.getOriginalClass() + ".") || className.s
return sameNameDiff != null ? sameNameDiff : maxRenameDiff;
}

private static boolean matchCondition(String sourceFolder, String className, UMLClassBaseDiff classDiff) {
if (classDiff.getNextClass().getName().equals(className) && classDiff.getNextClass().getSourceFolder().equals(sourceFolder))
return true;
return false;
}

private static UMLAbstractClassDiff searchRecursively(String className, UMLAnonymousClassDiff anonymousClassDiff) {
UMLAbstractClass originalClass = anonymousClassDiff.getOriginalClass();
UMLAbstractClass nextClass = anonymousClassDiff.getNextClass();
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/org/codetracker/AnnotationTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public History.HistoryInfo<Annotation> blame() throws Exception {
continue;
}
String rightMethodClassName = rightMethod.getUmlOperation().getClassName();
String rightMethodSourceFolder = rightMethod.getUmlOperation().getLocationInfo().getSourceFolder();
Annotation rightAnnotation = rightMethod.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation == null) {
continue;
Expand Down Expand Up @@ -301,7 +302,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM
}


UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightMethodClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightMethodSourceFolder, rightMethodClassName);
if (umlClassDiff != null) {
found = changeHistory.checkClassDiffForAnnotationChange(currentVersion, parentVersion, equalMethod, equalAnnotation, umlClassDiff);

Expand Down Expand Up @@ -332,6 +333,7 @@ else if (currentAnnotation.getOperation().get() instanceof UMLAttribute) {
continue;
}
String rightAttributeClassName = rightAttribute.getUmlAttribute().getClassName();
String rightAttributeSourceFolder = rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder();
Annotation rightAnnotation = rightAttribute.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation == null) {
continue;
Expand Down Expand Up @@ -366,7 +368,7 @@ else if (currentAnnotation.getOperation().get() instanceof UMLAttribute) {
historyReport.step4PlusPlus();
break;
}
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffLocal, rightAttributeClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffLocal, rightAttributeSourceFolder, rightAttributeClassName);
found = changeHistory.checkClassDiffForAnnotationChange(currentVersion, parentVersion, rightAttribute, equalAnnotation, umlClassDiff);
if (found) {
historyReport.step4PlusPlus();
Expand Down Expand Up @@ -430,7 +432,7 @@ else if (currentAnnotation.getOperation().get() instanceof UMLAttribute) {
UMLModelDiff umlModelDiffPartial = umlModelPairPartial.getLeft().diff(umlModelPairPartial.getRight());
//List<Refactoring> refactoringsPartial = umlModelDiffPartial.getRefactorings();

UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffPartial, rightAttributeClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffPartial, rightAttributeSourceFolder, rightAttributeClassName);
boolean found = changeHistory.checkClassDiffForAnnotationChange(currentVersion, parentVersion, rightAttribute, equalAnnotation, umlClassDiff);
if (found) {
historyReport.step5PlusPlus();
Expand Down Expand Up @@ -493,7 +495,7 @@ else if (RefactoringType.MOVE_RENAME_ATTRIBUTE.equals(refactoring.getRefactoring
}


UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightAttributeClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightAttributeSourceFolder, rightAttributeClassName);
if (umlClassDiff != null) {
found = changeHistory.checkClassDiffForAnnotationChange(currentVersion, parentVersion, rightAttribute, equalAnnotation, umlClassDiff);

Expand Down Expand Up @@ -522,6 +524,8 @@ else if (currentAnnotation.getClazz().isPresent()) {
if (rightClass == null) {
continue;
}
String rightClassName = rightClass.getUmlClass().getName();
String rightClassSourceFolder = rightClass.getUmlClass().getLocationInfo().getSourceFolder();
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation == null) {
continue;
Expand All @@ -547,7 +551,7 @@ else if (currentAnnotation.getClazz().isPresent()) {
UMLModelDiff umlModelDiffLocal = leftModel.diff(rightModel);
{
//Local Refactoring
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffLocal, rightClass.getUmlClass().getName());
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffLocal, rightClassSourceFolder, rightClassName);
boolean found = changeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightAnnotation::equalIdentifierIgnoringVersion, classDiff);
if (found) {
historyReport.step4PlusPlus();
Expand Down Expand Up @@ -592,7 +596,7 @@ else if (currentAnnotation.getClazz().isPresent()) {
else {
UMLModelDiff umlModelDiffPartial = umlModelPairPartial.getLeft().diff(umlModelPairPartial.getRight());
//List<Refactoring> refactoringsPartial = umlModelDiffPartial.getRefactorings();
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffPartial, rightClass.getUmlClass().getName());
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffPartial, rightClassSourceFolder, rightClassName);
boolean found = changeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightAnnotation::equalIdentifierIgnoringVersion, classDiff);
if (found) {
historyReport.step5PlusPlus();
Expand All @@ -615,7 +619,7 @@ else if (currentAnnotation.getClazz().isPresent()) {
}
}

UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightClass.getUmlClass().getName());
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightClassSourceFolder, rightClassName);
if (umlClassDiff != null) {
boolean found = changeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightAnnotation::equalIdentifierIgnoringVersion, umlClassDiff);
if (found) {
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/org/codetracker/CommentTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public History.HistoryInfo<Comment> blame() throws Exception {
continue;
}
String rightMethodClassName = rightMethod.getUmlOperation().getClassName();
String rightMethodSourceFolder = rightMethod.getUmlOperation().getLocationInfo().getSourceFolder();
Comment rightComment = rightMethod.findComment(currentComment::equalIdentifierIgnoringVersion);
if (rightComment == null) {
continue;
Expand Down Expand Up @@ -320,7 +321,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM
}


UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightMethodClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightMethodSourceFolder, rightMethodClassName);
if (umlClassDiff != null) {
found = changeHistory.checkClassDiffForCommentChange(currentVersion, parentVersion, equalMethod, equalComment, umlClassDiff);

Expand Down Expand Up @@ -351,6 +352,7 @@ else if (currentComment.getOperation().get() instanceof UMLAttribute) {
continue;
}
String rightAttributeClassName = rightAttribute.getUmlAttribute().getClassName();
String rightAttributeSourceFolder = rightAttribute.getUmlAttribute().getLocationInfo().getSourceFolder();
Comment rightComment = rightAttribute.findComment(currentComment::equalIdentifierIgnoringVersion);
if (rightComment == null) {
continue;
Expand Down Expand Up @@ -385,7 +387,7 @@ else if (currentComment.getOperation().get() instanceof UMLAttribute) {
historyReport.step4PlusPlus();
break;
}
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffLocal, rightAttributeClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffLocal, rightAttributeSourceFolder, rightAttributeClassName);
found = changeHistory.checkClassDiffForCommentChange(currentVersion, parentVersion, rightAttribute, equalComment, umlClassDiff);
if (found) {
historyReport.step4PlusPlus();
Expand Down Expand Up @@ -449,7 +451,7 @@ else if (currentComment.getOperation().get() instanceof UMLAttribute) {
UMLModelDiff umlModelDiffPartial = umlModelPairPartial.getLeft().diff(umlModelPairPartial.getRight());
//List<Refactoring> refactoringsPartial = umlModelDiffPartial.getRefactorings();

UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffPartial, rightAttributeClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffPartial, rightAttributeSourceFolder, rightAttributeClassName);
boolean found = changeHistory.checkClassDiffForCommentChange(currentVersion, parentVersion, rightAttribute, equalComment, umlClassDiff);
if (found) {
historyReport.step5PlusPlus();
Expand Down Expand Up @@ -512,7 +514,7 @@ else if (RefactoringType.MOVE_RENAME_ATTRIBUTE.equals(refactoring.getRefactoring
}


UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightAttributeClassName);
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightAttributeSourceFolder, rightAttributeClassName);
if (umlClassDiff != null) {
found = changeHistory.checkClassDiffForCommentChange(currentVersion, parentVersion, rightAttribute, equalComment, umlClassDiff);

Expand Down Expand Up @@ -541,6 +543,8 @@ else if (currentComment.getClazz().isPresent()) {
if (rightClass == null) {
continue;
}
String rightClassName = rightClass.getUmlClass().getName();
String rightClassSourceFolder = rightClass.getUmlClass().getLocationInfo().getSourceFolder();
Comment rightComment = rightClass.findComment(currentComment::equalIdentifierIgnoringVersion);
if (rightComment == null) {
continue;
Expand All @@ -566,7 +570,7 @@ else if (currentComment.getClazz().isPresent()) {
UMLModelDiff umlModelDiffLocal = leftModel.diff(rightModel);
{
//Local Refactoring
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffLocal, rightClass.getUmlClass().getName());
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffLocal, rightClassSourceFolder, rightClassName);
boolean found = changeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightComment::equalIdentifierIgnoringVersion, classDiff);
if (found) {
historyReport.step4PlusPlus();
Expand Down Expand Up @@ -611,7 +615,7 @@ else if (currentComment.getClazz().isPresent()) {
else {
UMLModelDiff umlModelDiffPartial = umlModelPairPartial.getLeft().diff(umlModelPairPartial.getRight());
//List<Refactoring> refactoringsPartial = umlModelDiffPartial.getRefactorings();
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffPartial, rightClass.getUmlClass().getName());
UMLAbstractClassDiff classDiff = getUMLClassDiff(umlModelDiffPartial, rightClassSourceFolder, rightClassName);
boolean found = changeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightComment::equalIdentifierIgnoringVersion, classDiff);
if (found) {
historyReport.step5PlusPlus();
Expand All @@ -634,7 +638,7 @@ else if (currentComment.getClazz().isPresent()) {
}
}

UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightClass.getUmlClass().getName());
UMLAbstractClassDiff umlClassDiff = getUMLClassDiff(umlModelDiffAll, rightClassSourceFolder, rightClassName);
if (umlClassDiff != null) {
boolean found = changeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightComment::equalIdentifierIgnoringVersion, umlClassDiff);
if (found) {
Expand Down
Loading

0 comments on commit 459fa25

Please sign in to comment.