Skip to content

Commit

Permalink
Support type parameter changes in MethodTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 17, 2024
1 parent c8a5423 commit 0345a29
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/main/java/org/codetracker/MethodTrackerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ public History<Method> track() throws Exception {
//NO CHANGE
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
if (leftMethod != null) {
/*
UMLJavadoc leftJavadoc = leftMethod.getUmlOperation().getJavadoc();
UMLJavadoc rightJavadoc = rightMethod.getUmlOperation().getJavadoc();
if (leftJavadoc != null && rightJavadoc != null && !leftJavadoc.getFullText().equals(rightJavadoc.getFullText())) {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
changeHistory.get().connectRelatedNodes();
currentMethod = leftMethod;
}
*/
if (leftMethod.getUmlOperation() instanceof UMLOperation && rightMethod.getUmlOperation() instanceof UMLOperation) {
UMLOperation leftOperation = (UMLOperation)leftMethod.getUmlOperation();
UMLOperation rightOperation = (UMLOperation)rightMethod.getUmlOperation();
if (!leftOperation.getTypeParameters().equals(rightOperation.getTypeParameters())) {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.TYPE_PARAMETER_CHANGE));
changeHistory.get().connectRelatedNodes();
currentMethod = leftMethod;
}
}
historyReport.step2PlusPlus();
continue;
}
Expand All @@ -99,6 +117,20 @@ public History<Method> track() throws Exception {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.BODY_CHANGE));
if (!leftMethod.equalDocuments(rightMethod))
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
/*
UMLJavadoc leftJavadoc = leftMethod.getUmlOperation().getJavadoc();
UMLJavadoc rightJavadoc = rightMethod.getUmlOperation().getJavadoc();
if (leftJavadoc != null && rightJavadoc != null && !leftJavadoc.getFullText().equals(rightJavadoc.getFullText())) {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
}
*/
if (leftMethod.getUmlOperation() instanceof UMLOperation && rightMethod.getUmlOperation() instanceof UMLOperation) {
UMLOperation leftOperation = (UMLOperation)leftMethod.getUmlOperation();
UMLOperation rightOperation = (UMLOperation)rightMethod.getUmlOperation();
if (!leftOperation.getTypeParameters().equals(rightOperation.getTypeParameters())) {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.TYPE_PARAMETER_CHANGE));
}
}
changeHistory.get().connectRelatedNodes();
currentMethod = leftMethod;
historyReport.step3PlusPlus();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public History<Method> track() throws Exception {
//NO CHANGE
Method leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersion);
if (leftMethod != null) {
if (leftMethod.getUmlOperation() instanceof UMLOperation && rightMethod.getUmlOperation() instanceof UMLOperation) {
UMLOperation leftOperation = (UMLOperation)leftMethod.getUmlOperation();
UMLOperation rightOperation = (UMLOperation)rightMethod.getUmlOperation();
if (!leftOperation.getTypeParameters().equals(rightOperation.getTypeParameters())) {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.TYPE_PARAMETER_CHANGE));
changeHistory.get().connectRelatedNodes();
currentMethod = leftMethod;
}
}
historyReport.step2PlusPlus();
continue;
}
Expand All @@ -112,6 +121,13 @@ public History<Method> track() throws Exception {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.BODY_CHANGE));
if (!leftMethod.equalDocuments(rightMethod))
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.DOCUMENTATION_CHANGE));
if (leftMethod.getUmlOperation() instanceof UMLOperation && rightMethod.getUmlOperation() instanceof UMLOperation) {
UMLOperation leftOperation = (UMLOperation)leftMethod.getUmlOperation();
UMLOperation rightOperation = (UMLOperation)rightMethod.getUmlOperation();
if (!leftOperation.getTypeParameters().equals(rightOperation.getTypeParameters())) {
changeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.TYPE_PARAMETER_CHANGE));
}
}
changeHistory.get().connectRelatedNodes();
currentMethod = leftMethod;
historyReport.step3PlusPlus();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/codetracker/change/Change.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum Type {
REPLACE_LOOP_WITH_PIPELINE("loop replaced with pipeline"),
REPLACE_CONDITIONAL_WITH_TERNARY("conditional replaced with ternary"),
DOCUMENTATION_CHANGE("documentation change"),
TYPE_PARAMETER_CHANGE("type parameter change"),
RENAME("rename"),
MODIFIER_CHANGE("modifier change"),
ACCESS_MODIFIER_CHANGE("access modifier change"),
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/codetracker/change/ChangeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public AbstractChange build() {
change = new DocumentationChange();
break;
}
case TYPE_PARAMETER_CHANGE: {
change = new MethodTypeParameterChange();
break;
}
case BODY_CHANGE: {
change = new BodyChange();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.codetracker.change.method;

public class MethodTypeParameterChange extends MethodSignatureChange {

public MethodTypeParameterChange() {
super(Type.TYPE_PARAMETER_CHANGE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,16 @@
"elementNameAfter": "junit-engine-api/src/main/java/org.junit.gen5.engine.HierarchicalTestEngine#executeAll(TestDescriptor, EngineExecutionListener, C)",
"comment": "Add Method Annotation @SuppressWarnings({\"unused\",\"unchecked\"}) in method private executeAll(parentDescriptor TestDescriptor, listener EngineExecutionListener, parentContext C) : void from class org.junit.gen5.engine.HierarchicalTestEngine"
},
{
"parentCommitId": "94a07d17a63802b99bbdab882e264eea06519053",
"commitId": "4c8ae138570195b329299f5af66a713bcb894102",
"commitTime": 1449828479,
"changeType": "type parameter change",
"elementFileBefore": "junit-engine-api/src/main/java/org/junit/gen5/engine/HierarchicalTestEngine.java",
"elementNameBefore": "junit-engine-api/src/main/java/org.junit.gen5.engine.HierarchicalTestEngine#executeAll(TestDescriptor, EngineExecutionListener, C)",
"elementFileAfter": "junit-engine-api/src/main/java/org/junit/gen5/engine/HierarchicalTestEngine.java",
"elementNameAfter": "junit-engine-api/src/main/java/org.junit.gen5.engine.HierarchicalTestEngine#executeAll(TestDescriptor, EngineExecutionListener, C)"
},
{
"parentCommitId": "0e14ad4525a5ade99dacdd76d0ab27223f57ebd4",
"commitId": "3f9c11b9326b7d3051cb2a50568cd91113a0c0da",
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/method/training-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ junit5-ClassTestDescriptor-prepare.json, 31, 0, 0
junit5-DefaultLauncher-discover.json, 39, 0, 0
junit5-DefaultLauncher-discoverRoot.json, 43, 0, 0
junit5-DefaultLauncher-execute.json, 49, 0, 0
junit5-NodeTestTask-execute.json, 59, 0, 0
junit5-NodeTestTask-execute.json, 60, 0, 0
junit5-TestFactoryTestDescriptor-invokeTestMethod.json, 34, 0, 0
junit5-TestMethodTestDescriptor-execute.json, 46, 0, 0
junit5-TestMethodTestDescriptor-invokeTestMethod.json, 45, 0, 0
Expand Down

0 comments on commit 0345a29

Please sign in to comment.