Skip to content

Commit 3b6d05c

Browse files
committed
Improved heuristic to tolerate differences that are parameter names
1 parent ad48140 commit 3b6d05c

File tree

6 files changed

+118
-33
lines changed

6 files changed

+118
-33
lines changed

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -326,27 +326,27 @@ Currently, it supports the detection of the following refactorings:
326326
**Commit dates**: between June 8th and August 7th, 2015
327327

328328
The original benchmark has been extended by adding newly supported refactoring types by RefactoringMiner.
329-
As of **February 4, 2025** the precision and recall of RefactoringMiner on this benchmark is:
329+
As of **March 15, 2025** the precision and recall of RefactoringMiner on this benchmark is:
330330

331331
| Refactoring Type | TP | FP | FN | Precision | Recall |
332332
|:-----------------------|-----------:|--------:|--------:|--------:|--------:|
333-
|**Total**|12413 | 16 | 226 | 0.999 | 0.982|
333+
|**Total**|12433 | 16 | 224 | 0.999 | 0.982|
334334
|Extract Method|1006 | 1 | 22 | 0.999 | 0.979|
335335
|Rename Class|56 | 0 | 2 | 1.000 | 0.966|
336-
|Move Attribute|256 | 0 | 8 | 1.000 | 0.970|
337-
|Move And Rename Attribute|16 | 0 | 0 | 1.000 | 1.000|
336+
|Move Attribute|257 | 0 | 8 | 1.000 | 0.970|
337+
|Move And Rename Attribute|17 | 0 | 0 | 1.000 | 1.000|
338338
|Replace Attribute| 1 | 0 | 0 | 1.000 | 1.000|
339-
|Rename Method|388 | 3 | 21 | 0.992 | 0.949|
339+
|Rename Method|389 | 3 | 21 | 0.992 | 0.949|
340340
|Inline Method|118 | 0 | 1 | 1.000 | 0.992|
341-
|Move Method|386 | 3 | 6 | 0.992 | 0.985|
341+
|Move Method|388 | 3 | 5 | 0.992 | 0.987|
342342
|Move And Rename Method|128 | 0 | 4 | 1.000 | 0.970|
343343
|Pull Up Method|288 | 0 | 5 | 1.000 | 0.983|
344344
|Move Class|1095 | 0 | 4 | 1.000 | 0.996|
345345
|Move And Rename Class|38 | 0 | 1 | 1.000 | 0.974|
346346
|Move Source Folder| 3 | 0 | 0 | 1.000 | 1.000|
347347
|Pull Up Attribute|139 | 0 | 1 | 1.000 | 0.993|
348348
|Push Down Attribute|35 | 0 | 0 | 1.000 | 1.000|
349-
|Push Down Method|45 | 0 | 1 | 1.000 | 0.978|
349+
|Push Down Method|46 | 0 | 0 | 1.000 | 1.000|
350350
|Extract Interface|22 | 0 | 0 | 1.000 | 1.000|
351351
|Extract Superclass|74 | 0 | 0 | 1.000 | 1.000|
352352
|Extract Subclass| 4 | 0 | 0 | 1.000 | 1.000|
@@ -356,12 +356,12 @@ As of **February 4, 2025** the precision and recall of RefactoringMiner on this
356356
|Replace Anonymous With Class| 8 | 0 | 0 | 1.000 | 1.000|
357357
|Rename Package|16 | 0 | 0 | 1.000 | 1.000|
358358
|Move Package|10 | 0 | 0 | 1.000 | 1.000|
359-
|Extract Variable|305 | 0 | 0 | 1.000 | 1.000|
359+
|Extract Variable|306 | 0 | 0 | 1.000 | 1.000|
360360
|Extract Attribute|25 | 0 | 0 | 1.000 | 1.000|
361-
|Inline Variable|116 | 0 | 0 | 1.000 | 1.000|
361+
|Inline Variable|118 | 0 | 0 | 1.000 | 1.000|
362362
|Inline Attribute| 9 | 0 | 0 | 1.000 | 1.000|
363363
|Rename Variable|333 | 3 | 11 | 0.991 | 0.968|
364-
|Rename Parameter|493 | 2 | 24 | 0.996 | 0.954|
364+
|Rename Parameter|492 | 2 | 24 | 0.996 | 0.953|
365365
|Rename Attribute|146 | 0 | 9 | 1.000 | 0.942|
366366
|Merge Variable| 6 | 0 | 0 | 1.000 | 1.000|
367367
|Merge Parameter|28 | 0 | 0 | 1.000 | 1.000|
@@ -374,11 +374,11 @@ As of **February 4, 2025** the precision and recall of RefactoringMiner on this
374374
|Parameterize Variable|111 | 0 | 0 | 1.000 | 1.000|
375375
|Localize Parameter|26 | 0 | 0 | 1.000 | 1.000|
376376
|Parameterize Attribute|23 | 0 | 0 | 1.000 | 1.000|
377-
|Change Return Type|433 | 0 | 12 | 1.000 | 0.973|
377+
|Change Return Type|434 | 0 | 12 | 1.000 | 0.973|
378378
|Change Variable Type|807 | 2 | 7 | 0.998 | 0.991|
379-
|Change Parameter Type|653 | 1 | 10 | 0.998 | 0.985|
379+
|Change Parameter Type|654 | 1 | 10 | 0.998 | 0.985|
380380
|Change Attribute Type|244 | 0 | 8 | 1.000 | 0.968|
381-
|Add Method Annotation|332 | 0 | 1 | 1.000 | 0.997|
381+
|Add Method Annotation|333 | 0 | 1 | 1.000 | 0.997|
382382
|Remove Method Annotation|100 | 0 | 0 | 1.000 | 1.000|
383383
|Modify Method Annotation|29 | 0 | 0 | 1.000 | 1.000|
384384
|Add Attribute Annotation|62 | 0 | 1 | 1.000 | 0.984|
@@ -390,18 +390,18 @@ As of **February 4, 2025** the precision and recall of RefactoringMiner on this
390390
|Add Parameter Annotation|34 | 0 | 0 | 1.000 | 1.000|
391391
|Remove Parameter Annotation| 4 | 0 | 0 | 1.000 | 1.000|
392392
|Modify Parameter Annotation| 2 | 0 | 0 | 1.000 | 1.000|
393-
|Add Parameter|849 | 1 | 1 | 0.999 | 0.999|
393+
|Add Parameter|851 | 1 | 1 | 0.999 | 0.999|
394394
|Remove Parameter|311 | 0 | 0 | 1.000 | 1.000|
395395
|Reorder Parameter| 9 | 0 | 0 | 1.000 | 1.000|
396396
|Add Variable Annotation| 1 | 0 | 0 | 1.000 | 1.000|
397397
|Remove Variable Annotation| 4 | 0 | 0 | 1.000 | 1.000|
398398
|Add Thrown Exception Type|41 | 0 | 0 | 1.000 | 1.000|
399399
|Remove Thrown Exception Type|270 | 0 | 0 | 1.000 | 1.000|
400400
|Change Thrown Exception Type| 9 | 0 | 0 | 1.000 | 1.000|
401-
|Change Method Access Modifier|332 | 0 | 0 | 1.000 | 1.000|
402-
|Change Attribute Access Modifier|231 | 0 | 0 | 1.000 | 1.000|
403-
|Encapsulate Attribute|49 | 0 | 0 | 1.000 | 1.000|
404-
|Add Method Modifier|89 | 0 | 0 | 1.000 | 1.000|
401+
|Change Method Access Modifier|334 | 0 | 0 | 1.000 | 1.000|
402+
|Change Attribute Access Modifier|232 | 0 | 0 | 1.000 | 1.000|
403+
|Encapsulate Attribute|52 | 0 | 0 | 1.000 | 1.000|
404+
|Add Method Modifier|90 | 0 | 0 | 1.000 | 1.000|
405405
|Remove Method Modifier|111 | 0 | 0 | 1.000 | 1.000|
406406
|Add Attribute Modifier|142 | 0 | 0 | 1.000 | 1.000|
407407
|Remove Attribute Modifier|143 | 0 | 0 | 1.000 | 1.000|
@@ -441,18 +441,18 @@ As of **February 4, 2025** the precision and recall of RefactoringMiner on this
441441
**Commit dates**: March 28, 2024
442442

