Skip to content

Commit

Permalink
Handle class annotation changes in FileTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 25, 2024
1 parent f7a6d5b commit 3a59940
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
52 changes: 52 additions & 0 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ else if (leftClass != null && (annotationChanged || modifiersChanged)) {
Set<Class> classRefactored = startClassChangeHistory.analyseClassRefactorings(refactorings, currentVersion, parentVersion, rightClass::equalIdentifierIgnoringVersion);
boolean refactored = !classRefactored.isEmpty();
if (refactored) {
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
if (leftSuperclass != null && rightSuperclass != null) {
if (!leftSuperclass.equals(rightSuperclass)) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
}
else if (leftSuperclass != null && rightSuperclass == null) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
else if (leftSuperclass == null && rightSuperclass != null) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
if (!leftClass.getUmlClass().getImplementedInterfaces().equals(rightClass.getUmlClass().getImplementedInterfaces())) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
checkSignatureFormatChange(startClassChangeHistory, leftClass, rightClass);
Map<Method, MethodTrackerChangeHistory> notFoundMethods = processMethodsWithSameSignature(rightModel, currentVersion, leftModel, parentVersion);
Map<Attribute, AttributeTrackerChangeHistory> notFoundAttributes = processAttributesWithSameSignature(rightModel, currentVersion, leftModel, parentVersion);
Map<Class, ClassTrackerChangeHistory> notFoundInnerClasses = new LinkedHashMap<>();
Expand Down Expand Up @@ -514,6 +535,20 @@ else if (key instanceof Comment) {
}
}
}
else if (key instanceof Annotation) {
Annotation startAnnotation = (Annotation)key;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if (startAnnotation.getClazz().isPresent()) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation != null) {
Annotation annotationBefore = Annotation.of(rightAnnotation.getAnnotation(), rightAnnotation.getClazz().get(), parentVersion);
startAnnotationChangeHistory.get().handleAdd(annotationBefore, rightAnnotation, "added with class");
startAnnotationChangeHistory.add(annotationBefore);
startAnnotationChangeHistory.get().connectRelatedNodes();
}
}
}
}
}

Expand Down Expand Up @@ -552,6 +587,23 @@ else if (key instanceof Comment) {
startCommentChangeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightComment::equalIdentifierIgnoringVersion, classDiff);
}
}
else if (key instanceof Annotation) {
Annotation startAnnotation = (Annotation)key;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getClazz().isPresent() && startAnnotation.getClazz().get().equals(rightClass.getUmlClass())) ||
(!startAnnotationChangeHistory.isEmpty() && startAnnotationChangeHistory.peek().getClazz().isPresent() && rightClass.getUmlClass().equals(startAnnotationChangeHistory.peek().getClazz().get()))) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null || currentAnnotation.isAdded()) {
continue;
}
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation == null) {
continue;
}
startAnnotationChangeHistory.poll();
startAnnotationChangeHistory.checkBodyOfMatchedClasses(currentVersion, currentVersion, rightAnnotation::equalIdentifierIgnoringVersion, classDiff);
}
}
}
}

