Skip to content

Commit

Permalink
Relaxing rule for Rename Variable detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 7, 2024
1 parent 668b1a4 commit ef665c8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ private void streamAPICallsInExtractedMethods(VariableDeclarationContainer calle
UMLOperation addedOperation = classDiff.matchesOperation(call, classDiff.getAddedOperations(), callerOperation);
if(addedOperation != null && !map.keySet().contains(addedOperation)) {
List<AbstractCodeFragment> newLeaves2 = new ArrayList<AbstractCodeFragment>();
if(!addedOperation.hasEmptyBody()) {
if(!addedOperation.hasEmptyBody() && addedOperation.getBody() != null) {
Set<AbstractCodeFragment> newStreamAPIStatements2 = statementsWithStreamAPICalls(addedOperation.getBody().getCompositeStatement().getLeaves());
for(AbstractCodeFragment streamAPICall : newStreamAPIStatements2) {
if(streamAPICall.getLambdas().size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ private Map<Replacement, Set<AbstractCodeMapping>> getReplacementOccurrenceMap(R
Map<Replacement, Set<AbstractCodeMapping>> map = new LinkedHashMap<Replacement, Set<AbstractCodeMapping>>();
for(AbstractCodeMapping mapping : mappings) {
for(Replacement replacement : mapping.getReplacements()) {
if(replacement.getType().equals(type) && !returnVariableMapping(mapping, replacement) && !mapping.containsReplacement(ReplacementType.CONCATENATION) &&
if(replacement.getType().equals(type) && !returnVariableMapping(mapping, replacement) &&
!containsMethodInvocationReplacementWithDifferentExpressionNameAndArguments(mapping.getReplacements()) &&
replacementNotInsideMethodSignatureOfAnonymousClass(mapping, replacement)) {
if(map.containsKey(replacement)) {
Expand Down Expand Up @@ -2097,7 +2097,7 @@ private Map<Replacement, Set<AbstractCodeMapping>> getVariableDeclarationReplace
Map<Replacement, Set<AbstractCodeMapping>> map = new LinkedHashMap<Replacement, Set<AbstractCodeMapping>>();
for(AbstractCodeMapping mapping : mappings) {
for(Replacement replacement : mapping.getReplacements()) {
if(replacement.getType().equals(ReplacementType.VARIABLE_NAME) && !returnVariableMapping(mapping, replacement) && !mapping.containsReplacement(ReplacementType.CONCATENATION) &&
if(replacement.getType().equals(ReplacementType.VARIABLE_NAME) && !returnVariableMapping(mapping, replacement) &&
!containsMethodInvocationReplacementWithDifferentExpressionNameAndArguments(mapping.getReplacements()) &&
replacementNotInsideMethodSignatureOfAnonymousClass(mapping, replacement)) {
String before = new String(replacement.getBefore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public void testAllRefactorings() throws Exception {
GitHistoryRefactoringMinerImpl detector = new GitHistoryRefactoringMinerImpl();
TestBuilder test = new TestBuilder(detector, REPOS, Refactorings.All.getValue());
RefactoringPopulator.feedRefactoringsInstances(Refactorings.All.getValue(), Systems.FSE.getValue(), test);
test.assertExpectationsWithGitHubAPI(12302, 20, 232);
test.assertExpectationsWithGitHubAPI(12300, 20, 232);
}
}
15 changes: 4 additions & 11 deletions src/test/resources/oracle/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -34522,17 +34522,10 @@
}, {
"type": "Rename Variable",
"description": "Rename Variable len : int to realSize : int in method private insertOrUpdate(recid long, out DataIO.DataOutputByteArray, isInsert boolean) : void from class org.mapdb.StoreAppend",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner, GumTreeDiff",
"validators": null
}, {
"type": "Add Variable Modifier",
"description": "Add Variable Modifier final in variable realSize : int in method private insertOrUpdate(recid long, out DataIO.DataOutputByteArray, isInsert boolean) : void from class org.mapdb.StoreAppend",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
"comment": "<p>This is quite debatable, as there are many contradicting replacements of variable len in the code. Sometimes it is replaced with realSize, sometimes with out. It seems plus=headSize realSize</p>",
"validation": "FP",
"detectionTools": "GumTreeDiff",
"validators": "Nikos"
}, {
"type": "Inline Attribute",
"description": "Inline Attribute protected indexPageCRC : boolean in class org.mapdb.StoreDirect",
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/oracle/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ c4a37e38aba926c2bef27e4fc00e3a4848ce46bd, 6, 0, 0
ca7d0c3b33a0863bed04c77932b9ef6b1317f34e, 1, 0, 0
a70ca1d9ad2ea07b19c5e1f9540c809d7a12d3fb, 6, 0, 0
d31fa31cdcc5ea2fa96116e3b1265baa180df58a, 111, 1, 3
32dd05fc13b53873bf18c589622b55d12e3883c7, 15, 0, 0
32dd05fc13b53873bf18c589622b55d12e3883c7, 13, 0, 0
c265bde2ace252bc1e1c65c6af93520e5994edd2, 1, 0, 0
40f00732b9652350ac11830367fd32db67987fc7, 17, 0, 0
8184a32a019b2ed956e8f24c18cb49a266af47bf, 17, 0, 0
Expand Down

0 comments on commit ef665c8

Please sign in to comment.