443443
The original benchmark has been re-validated and corrected by Nikolaos Tsantalis. The validation process is still in progress.
444-
As of **March 3, 2025** the precision and recall of RefactoringMiner on this benchmark is:
444+
As of **March 15, 2025** the precision and recall of RefactoringMiner on this benchmark is:
445445

446446
| Refactoring Type | TP | FP | FN | Precision | Recall |
447447
|:-----------------------|-----------:|--------:|--------:|--------:|--------:|
448-
|**Total**|3035 | 216 | 356 | 0.934 | 0.895|
449-
|Extract Method|329 | 24 | 33 | 0.932 | 0.909|
448+
|**Total**|3043 | 209 | 355 | 0.936 | 0.896|
449+
|Extract Method|329 | 21 | 33 | 0.940 | 0.909|
450450
|Rename Class|229 | 2 | 3 | 0.991 | 0.987|
451451
|Move Attribute|69 | 3 | 11 | 0.958 | 0.863|
452452
|Move And Rename Attribute| 4 | 0 | 4 | 1.000 | 0.500|
453453
|Rename Method|271 | 23 | 25 | 0.922 | 0.916|
454454
|Inline Method|63 | 9 | 6 | 0.875 | 0.913|
455-
|Move Method|259 | 5 | 8 | 0.981 | 0.970|
455+
|Move Method|260 | 5 | 7 | 0.981 | 0.974|
456456
|Move And Rename Method|18 | 6 | 10 | 0.750 | 0.643|
457457
|Pull Up Method|42 | 3 | 8 | 0.933 | 0.840|
458458
|Move Class|138 | 7 | 4 | 0.952 | 0.972|
@@ -464,14 +464,14 @@ As of **March 3, 2025** the precision and recall of RefactoringMiner on this ben
464464
|Extract Superclass| 7 | 2 | 0 | 0.778 | 1.000|
465465
|Extract Subclass| 3 | 0 | 6 | 1.000 | 0.333|
466466
|Extract Class|40 | 2 | 11 | 0.952 | 0.784|
467-
|Extract And Move Method|99 | 24 | 21 | 0.805 | 0.825|
468-
|Move And Inline Method|17 | 7 | 13 | 0.708 | 0.567|
467+
|Extract And Move Method|99 | 21 | 21 | 0.825 | 0.825|
468+
|Move And Inline Method|25 | 7 | 12 | 0.781 | 0.676|
469469
|Extract Variable|238 | 15 | 42 | 0.941 | 0.850|
470-
|Inline Variable|80 | 12 | 42 | 0.870 | 0.656|
471-
|Rename Variable|266 | 26 | 28 | 0.911 | 0.905|
470+
|Inline Variable|81 | 12 | 41 | 0.871 | 0.664|
471+
|Rename Variable|264 | 26 | 30 | 0.910 | 0.898|
472472
|Rename Attribute|101 | 6 | 15 | 0.944 | 0.871|
473473
|Change Return Type|153 | 9 | 27 | 0.944 | 0.850|
474-
|Change Variable Type|363 | 25 | 18 | 0.936 | 0.953|
474+
|Change Variable Type|363 | 24 | 18 | 0.938 | 0.953|
475475
|Change Attribute Type|158 | 3 | 9 | 0.981 | 0.946|
476476
|Change Type Declaration Kind| 4 | 0 | 0 | 1.000 | 1.000|
477477
|Split Method| 6 | 0 | 0 | 1.000 | 1.000|