Expand Down
52 changes: 52 additions & 0 deletions src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,27 @@ else if (leftClass != null && (annotationChanged || modifiersChanged)) {
Set<Class> classRefactored = startClassChangeHistory.analyseClassRefactorings(refactorings, currentVersion, parentVersion, rightClass::equalIdentifierIgnoringVersion);
boolean refactored = !classRefactored.isEmpty();
if (refactored) {
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
if (leftSuperclass != null && rightSuperclass != null) {
if (!leftSuperclass.equals(rightSuperclass)) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
}
else if (leftSuperclass != null && rightSuperclass == null) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
else if (leftSuperclass == null && rightSuperclass != null) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SUPERCLASS_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
if (!leftClass.getUmlClass().getImplementedInterfaces().equals(rightClass.getUmlClass().getImplementedInterfaces())) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
checkSignatureFormatChange(startClassChangeHistory, leftClass, rightClass);
Map<Method, MethodTrackerChangeHistory> notFoundMethods = processMethodsWithSameSignature(rightModel, currentVersion, leftModel, parentVersion);
Map<Attribute, AttributeTrackerChangeHistory> notFoundAttributes = processAttributesWithSameSignature(rightModel, currentVersion, leftModel, parentVersion);
Map<Class, ClassTrackerChangeHistory> notFoundInnerClasses = new LinkedHashMap<>();
Expand Down Expand Up @@ -521,6 +542,20 @@ else if (key instanceof Comment) {
}
}
}
else if (key instanceof Annotation) {
Annotation startAnnotation = (Annotation)key;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if (startAnnotation.getClazz().isPresent()) {
Annotation currentAnnotation = startAnnotationChangeHistory.poll();
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation != null) {
Annotation annotationBefore = Annotation.of(rightAnnotation.getAnnotation(), rightAnnotation.getClazz().get(), parentVersion);
startAnnotationChangeHistory.get().handleAdd(annotationBefore, rightAnnotation, "added with class");
startAnnotationChangeHistory.add(annotationBefore);
startAnnotationChangeHistory.get().connectRelatedNodes();
}
}
}
}
}

Expand Down Expand Up @@ -559,6 +594,23 @@ else if (key instanceof Comment) {
startCommentChangeHistory.checkBodyOfMatchedClasses(currentVersion, parentVersion, rightComment::equalIdentifierIgnoringVersion, classDiff);
}
}
else if (key instanceof Annotation) {
Annotation startAnnotation = (Annotation)key;
AnnotationTrackerChangeHistory startAnnotationChangeHistory = (AnnotationTrackerChangeHistory) programElementMap.get(startAnnotation);
if ((startAnnotation.getClazz().isPresent() && startAnnotation.getClazz().get().equals(rightClass.getUmlClass())) ||
(!startAnnotationChangeHistory.isEmpty() && startAnnotationChangeHistory.peek().getClazz().isPresent() && rightClass.getUmlClass().equals(startAnnotationChangeHistory.peek().getClazz().get()))) {
Annotation currentAnnotation = startAnnotationChangeHistory.peek();
if (currentAnnotation == null || currentAnnotation.isAdded()) {
continue;
}
Annotation rightAnnotation = rightClass.findAnnotation(currentAnnotation::equalIdentifierIgnoringVersion);
if (rightAnnotation == null) {
continue;
}
startAnnotationChangeHistory.poll();
startAnnotationChangeHistory.checkBodyOfMatchedClasses(currentVersion, currentVersion, rightAnnotation::equalIdentifierIgnoringVersion, classDiff);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/blame/blameTestWithLocalRepo7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ c1d682aee junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor
470866bc1 junit5-engine/src/main/java/org/junit/gen5/engine/junit5/descriptor/ClassTestDescriptor.java (JUnit Team 2015-12-09 09:08:59 +0000 70) *
470866bc1 junit5-engine/src/main/java/org/junit/gen5/engine/junit5/descriptor/ClassTestDescriptor.java (JUnit Team 2015-12-09 09:08:59 +0000 71) * @since 5.0
470866bc1 junit5-engine/src/main/java/org/junit/gen5/engine/junit5/descriptor/ClassTestDescriptor.java (JUnit Team 2015-12-09 09:08:59 +0000 72) */
73) @API(status = INTERNAL, since = "5.0")
a1a607b96 junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ClassTestDescriptor.java (JUnit Team 2017-09-08 15:25:31 +0000 73) @API(status = INTERNAL, since = "5.0")
babcc661b junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ClassTestDescriptor.java (JUnit Team 2016-06-20 13:08:43 +0000 74) public class ClassTestDescriptor extends JupiterTestDescriptor {
75)
e0e131335 junit5-engine/src/main/java/org/junit/gen5/engine/junit5/descriptor/ClassTestDescriptor.java (Sam Brannen 2016-05-28 17:02:34 +0000 76) private static final ExecutableInvoker executableInvoker = new ExecutableInvoker();
Expand Down

0 comments on commit 3a59940

Please sign in to comment.