Skip to content

Commit

Permalink
Signature format change for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 5, 2024
1 parent 0fc7302 commit 947ece9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -946,11 +946,11 @@ public HistoryInfo<Comment> blameReturn() {
return null;
}

public HistoryInfo<Comment> blameReturn(int exactLineNumber) {
public HistoryInfo<Comment> blameReturn(Comment startComment, int exactLineNumber) {
List<HistoryInfo<Comment>> history = getHistory();
for (History.HistoryInfo<Comment> historyInfo : history) {
Pair<Comment, Comment> pair = Pair.of(historyInfo.getElementBefore(), historyInfo.getElementAfter());
boolean multiLine = historyInfo.getElementBefore().isMultiLine() && historyInfo.getElementAfter().isMultiLine();
boolean multiLine = startComment.isMultiLine();
for (Change change : historyInfo.getChangeList()) {
if (change instanceof Introduced) {
return historyInfo;
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/org/codetracker/FileTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ else if (leftSuperclass == null && rightSuperclass != null) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
startClassChangeHistory.processChange(leftClass, rightClass);
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 @@ -409,7 +409,7 @@ else if (startElement instanceof Class) {
else if (startElement instanceof Comment) {
Comment startComment = (Comment)startElement;
CommentTrackerChangeHistory commentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
HistoryInfo<Comment> historyInfo = commentChangeHistory.blameReturn(lineNumber);
HistoryInfo<Comment> historyInfo = commentChangeHistory.blameReturn(startComment, lineNumber);
blameInfo.put(lineNumber, historyInfo);
}
else if (startElement instanceof Import) {
Expand Down Expand Up @@ -1094,7 +1094,7 @@ else if (leftSuperclass == null && rightSuperclass != null) {
startInnerClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
startInnerClassChangeHistory.get().connectRelatedNodes();
}
startInnerClassChangeHistory.processChange(leftClass, rightClass);
checkSignatureFormatChange(startInnerClassChangeHistory, leftClass, rightClass);
startInnerClassChangeHistory.setCurrent(leftClass);
startInnerClassChangeHistory.addFirst(leftClass);
foundInnerClasses.add(Pair.of(leftClass, rightClass));
Expand Down Expand Up @@ -1185,7 +1185,7 @@ private Map<Attribute, AttributeTrackerChangeHistory> processAttributesWithSameS
if (leftAttribute != null) {
startAttributeChangeHistory.setCurrent(leftAttribute);
startAttributeChangeHistory.checkInitializerChange(rightAttribute, leftAttribute);
checkSignatureFormatChange(startAttributeChangeHistory, rightAttribute, leftAttribute);
checkSignatureFormatChange(startAttributeChangeHistory, leftAttribute, rightAttribute);
for (CodeElement key2 : programElementMap.keySet()) {
if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
Expand Down Expand Up @@ -1252,7 +1252,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
if (leftMethod != null) {
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
continue;
}
//CHANGE BODY OR DOCUMENT
Expand Down Expand Up @@ -1281,7 +1281,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
if (!leftMethod.equalDocuments(rightMethod))
startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
startMethodChangeHistory.get().connectRelatedNodes();
startMethodChangeHistory.elements.remove(currentMethod);
startMethodChangeHistory.elements.add(leftMethod);
Expand Down Expand Up @@ -1309,7 +1309,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
if (leftMethod != null) {
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
startMethodChangeHistory.setCurrent(leftMethod);
continue;
}
Expand Down Expand Up @@ -1339,7 +1339,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
if (!leftMethod.equalDocuments(rightMethod))
startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
startMethodChangeHistory.get().connectRelatedNodes();
startMethodChangeHistory.setCurrent(leftMethod);
processNestedStatementsAndComments(rightModel, currentVersion, leftModel, parentVersion,
Expand All @@ -1351,15 +1351,23 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
return notFoundMethods;
}

private void checkSignatureFormatChange(MethodTrackerChangeHistory startMethodChangeHistory, Method rightMethod, Method leftMethod) {
private void checkSignatureFormatChange(ClassTrackerChangeHistory startClassChangeHistory, Class leftClass, Class rightClass) {
if (leftClass.differInFormatting(rightClass)) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SIGNATURE_FORMAT_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
startClassChangeHistory.processChange(leftClass, rightClass);
}

private void checkSignatureFormatChange(MethodTrackerChangeHistory startMethodChangeHistory, Method leftMethod, Method rightMethod) {
if (leftMethod.differInFormatting(rightMethod)) {
startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.SIGNATURE_FORMAT_CHANGE));
startMethodChangeHistory.processChange(leftMethod, rightMethod);
startMethodChangeHistory.get().connectRelatedNodes();
}
}

private void checkSignatureFormatChange(AttributeTrackerChangeHistory startAtributeChangeHistory, Attribute rightAttribute, Attribute leftAttribute) {
private void checkSignatureFormatChange(AttributeTrackerChangeHistory startAtributeChangeHistory, Attribute leftAttribute, Attribute rightAttribute) {
if (leftAttribute.differInFormatting(rightAttribute)) {
startAtributeChangeHistory.get().addChange(leftAttribute, rightAttribute, ChangeFactory.forAttribute(Change.Type.SIGNATURE_FORMAT_CHANGE));
startAtributeChangeHistory.processChange(leftAttribute, rightAttribute);
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ else if (leftSuperclass == null && rightSuperclass != null) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
startClassChangeHistory.processChange(leftClass, rightClass);
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 @@ -417,7 +417,7 @@ else if (startElement instanceof Class) {
else if (startElement instanceof Comment) {
Comment startComment = (Comment)startElement;
CommentTrackerChangeHistory commentChangeHistory = (CommentTrackerChangeHistory) programElementMap.get(startComment);
HistoryInfo<Comment> historyInfo = commentChangeHistory.blameReturn(lineNumber);
HistoryInfo<Comment> historyInfo = commentChangeHistory.blameReturn(startComment, lineNumber);
blameInfo.put(lineNumber, historyInfo);
}
else if (startElement instanceof Import) {
Expand Down Expand Up @@ -1101,7 +1101,7 @@ else if (leftSuperclass == null && rightSuperclass != null) {
startInnerClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.INTERFACE_LIST_CHANGE));
startInnerClassChangeHistory.get().connectRelatedNodes();
}
startInnerClassChangeHistory.processChange(leftClass, rightClass);
checkSignatureFormatChange(startInnerClassChangeHistory, leftClass, rightClass);
startInnerClassChangeHistory.setCurrent(leftClass);
startInnerClassChangeHistory.addFirst(leftClass);
foundInnerClasses.add(Pair.of(leftClass, rightClass));
Expand Down Expand Up @@ -1192,7 +1192,7 @@ private Map<Attribute, AttributeTrackerChangeHistory> processAttributesWithSameS
if (leftAttribute != null) {
startAttributeChangeHistory.setCurrent(leftAttribute);
startAttributeChangeHistory.checkInitializerChange(rightAttribute, leftAttribute);
checkSignatureFormatChange(startAttributeChangeHistory, rightAttribute, leftAttribute);
checkSignatureFormatChange(startAttributeChangeHistory, leftAttribute, rightAttribute);
for (CodeElement key2 : programElementMap.keySet()) {
if (key2 instanceof Comment) {
Comment startComment = (Comment)key2;
Expand Down Expand Up @@ -1259,7 +1259,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
if (leftMethod != null) {
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
continue;
}
//CHANGE BODY OR DOCUMENT
Expand Down Expand Up @@ -1288,7 +1288,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
if (!leftMethod.equalDocuments(rightMethod))
startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
startMethodChangeHistory.get().connectRelatedNodes();
startMethodChangeHistory.elements.remove(currentMethod);
startMethodChangeHistory.elements.add(leftMethod);
Expand Down Expand Up @@ -1316,7 +1316,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
if (leftMethod != null) {
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
startMethodChangeHistory.setCurrent(leftMethod);
continue;
}
Expand Down Expand Up @@ -1346,7 +1346,7 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
if (!leftMethod.equalDocuments(rightMethod))
startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
checkIfJavadocChanged(currentVersion, parentVersion, startMethod, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, rightMethod, leftMethod);
checkSignatureFormatChange(startMethodChangeHistory, leftMethod, rightMethod);
startMethodChangeHistory.get().connectRelatedNodes();
startMethodChangeHistory.setCurrent(leftMethod);
processNestedStatementsAndComments(rightModel, currentVersion, leftModel, parentVersion,
Expand All @@ -1358,15 +1358,23 @@ private Map<Method, MethodTrackerChangeHistory> processMethodsWithSameSignature(
return notFoundMethods;
}

private void checkSignatureFormatChange(MethodTrackerChangeHistory startMethodChangeHistory, Method rightMethod, Method leftMethod) {
private void checkSignatureFormatChange(ClassTrackerChangeHistory startClassChangeHistory, Class leftClass, Class rightClass) {
if (leftClass.differInFormatting(rightClass)) {
startClassChangeHistory.get().addChange(leftClass, rightClass, ChangeFactory.forClass(Change.Type.SIGNATURE_FORMAT_CHANGE));
startClassChangeHistory.get().connectRelatedNodes();
}
startClassChangeHistory.processChange(leftClass, rightClass);
}

private void checkSignatureFormatChange(MethodTrackerChangeHistory startMethodChangeHistory, Method leftMethod, Method rightMethod) {
if (leftMethod.differInFormatting(rightMethod)) {
startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.SIGNATURE_FORMAT_CHANGE));
startMethodChangeHistory.processChange(leftMethod, rightMethod);
startMethodChangeHistory.get().connectRelatedNodes();
}
}

private void checkSignatureFormatChange(AttributeTrackerChangeHistory startAtributeChangeHistory, Attribute rightAttribute, Attribute leftAttribute) {
private void checkSignatureFormatChange(AttributeTrackerChangeHistory startAtributeChangeHistory, Attribute leftAttribute, Attribute rightAttribute) {
if (leftAttribute.differInFormatting(rightAttribute)) {
startAtributeChangeHistory.get().addChange(leftAttribute, rightAttribute, ChangeFactory.forAttribute(Change.Type.SIGNATURE_FORMAT_CHANGE));
startAtributeChangeHistory.processChange(leftAttribute, rightAttribute);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/codetracker/change/ChangeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ public AbstractChange build() {
change = new MethodSignatureFormatChange();
else if (isAttribute())
change = new AttributeSignatureFormatChange();
else if (isClass())
change = new ClassSignatureFormatChange();
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.codetracker.change.clazz;

public class ClassSignatureFormatChange extends ClassChange {

public ClassSignatureFormatChange() {
super(Type.SIGNATURE_FORMAT_CHANGE);
}

}
11 changes: 11 additions & 0 deletions src/main/java/org/codetracker/element/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ public static Class of(UMLAbstractClass umlClass, Version version) {
return new Class(umlClass, identifierExcludeVersion, className, umlClass.getLocationInfo().getFilePath(), version);
}

public boolean differInFormatting(Class other) {
if (umlClass instanceof UMLClass && other.umlClass instanceof UMLClass) {
String thisSignature = ((UMLClass) umlClass).getActualSignature();
String otherSignature = ((UMLClass) other.umlClass).getActualSignature();
if (thisSignature != null && otherSignature != null) {
return !thisSignature.equals(otherSignature) && thisSignature.replaceAll("\\s+","").equals(otherSignature.replaceAll("\\s+",""));
}
}
return false;
}

public int signatureStartLine() {
int classSignatureStartLine = -1;
if (umlClass instanceof UMLClass) {
Expand Down

0 comments on commit 947ece9

Please sign in to comment.