From 0345a291c007faa3a466f5c5080b49b338b4435f Mon Sep 17 00:00:00 2001 From: tsantalis Date: Tue, 17 Sep 2024 16:19:30 -0400 Subject: [PATCH] Support type parameter changes in MethodTracker --- .../org/codetracker/MethodTrackerImpl.java | 32 +++++++++++++++++++ .../MethodTrackerWithLocalFilesImpl.java | 16 ++++++++++ .../java/org/codetracker/change/Change.java | 1 + .../org/codetracker/change/ChangeFactory.java | 4 +++ .../method/MethodTypeParameterChange.java | 9 ++++++ .../training/junit5-NodeTestTask-execute.json | 10 ++++++ .../resources/method/training-expected.txt | 2 +- 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/codetracker/change/method/MethodTypeParameterChange.java diff --git a/src/main/java/org/codetracker/MethodTrackerImpl.java b/src/main/java/org/codetracker/MethodTrackerImpl.java index 577a160de4b..eaede546817 100644 --- a/src/main/java/org/codetracker/MethodTrackerImpl.java +++ b/src/main/java/org/codetracker/MethodTrackerImpl.java @@ -87,6 +87,24 @@ public History 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; } @@ -99,6 +117,20 @@ public History 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(); diff --git a/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java b/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java index e4bac74dcf7..0068c960c9d 100644 --- a/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java +++ b/src/main/java/org/codetracker/MethodTrackerWithLocalFilesImpl.java @@ -100,6 +100,15 @@ public History 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; } @@ -112,6 +121,13 @@ public History 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(); diff --git a/src/main/java/org/codetracker/change/Change.java b/src/main/java/org/codetracker/change/Change.java index ba0d0b493e9..df77c1cbbc2 100644 --- a/src/main/java/org/codetracker/change/Change.java +++ b/src/main/java/org/codetracker/change/Change.java @@ -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"), diff --git a/src/main/java/org/codetracker/change/ChangeFactory.java b/src/main/java/org/codetracker/change/ChangeFactory.java index 8928710c7d7..2ffc2489520 100644 --- a/src/main/java/org/codetracker/change/ChangeFactory.java +++ b/src/main/java/org/codetracker/change/ChangeFactory.java @@ -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; diff --git a/src/main/java/org/codetracker/change/method/MethodTypeParameterChange.java b/src/main/java/org/codetracker/change/method/MethodTypeParameterChange.java new file mode 100644 index 00000000000..4b55d38c654 --- /dev/null +++ b/src/main/java/org/codetracker/change/method/MethodTypeParameterChange.java @@ -0,0 +1,9 @@ +package org.codetracker.change.method; + +public class MethodTypeParameterChange extends MethodSignatureChange { + + public MethodTypeParameterChange() { + super(Type.TYPE_PARAMETER_CHANGE); + } + +} diff --git a/src/main/resources/oracle/method/training/junit5-NodeTestTask-execute.json b/src/main/resources/oracle/method/training/junit5-NodeTestTask-execute.json index c0d09b74419..9c99923398b 100644 --- a/src/main/resources/oracle/method/training/junit5-NodeTestTask-execute.json +++ b/src/main/resources/oracle/method/training/junit5-NodeTestTask-execute.json @@ -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", diff --git a/src/test/resources/method/training-expected.txt b/src/test/resources/method/training-expected.txt index e7db1be3ee9..7db492705a2 100644 --- a/src/test/resources/method/training-expected.txt +++ b/src/test/resources/method/training-expected.txt @@ -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