Skip to content

Commit

Permalink
Add FileTracker blame test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 18, 2024
1 parent 6076992 commit 20e0683
Show file tree
Hide file tree
Showing 7 changed files with 1,890 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,17 @@ public void blame() throws Exception {
boolean annotationChanged = false;
if(leftClass == null) {
leftClass = getClass(leftModel, parentVersion, rightClass::equalIdentifierIgnoringVersionAndAnnotation);
annotationChanged = true;
if(leftClass != null)
annotationChanged = true;
}
boolean modifiersChanged = false;
if(leftClass == null) {
leftClass = getClass(leftModel, parentVersion, rightClass::equalIdentifierIgnoringVersionAndModifiers);
if(leftClass != null)
modifiersChanged = true;
}
// No class signature change
if (leftClass != null && !annotationChanged) {
if (leftClass != null && !annotationChanged && !modifiersChanged) {
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
if (leftSuperclass != null && rightSuperclass != null) {
Expand Down Expand Up @@ -314,7 +321,7 @@ else if (leftSuperclass == null && rightSuperclass != null) {
}
continue;
}
else if (leftClass != null && annotationChanged) {
else if (leftClass != null && (annotationChanged || modifiersChanged)) {
UMLModelDiff umlModelDiffLocal = leftModel.diff(rightModel);
List<Refactoring> refactorings = umlModelDiffLocal.getRefactorings();
Set<Class> classRefactored = startClassChangeHistory.analyseClassRefactorings(refactorings, currentVersion, parentVersion, rightClass::equalIdentifierIgnoringVersion);
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,17 @@ public void blame() throws Exception {
boolean annotationChanged = false;
if(leftClass == null) {
leftClass = getClass(leftModel, parentVersion, rightClass::equalIdentifierIgnoringVersionAndAnnotation);
annotationChanged = true;
if(leftClass != null)
annotationChanged = true;
}
boolean modifiersChanged = false;
if(leftClass == null) {
leftClass = getClass(leftModel, parentVersion, rightClass::equalIdentifierIgnoringVersionAndModifiers);
if(leftClass != null)
modifiersChanged = true;
}
// No class signature change
if (leftClass != null && !annotationChanged) {
if (leftClass != null && !annotationChanged && !modifiersChanged) {
UMLType leftSuperclass = leftClass.getUmlClass().getSuperclass();
UMLType rightSuperclass = rightClass.getUmlClass().getSuperclass();
if (leftSuperclass != null && rightSuperclass != null) {
Expand Down Expand Up @@ -322,7 +329,7 @@ else if (leftSuperclass == null && rightSuperclass != null) {
}
continue;
}
else if (leftClass != null && annotationChanged) {
else if (leftClass != null && (annotationChanged || modifiersChanged)) {
UMLModelDiff umlModelDiffLocal = leftModel.diff(rightModel);
List<Refactoring> refactorings = umlModelDiffLocal.getRefactorings();
Set<Class> classRefactored = startClassChangeHistory.analyseClassRefactorings(refactorings, currentVersion, parentVersion, rightClass::equalIdentifierIgnoringVersion);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/codetracker/element/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import gr.uom.java.xmi.decomposition.StatementObject;

import org.codetracker.api.Version;
import org.refactoringminer.util.PrefixSuffixUtils;

import static org.codetracker.util.Util.annotationsToString;
import static org.codetracker.util.Util.getPath;
Expand Down Expand Up @@ -58,7 +59,19 @@ public boolean differInFormatting(Attribute other) {
String thisSignature = umlAttribute.getVariableDeclaration().getActualSignature();
String otherSignature = other.umlAttribute.getVariableDeclaration().getActualSignature();
if (thisSignature != null && otherSignature != null) {
return !thisSignature.equals(otherSignature) && thisSignature.replaceAll("\\s+","").equals(otherSignature.replaceAll("\\s+",""));
if(!thisSignature.equals(otherSignature)) {
//whitespace change
if(thisSignature.replaceAll("\\s+","").equals(otherSignature.replaceAll("\\s+",""))) {
return true;
}
else {
String prefix = PrefixSuffixUtils.longestCommonPrefix(thisSignature, otherSignature);
String suffix = PrefixSuffixUtils.longestCommonSuffix(thisSignature, otherSignature);
if(!prefix.isEmpty() && !suffix.isEmpty()) {
return true;
}
}
}
}
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/codetracker/element/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
public class Class extends BaseCodeElement {
private final UMLAbstractClass umlClass;
private final String identifierIgnoringVersionAndAnnotation;
private final String identifierIgnoringVersionAndModifiers;

private Class(UMLAbstractClass umlClass, String identifierExcludeVersion, String identifierExcludeVersionAndAnnotation, String name, String filePath, Version version) {
private Class(UMLAbstractClass umlClass, String identifierExcludeVersion, String identifierExcludeVersionAndAnnotation, String identifierIgnoringVersionAndModifiers, String name, String filePath, Version version) {
super(identifierExcludeVersion, name, filePath, version);
this.umlClass = umlClass;
this.identifierIgnoringVersionAndAnnotation = identifierExcludeVersionAndAnnotation;
this.identifierIgnoringVersionAndModifiers = identifierIgnoringVersionAndModifiers;
}

public BaseCodeElement of(Version version) {
Expand All @@ -43,8 +45,9 @@ public static Class of(UMLAbstractClass umlClass, Version version) {
String visibility = umlClass.getVisibility().toString();
String identifierExcludeVersion = String.format("%s%s.(%s)%s(%s)%s%s", sourceFolder, packageName, visibility, modifiersString, umlClass.getTypeDeclarationKind(), name, annotationsToString(umlClass.getAnnotations()));
String identifierExcludeVersionAndAnnotation = String.format("%s%s.(%s)%s(%s)%s", sourceFolder, packageName, visibility, modifiersString, umlClass.getTypeDeclarationKind(), name);
String identifierExcludeVersionAndModifiers = String.format("%s%s.(%s)(%s)%s%s", sourceFolder, packageName, visibility, umlClass.getTypeDeclarationKind(), name, annotationsToString(umlClass.getAnnotations()));
String className = String.format("%s%s.(%s)%s%s(%d)", sourceFolder, packageName, visibility, modifiersString, name, umlClass.getLocationInfo().getStartLine());
return new Class(umlClass, identifierExcludeVersion, identifierExcludeVersionAndAnnotation, className, umlClass.getLocationInfo().getFilePath(), version);
return new Class(umlClass, identifierExcludeVersion, identifierExcludeVersionAndAnnotation, identifierExcludeVersionAndModifiers, className, umlClass.getLocationInfo().getFilePath(), version);
}

public boolean differInFormatting(Class other) {
Expand Down Expand Up @@ -153,6 +156,10 @@ public boolean equalIdentifierIgnoringVersionAndAnnotation(Class clazz) {
return this.identifierIgnoringVersionAndAnnotation.equals(clazz.identifierIgnoringVersionAndAnnotation);
}

public boolean equalIdentifierIgnoringVersionAndModifiers(Class clazz) {
return this.identifierIgnoringVersionAndModifiers.equals(clazz.identifierIgnoringVersionAndModifiers);
}

public void checkClosingBracket(int lineNumber) {
if (getLocation().getEndLine() == lineNumber) {
setClosingCurlyBracket(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private static Stream<Arguments> testBlamerInputProvider(){
"https://github.com/hibernate/hibernate-orm/commit/8bd79b29cfa7b2d539a746dc356d60b66e1e596b, hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java, /src/test/resources/blame/blameTestWithLocalRepo8.txt",
"https://github.com/apache/flink/commit/9e936a5f8198b0059e9b5fba33163c2bbe3efbdd, flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/DataStream.java, /src/test/resources/blame/blameTestWithLocalRepo9.txt",
"https://github.com/checkstyle/checkstyle/commit/119fd4fb33bef9f5c66fc950396669af842c21a3, src/main/java/com/puppycrawl/tools/checkstyle/TreeWalker.java, /src/test/resources/blame/blameTestWithLocalRepo10.txt",
"https://github.com/apache/commons-lang/commit/a36c903d4f1065bc59f5e6d2bb0f9d92a5e71d83, src/main/java/org/apache/commons/lang3/time/DateUtils.java, /src/test/resources/blame/blameTestWithLocalRepo11.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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class CodeTrackerBlameWithLocalFilesTest {
"https://github.com/hibernate/hibernate-orm/commit/8bd79b29cfa7b2d539a746dc356d60b66e1e596b, hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java, /src/test/resources/blame/blameTestWithLocalRepo8.txt",
//"https://github.com/apache/flink/commit/9e936a5f8198b0059e9b5fba33163c2bbe3efbdd, flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/DataStream.java, /src/test/resources/blame/blameTestWithLocalRepo9.txt",
"https://github.com/checkstyle/checkstyle/commit/119fd4fb33bef9f5c66fc950396669af842c21a3, src/main/java/com/puppycrawl/tools/checkstyle/TreeWalker.java, /src/test/resources/blame/blameTestWithLocalRepo10.txt",
"https://github.com/apache/commons-lang/commit/a36c903d4f1065bc59f5e6d2bb0f9d92a5e71d83, src/main/java/org/apache/commons/lang3/time/DateUtils.java, /src/test/resources/blame/blameTestWithLocalRepo11.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 20e0683

Please sign in to comment.