Skip to content

Commit

Permalink
Add new blame test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 28, 2024
1 parent c2c1919 commit dd38ce9
Show file tree
Hide file tree
Showing 4 changed files with 834 additions and 26 deletions.
55 changes: 42 additions & 13 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ private void processAddedMethods(UMLModel rightModel, UMLModelDiff umlModelDiffA
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
Expand All @@ -771,7 +771,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
if (currentAnnotation == null) {
Expand Down Expand Up @@ -1000,7 +1000,7 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand Down Expand Up @@ -1029,7 +1029,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null) {
Expand Down Expand Up @@ -1111,8 +1111,7 @@ else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlO
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(rightMethod.getUmlOperation())) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
if (matchingMethod(rightMethod, startComment) || matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
continue;
Expand All @@ -1127,7 +1126,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(rightMethod.getUmlOperation())) ||
if (matchingMethod(rightMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
if (currentAnnotation == null) {
Expand All @@ -1145,6 +1144,36 @@ else if (key2 instanceof Annotation) {
}
}

private boolean matchingMethod(Method rightMethod, Comment startComment) {
if(startComment.getOperation().isPresent()) {
VariableDeclarationContainer container = startComment.getOperation().get();
if(container instanceof UMLOperation) {
return container.equals(rightMethod.getUmlOperation());
}
else if(container instanceof UMLInitializer && rightMethod.getUmlOperation() instanceof UMLInitializer) {
UMLInitializer init1 = (UMLInitializer)container;
UMLInitializer init2 = (UMLInitializer)rightMethod.getUmlOperation();
return init1.getClassName().equals(init2.getClassName()) && init1.isStatic() == init2.isStatic();
}
}
return false;
}

private boolean matchingMethod(Method rightMethod, Annotation startAnnotation) {
if(startAnnotation.getOperation().isPresent()) {
VariableDeclarationContainer container = startAnnotation.getOperation().get();
if(container instanceof UMLOperation) {
return container.equals(rightMethod.getUmlOperation());
}
else if(container instanceof UMLInitializer && rightMethod.getUmlOperation() instanceof UMLInitializer) {
UMLInitializer init1 = (UMLInitializer)container;
UMLInitializer init2 = (UMLInitializer)rightMethod.getUmlOperation();
return init1.getClassName().equals(init2.getClassName()) && init1.isStatic() == init2.isStatic();
}
}
return false;
}

private boolean matchingPeekMethod(Method rightMethod, BlockTrackerChangeHistory startBlockChangeHistory) {
if(!startBlockChangeHistory.isEmpty()) {
VariableDeclarationContainer container = startBlockChangeHistory.peek().getOperation();
Expand Down Expand Up @@ -1549,7 +1578,7 @@ private void checkIfJavadocChanged(Version currentVersion, Version parentVersion
Comment startComment = (Comment)key2;
if (startComment.getLocation().getCodeElementType().equals(CodeElementType.JAVADOC)) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand All @@ -1571,7 +1600,7 @@ else if (leftJavadoc == null && rightJavadoc != null) {
Comment startComment = (Comment)key2;
if (startComment.getLocation().getCodeElementType().equals(CodeElementType.JAVADOC)) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand Down Expand Up @@ -1638,7 +1667,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand All @@ -1658,7 +1687,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null) {
Expand Down Expand Up @@ -1716,7 +1745,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand All @@ -1735,7 +1764,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null) {
Expand Down
55 changes: 42 additions & 13 deletions src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ private void processAddedMethods(UMLModel rightModel, UMLModelDiff umlModelDiffA
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
Expand All @@ -778,7 +778,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
if (currentAnnotation == null) {
Expand Down Expand Up @@ -1007,7 +1007,7 @@ private void processLocallyRefactoredMethods(Map<Method, MethodTrackerChangeHist
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null) {
Expand Down Expand Up @@ -1118,8 +1118,7 @@ else if(startMethodChangeHistory.isMethodAdded(umlModelDiff, rightMethod.getUmlO
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(rightMethod.getUmlOperation())) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
if (matchingMethod(rightMethod, startComment) || matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.poll();
if (currentComment == null) {
continue;
Expand All @@ -1134,7 +1133,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(rightMethod.getUmlOperation())) ||
if (matchingMethod(rightMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
if (currentAnnotation == null) {
Expand All @@ -1152,6 +1151,36 @@ else if (key2 instanceof Annotation) {
}
}

private boolean matchingMethod(Method rightMethod, Comment startComment) {
if(startComment.getOperation().isPresent()) {
VariableDeclarationContainer container = startComment.getOperation().get();
if(container instanceof UMLOperation) {
return container.equals(rightMethod.getUmlOperation());
}
else if(container instanceof UMLInitializer && rightMethod.getUmlOperation() instanceof UMLInitializer) {
UMLInitializer init1 = (UMLInitializer)container;
UMLInitializer init2 = (UMLInitializer)rightMethod.getUmlOperation();
return init1.getClassName().equals(init2.getClassName()) && init1.isStatic() == init2.isStatic();
}
}
return false;
}

private boolean matchingMethod(Method rightMethod, Annotation startAnnotation) {
if(startAnnotation.getOperation().isPresent()) {
VariableDeclarationContainer container = startAnnotation.getOperation().get();
if(container instanceof UMLOperation) {
return container.equals(rightMethod.getUmlOperation());
}
else if(container instanceof UMLInitializer && rightMethod.getUmlOperation() instanceof UMLInitializer) {
UMLInitializer init1 = (UMLInitializer)container;
UMLInitializer init2 = (UMLInitializer)rightMethod.getUmlOperation();
return init1.getClassName().equals(init2.getClassName()) && init1.isStatic() == init2.isStatic();
}
}
return false;
}

private boolean matchingPeekMethod(Method rightMethod, BlockTrackerChangeHistory startBlockChangeHistory) {
if(!startBlockChangeHistory.isEmpty()) {
VariableDeclarationContainer container = startBlockChangeHistory.peek().getOperation();
Expand Down Expand Up @@ -1556,7 +1585,7 @@ private void checkIfJavadocChanged(Version currentVersion, Version parentVersion
Comment startComment = (Comment)key2;
if (startComment.getLocation().getCodeElementType().equals(CodeElementType.JAVADOC)) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand All @@ -1578,7 +1607,7 @@ else if (leftJavadoc == null && rightJavadoc != null) {
Comment startComment = (Comment)key2;
if (startComment.getLocation().getCodeElementType().equals(CodeElementType.JAVADOC)) {
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand Down Expand Up @@ -1645,7 +1674,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand All @@ -1665,7 +1694,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null) {
Expand Down Expand Up @@ -1723,7 +1752,7 @@ else if (leftOperation instanceof UMLInitializer && rightOperation instanceof UM
else if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
CommentTrackerChangeHistory startCommentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
if ((startComment.getOperation().isPresent() && startComment.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startComment) ||
matchingPeekMethod(rightMethod, startCommentChangeHistory)) {
Comment currentComment = startCommentChangeHistory.peek();
if (currentComment == null) {
Expand All @@ -1742,7 +1771,7 @@ else if (key2 instanceof Comment) {
else if (key2 instanceof Annotation) {
Annotation startAnnotation = (Annotation)key2;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getOperation().isPresent() && startAnnotation.getOperation().get().equals(startMethod.getUmlOperation())) ||
if (matchingMethod(startMethod, startAnnotation) ||
matchingPeekMethod(rightMethod, startAnnotationChangeHistory)) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null) {
Expand Down
Loading

0 comments on commit dd38ce9

Please sign in to comment.