Skip to content

Commit

Permalink
Improved detection of Extract Class refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Feb 4, 2025
1 parent cf73358 commit 3dd3b4d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/main/java/gr/uom/java/xmi/UMLAbstractClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ public boolean containsOperationWithIdenticalBody(UMLOperation operation) {
return false;
}

public UMLOperation operationWithIdenticalBody(UMLOperation operation) {
if(operation.getBody() != null) {
for(UMLOperation originalOperation : operations) {
if(originalOperation.getBody() != null && originalOperation.getBodyHashCode() == operation.getBodyHashCode())
return originalOperation;
}
}
return null;
}

public boolean containsOperationWithIdenticalBodyAndActualSignature(UMLOperation operation) {
if(operation.getBody() != null) {
for(UMLOperation originalOperation : operations) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/gr/uom/java/xmi/UMLOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ public boolean hasDataProviderAnnotation() {
return false;
}

public boolean hasParametersAnnotation() {
for(UMLAnnotation annotation : annotations) {
if(annotation.getTypeName().equals("Parameters")) {
return true;
}
}
return false;
}

public UMLJavadoc getJavadoc() {
return javadoc;
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,12 @@ private ExtractClassRefactoring atLeastOneCommonAttributeOrOperation(UMLClass um
operation.getSynchronizedStatements().size() == matchedOperation.getSynchronizedStatements().size()) {
commonOperations.put(operation, matchedOperation);
}
if(matchedOperation == null && !operation.hasEmptyBody()) {
matchedOperation = umlClass.operationWithIdenticalBody(operation);
if(matchedOperation != null) {
commonOperations.put(operation, matchedOperation);
}
}
}
}
for(UMLOperation operation : classDiff.getRemovedOperations()) {
Expand Down Expand Up @@ -6109,9 +6115,10 @@ private boolean movedAndRenamedMethodSignature(UMLOperation removedOperation, UM
intersection.retainAll(newParameterNames);
boolean parameterMatch = oldParameters.equals(newParameters) || oldParameters.containsAll(newParameters) || newParameters.containsAll(oldParameters) || intersection.size() > 0 ||
removedOperation.isStatic() || addedOperation.isStatic();
boolean parametersAnnotation = removedOperation.hasParametersAnnotation() || addedOperation.hasParametersAnnotation();
return (parameterMatch && oldParameters.size() > 0 && newParameters.size() > 0) ||
(parameterMatch && addedOperation.equalReturnParameter(removedOperation) && (oldParameters.size() == 0 || newParameters.size() == 0)) ||
exactLeafMappings > 1;
exactLeafMappings > 1 || parametersAnnotation;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public void testAllRefactorings() throws Exception {
.or(Refactorings.SplitMethod.getValue());
TestBuilder test = new TestBuilder(detector, REPOS, types);
RefactoringPopulator.feedTSERefactoringInstances(test);
test.assertExpectationsWithGitHubAPI(2974, 255, 401);
test.assertExpectationsWithGitHubAPI(2979, 255, 396);
}
}
14 changes: 14 additions & 0 deletions src/test/resources/oracle/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -56467,6 +56467,13 @@
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Class",
"description": "Extract Class org.apache.cassandra.schema.Functions from class org.apache.cassandra.cql3.functions.Functions",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}],
"refDiffExecutionTime": 8203
}, {
Expand Down Expand Up @@ -96650,6 +96657,13 @@
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": "Nikos"
}, {
"type": "Extract Class",
"description": "Extract Class org.hibernate.jpa.test.instrument.cases.TestLazyPropertyOnPreUpdateExecutable from class org.hibernate.jpa.test.callbacks.CallbacksTest",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}],
"refDiffExecutionTime": 5200
}, {
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/oracle/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ d5f10a4958f5e870680be906689d92d1efb42480, 6, 0, 0
72b5348307d86b1a118e546c24d97f1ac1895bdb, 73, 0, 1
7ccbd4693288dbdbc2e6844aa0877640d63fbd04, 12, 0, 0
11048642b1e6b0e35efefab9e4e693b09c8753f5, 266, 0, 0
0b6ea757e34a63b1421b77ed5fbb61398377aab1, 6, 0, 0
0b6ea757e34a63b1421b77ed5fbb61398377aab1, 7, 0, 0
2b89553db5081fe4e55b7b34d636d0ea2acf71c5, 6, 0, 0
b25d3f32ed2e2da86f5c746098686445c2e2a314, 6, 1, 0
2581441eda268c45306423dd4c515514d98a14a0, 1, 0, 0
Expand All @@ -330,7 +330,7 @@ f283ed29814403bde6350a2598cdd6e2c8b983d5, 3, 0, 0
1a2c1bcdc7267abec9b19d77726aedbb045d79a8, 2, 1, 0
9a3fa887cfa03c082f249d1d4003d87c14ba5d24, 7, 0, 0
b70f7ea0ce27b5defa0a7773d448732364e7aee0, 5, 0, 0
35668435090eb47cf8c5e704243510b6cee35a7b, 42, 0, 0
35668435090eb47cf8c5e704243510b6cee35a7b, 43, 0, 0
e37d577b6cfc2d3e11252cef87ab9ebba72e1d52, 3, 0, 0
2b2bb6c734d106cdd1c0f4691607be2fe11d7ebb, 1, 0, 0
7f80425b6a0af9bdfef12c8a873676e39e0a04a6, 398, 2, 7
Expand Down

0 comments on commit 3dd3b4d

Please sign in to comment.