src/main/java/gr/uom/java/xmi/decomposition/StringBasedHeuristics.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ protected static boolean differOnlyInCastExpressionOrPrefixOperatorOrInfixOperan
143143
else if(diff2.isEmpty() && diff1.equals(JAVA.THIS_DOT)) {
144144
return true;
145145
}
146+
List<String> parameterNameList1 = container1.getParameterNameList();
147+
List<String> parameterNameList2 = container2.getParameterNameList();
148+
if(diff1.isEmpty() && parameterNameList2.contains(diff2)) {
149+
boolean skip = false;
150+
for(Replacement r : info.getReplacements()) {
151+
if(parameterNameList1.contains(r.getBefore())) {
152+
skip = true;
153+
}
154+
}
155+
if(!skip)
156+
return true;
157+
}
158+
else if(diff2.isEmpty() && parameterNameList1.contains(diff1)) {
159+
boolean skip = false;
160+
for(Replacement r : info.getReplacements()) {
161+
if(parameterNameList2.contains(r.getAfter())) {
162+
skip = true;
163+
}
164+
}
165+
if(!skip)
166+
return true;
167+
}
146168
if(diff1.isEmpty() && (diff2.equals("+") || diff2.equals("-")) && commonSuffix.startsWith(JAVA.ASSIGNMENT)) {
147169
return true;
148170
}

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(12423, 16, 225);
20+
test.assertExpectationsWithGitHubAPI(12433, 16, 224);
2121
}
2222
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public void testAllRefactorings() throws Exception {
4444
.or(Refactorings.SplitMethod.getValue());
4545
TestBuilder test = new TestBuilder(detector, REPOS, types);
4646
RefactoringPopulator.feedTSERefactoringInstances(test);
47-
test.assertExpectationsWithGitHubAPI(3042, 209, 356);
47+
test.assertExpectationsWithGitHubAPI(3043, 209, 355);
4848
}
4949
}

