Skip to content

Commit b77e668

Browse files
committed
Support Extract and Move Method from moved classes to added classes
1 parent 72b112e commit b77e668

File tree

6 files changed

+67
-11
lines changed

6 files changed

+67
-11
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,11 @@ Currently, it supports the detection of the following refactorings:
376376
**File**: [data.json](https://github.com/tsantalis/RefactoringMiner/blob/master/src/test/resources/oracle/data.json)
377377

378378
The original benchmark has been extended by adding newly supported refactoring types by RefactoringMiner.
379-
As of **October 25, 2025** the precision and recall of RefactoringMiner on this benchmark is:
379+
As of **November 1, 2025** the precision and recall of RefactoringMiner on this benchmark is:
380380

381381
| Refactoring Type | TP | FP | FN | Precision | Recall |
382382
|:-----------------------|-----------:|--------:|--------:|--------:|--------:|
383-
|**Total**|12512 | 13 | 219 | 0.999 | 0.983|
383+
|**Total**|12517 | 13 | 219 | 0.999 | 0.983|
384384
|Extract Method|1016 | 1 | 20 | 0.999 | 0.981|
385385
|Rename Class|56 | 0 | 2 | 1.000 | 0.966|
386386
|Move Attribute|257 | 0 | 8 | 1.000 | 0.970|
@@ -401,7 +401,7 @@ As of **October 25, 2025** the precision and recall of RefactoringMiner on this
401401
|Extract Superclass|74 | 0 | 0 | 1.000 | 1.000|
402402
|Extract Subclass| 4 | 0 | 0 | 1.000 | 1.000|
403403
|Extract Class|108 | 0 | 0 | 1.000 | 1.000|
404-
|Extract And Move Method|124 | 0 | 60 | 1.000 | 0.674|
404+
|Extract And Move Method|127 | 0 | 60 | 1.000 | 0.679|
405405
|Move And Inline Method|12 | 0 | 4 | 1.000 | 0.750|
406406
|Replace Anonymous With Class| 8 | 0 | 0 | 1.000 | 1.000|
407407
|Rename Package|16 | 0 | 0 | 1.000 | 1.000|
@@ -411,7 +411,7 @@ As of **October 25, 2025** the precision and recall of RefactoringMiner on this
411411
|Inline Variable|147 | 0 | 0 | 1.000 | 1.000|
412412
|Inline Attribute| 9 | 0 | 0 | 1.000 | 1.000|
413413
|Rename Variable|340 | 2 | 11 | 0.994 | 0.969|
414-
|Rename Parameter|493 | 2 | 24 | 0.996 | 0.954|
414+
|Rename Parameter|494 | 2 | 24 | 0.996 | 0.954|
415415
|Rename Attribute|146 | 0 | 9 | 1.000 | 0.942|
416416
|Merge Variable| 6 | 0 | 0 | 1.000 | 1.000|
417417
|Merge Parameter|28 | 0 | 0 | 1.000 | 1.000|
@@ -455,7 +455,7 @@ As of **October 25, 2025** the precision and recall of RefactoringMiner on this
455455
|Add Attribute Modifier|142 | 0 | 0 | 1.000 | 1.000|
456456
|Remove Attribute Modifier|143 | 0 | 0 | 1.000 | 1.000|
457457
|Add Variable Modifier|135 | 0 | 0 | 1.000 | 1.000|
458-
|Add Parameter Modifier|132 | 0 | 0 | 1.000 | 1.000|
458+
|Add Parameter Modifier|133 | 0 | 0 | 1.000 | 1.000|
459459
|Remove Variable Modifier|65 | 0 | 0 | 1.000 | 1.000|
460460
|Remove Parameter Modifier|39 | 0 | 0 | 1.000 | 1.000|
461461
|Change Class Access Modifier|78 | 0 | 0 | 1.000 | 1.000|
@@ -476,11 +476,12 @@ As of **October 25, 2025** the precision and recall of RefactoringMiner on this
476476
|Merge Catch| 2 | 0 | 0 | 1.000 | 1.000|
477477
|Merge Method| 3 | 0 | 0 | 1.000 | 1.000|
478478
|Split Method| 5 | 0 | 0 | 1.000 | 1.000|
479-
|Move Code|16 | 0 | 0 | 1.000 | 1.000|
479+
|Move Code|13 | 0 | 0 | 1.000 | 1.000|
480480
|Assert Throws|14 | 0 | 0 | 1.000 | 1.000|
481481
|Try With Resources| 4 | 0 | 0 | 1.000 | 1.000|
482482
|Replace Generic With Diamond|77 | 0 | 0 | 1.000 | 1.000|
483483
|Replace Conditional With Ternary| 8 | 0 | 0 | 1.000 | 1.000|
484+
|Extract Fixture| 3 | 0 | 0 | 1.000 | 1.000|
484485

485486
## Benchmark 2
486487
**Source**: Bo Liu, Hui Liu, Nan Niu, Yuxia Zhang, Guangjie Li, He Jiang, and Yanjie Jiang, "An Automated Approach to Discovering Software Refactorings by Comparing Successive Versions," IEEE Transactions on Software Engineering, 2025.
@@ -506,7 +507,7 @@ As of **November 1, 2025** the precision and recall of RefactoringMiner on this
506507

507508
| Refactoring Type | TP | FP | FN | Precision | Recall |
508509
|:-----------------------|-----------:|--------:|--------:|--------:|--------:|
509-
|**Total**|3415 | 50 | 121 | 0.986 | 0.966|
510+
|**Total**|3416 | 50 | 120 | 0.986 | 0.966|
510511
|Extract Method|371 | 1 | 4 | 0.997 | 0.989|
511512
|Rename Class|232 | 1 | 2 | 0.996 | 0.991|
512513
|Move Attribute|72 | 0 | 7 | 1.000 | 0.911|
@@ -525,7 +526,7 @@ As of **November 1, 2025** the precision and recall of RefactoringMiner on this
525526
|Extract Superclass| 8 | 0 | 0 | 1.000 | 1.000|
526527
|Extract Subclass| 8 | 0 | 0 | 1.000 | 1.000|
527528
|Extract Class|45 | 1 | 4 | 0.978 | 0.918|
528-
|Extract And Move Method|120 | 2 | 8 | 0.984 | 0.938|
529+
|Extract And Move Method|121 | 2 | 7 | 0.984 | 0.945|
529530
|Move And Inline Method|29 | 1 | 6 | 0.967 | 0.829|
530531
|Replace Anonymous With Class| 5 | 0 | 0 | 1.000 | 1.000|
531532
|Extract Variable|288 | 1 | 12 | 0.997 | 0.960|

src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,17 @@ private List<UMLOperationBodyMapper> getOperationBodyMappersInCommonClasses() {
25952595
return mappers;
25962596
}
25972597

2598+
private List<UMLOperationBodyMapper> getOperationBodyMappersInMovedClasses() {
2599+
List<UMLOperationBodyMapper> mappers = new ArrayList<UMLOperationBodyMapper>();
2600+
for(UMLClassMoveDiff classDiff : classMoveDiffList) {
2601+
mappers.addAll(classDiff.getOperationBodyMapperList());
2602+
}
2603+
for(UMLClassMoveDiff classDiff : innerClassMoveDiffList) {
2604+
mappers.addAll(classDiff.getOperationBodyMapperList());
2605+
}
2606+
return mappers;
2607+
}
2608+
25982609
private List<UMLOperationBodyMapper> getOperationBodyMappersInMovedAndRenamedClasses() {
25992610
List<UMLOperationBodyMapper> mappers = new ArrayList<UMLOperationBodyMapper>();
26002611
for(UMLClassMoveDiff classDiff : classMoveDiffList) {
@@ -3929,6 +3940,8 @@ else if(candidate.getOriginalAttribute().getName().equals(a2.getName())) {
39293940
checkForExtractedAndMovedLambdas(getOperationBodyMappersInMovedAndRenamedClasses(), allOperationsInAddedClasses);
39303941
if(allOperationsInAddedClasses.size() <= MAXIMUM_NUMBER_OF_COMPARED_METHODS) {
39313942
checkForExtractedAndMovedOperations(getOperationBodyMappersInCommonClasses(), allOperationsInAddedClasses);
3943+
processedOperationPairs.clear();
3944+
checkForExtractedAndMovedOperations(getOperationBodyMappersInMovedClasses(), allOperationsInAddedClasses);
39323945
}
39333946
checkForMovedCodeBetweenTestFixtures();
39343947
List<MoveAttributeRefactoring> moveAttributeRefactorings = new ArrayList<MoveAttributeRefactoring>();
@@ -5868,6 +5881,13 @@ private boolean extractAndMoveMatchCondition(UMLOperationBodyMapper operationBod
58685881
if(operationBodyMapper.containsOnlySystemCalls()) {
58695882
return false;
58705883
}
5884+
if(addedOperationInvocation.getContainer() != null && parentMapper.getMappings().isEmpty()) {
5885+
for(UMLAnonymousClass anonymous : addedOperationInvocation.getContainer().getAnonymousClassList()) {
5886+
if(anonymous.getLocationInfo().subsumes(addedOperationInvocation.getLocationInfo())) {
5887+
return false;
5888+
}
5889+
}
5890+
}
58715891
if(operationBodyMapper.getContainer2().isGetter() && mappingList.size() == 1) {
58725892
List<AbstractCodeMapping> parentMappingList = new ArrayList<AbstractCodeMapping>(parentMapper.getMappings());
58735893
AbstractCodeMapping callerMapping = null;

src/test/java/org/refactoringminer/test/TestAllRefactorings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public void testAllRefactorings() throws Exception {
1717
GitHistoryRefactoringMinerImpl detector = new GitHistoryRefactoringMinerImpl();
1818
TestBuilder test = new TestBuilder(detector, REPOS, Refactorings.All.getValue());
1919
RefactoringPopulator.feedRefactoringsInstances(Refactorings.All.getValue(), Systems.FSE.getValue(), test);
20-
test.assertExpectationsWithGitHubAPI(12512, 13, 219);
20+
test.assertExpectationsWithGitHubAPI(12517, 13, 219);
2121
}
2222
}

src/test/java/org/refactoringminer/test/TestNewDatasetRefactorings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public void testAllRefactorings() throws Exception {
5050
.or(Refactorings.ReplaceAttributeWithVariable.getValue());
5151
TestBuilder test = new TestBuilder(detector, REPOS, types);
5252
RefactoringPopulator.feedTSERefactoringInstances(test);
53-
test.assertExpectationsWithGitHubAPI(3415, 50, 121);
53+
test.assertExpectationsWithGitHubAPI(3416, 50, 120);
5454
}
5555
}

src/test/resources/oracle/data.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52514,6 +52514,41 @@
5251452514
"validation": "TP",
5251552515
"detectionTools": "RefactoringMiner",
5251652516
"validators": null
52517+
}, {
52518+
"type": "Extract And Move Method",
52519+
"description": "Extract And Move Method protected getHiveReadEntryHelper(mClient IMetaStoreClient, dbName String, tableName String, hiveConfigOverride Map<String,String>) : HiveReadEntry extracted from public load(key String) : HiveReadEntry in class org.apache.drill.exec.store.hive.schema.HiveSchemaFactory.TableLoader & moved to class org.apache.drill.exec.store.hive.DrillHiveMetaStoreClient",
52520+
"comment": null,
52521+
"validation": "TP",
52522+
"detectionTools": "RefactoringMiner",
52523+
"validators": null
52524+
}, {
52525+
"type": "Extract And Move Method",
52526+
"description": "Extract And Move Method protected getDatabasesHelper(mClient IMetaStoreClient) : List<String> extracted from public load(key String) : List<String> in class org.apache.drill.exec.store.hive.schema.HiveSchemaFactory.DatabaseLoader & moved to class org.apache.drill.exec.store.hive.DrillHiveMetaStoreClient",
52527+
"comment": null,
52528+
"validation": "TP",
52529+
"detectionTools": "RefactoringMiner",
52530+
"validators": null
52531+
}, {
52532+
"type": "Extract And Move Method",
52533+
"description": "Extract And Move Method protected getTableNamesHelper(mClient IMetaStoreClient, dbName String) : List<String> extracted from public load(dbName String) : List<String> in class org.apache.drill.exec.store.hive.schema.HiveSchemaFactory.TableNameLoader & moved to class org.apache.drill.exec.store.hive.DrillHiveMetaStoreClient",
52534+
"comment": null,
52535+
"validation": "TP",
52536+
"detectionTools": "RefactoringMiner",
52537+
"validators": null
52538+
}, {
52539+
"type": "Rename Parameter",
52540+
"description": "Rename Parameter key : String to tableName : String in method protected getHiveReadEntryHelper(mClient IMetaStoreClient, dbName String, tableName String, hiveConfigOverride Map<String,String>) : HiveReadEntry from class org.apache.drill.exec.store.hive.DrillHiveMetaStoreClient",
52541+
"comment": null,
52542+
"validation": "TP",
52543+
"detectionTools": "RefactoringMiner",
52544+
"validators": null
52545+
}, {
52546+
"type": "Add Parameter Modifier",
52547+
"description": "Add Parameter Modifier final in parameter tableName : String in method protected getHiveReadEntryHelper(mClient IMetaStoreClient, dbName String, tableName String, hiveConfigOverride Map<String,String>) : HiveReadEntry from class org.apache.drill.exec.store.hive.DrillHiveMetaStoreClient",
52548+
"comment": null,
52549+
"validation": "TP",
52550+
"detectionTools": "RefactoringMiner",
52551+
"validators": null
5251752552
}],
5251852553
"refDiffExecutionTime": 2022
5251952554
}, {

src/test/resources/oracle/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ b2bbd9941be6b132a83d27c0ae02c935e1dec5dd, 33, 0, 2
1212
f1b8ae1c44e6ba46118c2f66eae1725259acdccc, 7, 0, 0
1313
00aa01fb90f3210d1e3027d7f759fb1085b814bd, 62, 0, 5
1414
658a918eebcbdeb4f920c2947ca8d0e79ad86d89, 1, 0, 0
15-
c1b847acdc8cb90a1498b236b3bb5c81ca75c044, 76, 0, 2
15+
c1b847acdc8cb90a1498b236b3bb5c81ca75c044, 81, 0, 2
1616
35893c115ba23bd62a7036a33390420f074ce660, 19, 0, 0
1717
f166866cd68efa963534c5bc7fc9ca38e4aa2838, 1, 0, 0
1818
04bcfe98dbe7b05e508559930c21379ece845732, 51, 0, 0

0 commit comments

Comments
 (0)