Skip to content

Commit

Permalink
Fixed tracking of anonymous methods in moved/renamed files
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 4, 2024
1 parent baad546 commit 2199416
Show file tree
Hide file tree
Showing 5 changed files with 987 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ else if (key instanceof Comment) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if (startComment.getClazz().isPresent()) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
continue;
}
Comment rightComment = rightClass.findComment(currentComment::equalIdentifierIgnoringVersion);
if (rightComment != null) {
Comment commentBefore = Comment.of(rightComment.getComment(), rightComment.getClazz().get(), parentVersion);
Expand All @@ -544,6 +547,9 @@ else if (key instanceof Annotation) {
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if (startAnnotation.getClazz().isPresent()) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
if (currentAnnotation == null) {
continue;
}
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation != null) {
Annotation annotationBefore = Annotation.of(rightAnnotation.getAnnotation(), rightAnnotation.getClazz().get(), parentVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ else if (key instanceof Comment) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if (startComment.getClazz().isPresent()) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
continue;
}
Comment rightComment = rightClass.findComment(currentComment::equalIdentifierIgnoringVersion);
if (rightComment != null) {
Comment commentBefore = Comment.of(rightComment.getComment(), rightComment.getClazz().get(), parentVersion);
Expand All @@ -551,6 +554,9 @@ else if (key instanceof Annotation) {
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if (startAnnotation.getClazz().isPresent()) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
if (currentAnnotation == null) {
continue;
}
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation != null) {
Annotation annotationBefore = Annotation.of(rightAnnotation.getAnnotation(), rightAnnotation.getClazz().get(), parentVersion);
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/org/codetracker/MethodTrackerChangeHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,18 +596,40 @@ public Set<Method> isMethodContainerChanged(UMLModelDiff umlModelDiffAll, Collec
if (found)
break;
for (UMLOperationBodyMapper umlOperationBodyMapper : classRenameDiffList.getOperationBodyMapperList()) {
found = addMethodChange(currentVersion, parentVersion, equalOperator, leftMethodSet, new RenameClassRefactoring(classRenameDiffList.getOriginalClass(), classRenameDiffList.getRenamedClass()), umlOperationBodyMapper.getContainer1(), umlOperationBodyMapper.getContainer2(), changeType);
if (found)
break;
found = addMethodChange(currentVersion, parentVersion, equalOperator, leftMethodSet, new RenameClassRefactoring(classRenameDiffList.getOriginalClass(), classRenameDiffList.getRenamedClass()), umlOperationBodyMapper.getContainer1(), umlOperationBodyMapper.getContainer2(), changeType);
if (found)
break;
for (UMLAnonymousClassDiff anonymousClassDiff : umlOperationBodyMapper.getAnonymousClassDiffs()) {
if (found)
break;
for (UMLOperationBodyMapper anonymousOperationBodyMapper : anonymousClassDiff.getOperationBodyMapperList()) {
found = addMethodChange(currentVersion, parentVersion, equalOperator, leftMethodSet, null, anonymousOperationBodyMapper.getContainer1(), anonymousOperationBodyMapper.getContainer2(), changeType);
if (found)
break;
}
}
}
}
for (UMLClassMoveDiff classMoveDiff : classMovedDiffList) {
if (found)
break;
for (UMLOperationBodyMapper umlOperationBodyMapper : classMoveDiff.getOperationBodyMapperList()) {
found = addMethodChange(currentVersion, parentVersion, equalOperator, leftMethodSet, new MoveClassRefactoring(classMoveDiff.getOriginalClass(), classMoveDiff.getMovedClass()), umlOperationBodyMapper.getContainer1(), umlOperationBodyMapper.getContainer2(), changeType);
if (found)
break;
found = addMethodChange(currentVersion, parentVersion, equalOperator, leftMethodSet, new MoveClassRefactoring(classMoveDiff.getOriginalClass(), classMoveDiff.getMovedClass()), umlOperationBodyMapper.getContainer1(), umlOperationBodyMapper.getContainer2(), changeType);
if (found)
break;
for (UMLAnonymousClassDiff anonymousClassDiff : umlOperationBodyMapper.getAnonymousClassDiffs()) {
if (found)
break;
for (UMLOperationBodyMapper anonymousOperationBodyMapper : anonymousClassDiff.getOperationBodyMapperList()) {
found = addMethodChange(currentVersion, parentVersion, equalOperator, leftMethodSet, null, anonymousOperationBodyMapper.getContainer1(), anonymousOperationBodyMapper.getContainer2(), changeType);
if (found)
break;
}
}
}
}
for (UMLClassDiff classDiff : umlModelDiffAll.getCommonClassDiffList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private static Stream<Arguments> testBlamerInputProvider(){
"https://github.com/checkstyle/checkstyle/commit/119fd4fb33bef9f5c66fc950396669af842c21a3, src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java, /src/test/resources/blame/blameTestWithLocalRepo13.txt",
"https://github.com/apache/flink/commit/9e936a5f8198b0059e9b5fba33163c2bbe3efbdd, flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/DispatcherRestEndpoint.java, /src/test/resources/blame/blameTestWithLocalRepo14.txt",
"https://github.com/junit-team/junit4/commit/02c328028b4d32c15bbf0becc9838e54ecbafcbf, src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java, /src/test/resources/blame/blameTestWithLocalRepo15.txt",
"https://github.com/square/okhttp/commit/5224f3045ba9b171fce521777edf389f9206173c, okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java, /src/test/resources/blame/blameTestWithLocalRepo16.txt",
"https://github.com/eclipse/jgit/commit/bd1a82502680b5de5bf86f6c4470185fd1602386, org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java, /src/test/resources/blame/blameTestUntilCommitZero.txt",
"https://github.com/JetBrains/intellij-community/commit/ecb1bb9d4d484ae63ee77f8ad45bdce154db9356, java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java, /src/test/resources/blame/blameTestUntilCommitZero2.txt",
"https://github.com/JetBrains/intellij-community/commit/ecb1bb9d4d484ae63ee77f8ad45bdce154db9356, java/compiler/impl/src/com/intellij/compiler/actions/CompileDirtyAction.java, /src/test/resources/blame/blameTestUntilCommitZero3.txt"
Expand Down
Loading

0 comments on commit 2199416

Please sign in to comment.