From ef665c844f3a1cc0406c1b5148d6d30ee2c461c1 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sat, 7 Dec 2024 08:06:41 -0500 Subject: [PATCH] Relaxing rule for Rename Variable detection https://github.com/eclipse-jgit/jgit/commit/c353645a09b677644c55daa9dcff7df54529dc04 --- .../xmi/decomposition/UMLOperationBodyMapper.java | 2 +- .../VariableReplacementAnalysis.java | 4 ++-- .../test/TestAllRefactorings.java | 2 +- src/test/resources/oracle/data.json | 15 ++++----------- src/test/resources/oracle/expected.txt | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java index 072275206a..c3ae9e1aab 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -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 newLeaves2 = new ArrayList(); - if(!addedOperation.hasEmptyBody()) { + if(!addedOperation.hasEmptyBody() && addedOperation.getBody() != null) { Set newStreamAPIStatements2 = statementsWithStreamAPICalls(addedOperation.getBody().getCompositeStatement().getLeaves()); for(AbstractCodeFragment streamAPICall : newStreamAPIStatements2) { if(streamAPICall.getLambdas().size() > 0) { diff --git a/src/main/java/gr/uom/java/xmi/decomposition/VariableReplacementAnalysis.java b/src/main/java/gr/uom/java/xmi/decomposition/VariableReplacementAnalysis.java index c3e53482be..ed4268a046 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/VariableReplacementAnalysis.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/VariableReplacementAnalysis.java @@ -1922,7 +1922,7 @@ private Map> getReplacementOccurrenceMap(R Map> map = new LinkedHashMap>(); 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)) { @@ -2097,7 +2097,7 @@ private Map> getVariableDeclarationReplace Map> map = new LinkedHashMap>(); 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()); diff --git a/src/test/java/org/refactoringminer/test/TestAllRefactorings.java b/src/test/java/org/refactoringminer/test/TestAllRefactorings.java index 5c1710ab19..4486a0850c 100644 --- a/src/test/java/org/refactoringminer/test/TestAllRefactorings.java +++ b/src/test/java/org/refactoringminer/test/TestAllRefactorings.java @@ -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); } } diff --git a/src/test/resources/oracle/data.json b/src/test/resources/oracle/data.json index 209caf2648..a8457f8ab6 100644 --- a/src/test/resources/oracle/data.json +++ b/src/test/resources/oracle/data.json @@ -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": "

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

", + "validation": "FP", + "detectionTools": "GumTreeDiff", + "validators": "Nikos" }, { "type": "Inline Attribute", "description": "Inline Attribute protected indexPageCRC : boolean in class org.mapdb.StoreDirect", diff --git a/src/test/resources/oracle/expected.txt b/src/test/resources/oracle/expected.txt index a9db71cb5b..e222033c0b 100644 --- a/src/test/resources/oracle/expected.txt +++ b/src/test/resources/oracle/expected.txt @@ -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