src/test/resources/oracle/data.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20355,6 +20355,27 @@
2035520355
"validation": "TP",
2035620356
"detectionTools": "RefactoringMiner",
2035720357
"validators": null
20358+
}, {
20359+
"type": "Rename Method",
20360+
"description": "Rename Method protected cleanAlerts() : void renamed to private sanitizeQualityGates(session DbSession) : void in class org.sonar.server.startup.RegisterMetrics",
20361+
"comment": null,
20362+
"validation": "TP",
20363+
"detectionTools": "RefactoringMiner",
20364+
"validators": null
20365+
}, {
20366+
"type": "Add Parameter",
20367+
"description": "Add Parameter session : DbSession in method private sanitizeQualityGates(session DbSession) : void from class org.sonar.server.startup.RegisterMetrics",
20368+
"comment": null,
20369+
"validation": "TP",
20370+
"detectionTools": "RefactoringMiner",
20371+
"validators": null
20372+
}, {
20373+
"type": "Change Method Access Modifier",
20374+
"description": "Change Method Access Modifier protected to private in method private sanitizeQualityGates(session DbSession) : void from class org.sonar.server.startup.RegisterMetrics",
20375+
"comment": null,
20376+
"validation": "TP",
20377+
"detectionTools": "RefactoringMiner",
20378+
"validators": null
2035820379
}],
2035920380
"refDiffExecutionTime": 4571
2036020381
}, {
@@ -73301,6 +73322,34 @@
7330173322
"validation": "TP",
7330273323
"detectionTools": "RefactoringMiner",
7330373324
"validators": "Nikos"
73325+
}, {
73326+
"type": "Extract Variable",
73327+
"description": "Extract Variable languageLocale : Locale in method public getLanguageString(languagueCode String, displayLocale Locale) : String from class org.wordpress.android.util.StringUtils",
73328+
"comment": null,
73329+
"validation": "TP",
73330+
"detectionTools": "RefactoringMiner",
73331+
"validators": null
73332+
}, {
73333+
"type": "Add Parameter",
73334+
"description": "Add Parameter displayLocale : Locale in method public getLanguageString(languagueCode String, displayLocale Locale) : String from class org.wordpress.android.util.StringUtils",
73335+
"comment": null,
73336+
"validation": "TP",
73337+
"detectionTools": "RefactoringMiner",
73338+
"validators": null
73339+
}, {
73340+
"type": "Add Method Modifier",
73341+
"description": "Add Method Modifier static in method public getLanguageString(languagueCode String, displayLocale Locale) : String from class org.wordpress.android.util.StringUtils",
73342+
"comment": null,
73343+
"validation": "TP",
73344+
"detectionTools": "RefactoringMiner",
73345+
"validators": null
73346+
}, {
73347+
"type": "Change Method Access Modifier",
73348+
"description": "Change Method Access Modifier private to public in method public getLanguageString(languagueCode String, displayLocale Locale) : String from class org.wordpress.android.util.StringUtils",
73349+
"comment": null,
73350+
"validation": "TP",
73351+
"detectionTools": "RefactoringMiner",
73352+
"validators": null
7330473353
}],
7330573354
"refDiffExecutionTime": 1235
7330673355
}, {
@@ -112598,6 +112647,13 @@
112598112647
"validation": "TP",
112599112648
"detectionTools": "RefactoringMiner",
112600112649
"validators": null
112650+
}, {
112651+
"type": "Inline Variable",
112652+
"description": "Inline Variable walker : ObjectWalk in method public preparePack(countingMonitor ProgressMonitor, interestingObjects Collection<? extends ObjectId>, uninterestingObjects Collection<? extends ObjectId>) : void from class org.eclipse.jgit.storage.pack.PackWriter",
112653+
"comment": null,
112654+
"validation": "TP",
112655+
"detectionTools": "RefactoringMiner",
112656+
"validators": null
112601112657
}],
112602112658
"refDiffExecutionTime": null
112603112659
}, {
@@ -112635,6 +112691,13 @@
112635112691
"validation": "TP",
112636112692
"detectionTools": "RefactoringMiner",
112637112693
"validators": null
112694+
}, {
112695+
"type": "Inline Variable",
112696+
"description": "Inline Variable walker : ObjectWalk in method public preparePack(countingMonitor ProgressMonitor, interestingObjects Collection<? extends ObjectId>, uninterestingObjects Collection<? extends ObjectId>) : void from class org.eclipse.jgit.storage.pack.PackWriter",
112697+
"comment": null,
112698+
"validation": "TP",
112699+
"detectionTools": "RefactoringMiner",
112700+
"validators": null
112638112701
}],
112639112702
"refDiffExecutionTime": null
112640112703
}, {

src/test/resources/oracle/expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ f9d3171f5020da5c359cdda28ef05172e858c464, 15, 0, 5
8484
2331fe19ea88a22de32f15375de8118226eaa1e6, 13, 0, 0
8585
5bab9e837cf273250aa26702204f139fdcfd9e7a, 4, 0, 0
8686
31fc19200207ccadc45328037d8a2a62b617c029, 9, 0, 0
87-
2fbcba41e365752681f635c706d577e605d3336a, 5, 0, 0
87+
2fbcba41e365752681f635c706d577e605d3336a, 6, 0, 0
8888
065a0a8122be356d1f898321763d3518b504b075, 4, 0, 0
8989
add1d4f07c925b8a9044cb3aa5bb4abdeaf49fc7, 1, 0, 0
90-
f5fe2dca3cb9f57891e1a4b18832fcc158d0c490, 4, 0, 0
90+
f5fe2dca3cb9f57891e1a4b18832fcc158d0c490, 5, 0, 0
9191
925801c14e7500313069b2bc04abd066798a881c, 2, 0, 0
9292
e6cb12dfe414497b4317820497985c110cb81864, 3, 0, 0
9393
bdc9f9a44f337ab595a3570833dc6a0558df904c, 7, 0, 6
@@ -442,7 +442,7 @@ cb49e436b9d7ee55f2531ebc2ef1863f5c9ba9fe, 1, 0, 0
442442
c22d40fab8dfe4c5cad9ba582caf0855ff64b324, 4, 0, 0
443443
7fb0d1ce3b6583013e81ac05eb9afb15d20eab7f, 5, 0, 0
444444
0e815f3e1339f91960c7c64ab395de6dd8ff9eec, 7, 0, 0
445-
021bf45623b748e70f20d956e86d595191241786, 19, 0, 5
445+
021bf45623b748e70f20d956e86d595191241786, 22, 0, 5
446446
56d4b999e8be70be237049708f019c278c356e71, 16, 0, 0
447447
a97341973c3b683d62d1422e5404ed5c7ccf45f8, 4, 0, 0
448448
e1f0dbc2f09541fc64ce88ee22d8f8f4648004fe, 2, 0, 0
@@ -541,7 +541,7 @@ abba5d83602c7ae23901bd579ba9fbb7dc36adc0, 27, 0, 4
541541
4bfe164cc8b4556b98df18098b162e0a84038b32, 1, 0, 0
542542
ab298886b59f4ad0235cd6d5764854189eb59eb6, 11, 0, 0
543543
cf1efb6d27a4037cdbe5a780afa6053859a60d4a, 3, 0, 0
544-
1b21ba4bcea986988d4bbd578e3bb9a20ec69606, 10, 0, 1
544+
1b21ba4bcea986988d4bbd578e3bb9a20ec69606, 15, 0, 0
545545
c53c6f45988db869d56abe3b1d831ff775f4fa73, 17, 0, 0
546546
446e2537895c15b404a74107069a12f3fc404b15, 44, 2, 0
547547
c30deabcaed4726bce4371d76257db63f2eba87c, 57, 0, 0

0 commit comments

Comments
 (0)