From 69d7bc8250841efd6e37faf5fd207ef390229d82 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Wed, 18 Dec 2024 20:30:17 -0500 Subject: [PATCH] Enable detection of Extract Variable merged : MergedAnnotation in method public findAnnotationDeclaringClassForTypes(annotationTypes List>, clazz Class) : Class from class org.springframework.core.annotation.AnnotationUtils in commit https://github.com/spring-projects/spring-framework/commit/c531a8a7058d24a110b312cd9a7a8bcf306845af --- .../xmi/decomposition/AbstractCodeMapping.java | 16 ++++++++++++++++ .../test/TestAllRefactorings.java | 2 +- src/test/resources/oracle/data.json | 7 +++++++ src/test/resources/oracle/expected.txt | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java index 5769864bed..ef99ec5b58 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java @@ -620,6 +620,22 @@ else if(after.startsWith("()" + JAVA.LAMBDA_ARROW + variableName + ".")) { } } } + else if(after.startsWith(variableName + " ") && initializer != null) { + if(initializer.toString().contains(before)) { + ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod); + List subExpressions = getFragment1().findExpression(before); + for(LeafExpression subExpression : subExpressions) { + LeafMapping leafMapping = new LeafMapping(subExpression, initializer, operation1, operation2); + ref.addSubExpressionMapping(leafMapping); + } + processExtractVariableRefactoring(ref, refactorings); + checkForNestedExtractVariable(ref, refactorings, nonMappedLeavesT2, insideExtractedOrInlinedMethod); + //if(identical()) { + identicalWithExtractedVariable = true; + //} + return; + } + } if(variableName.equals(after) && initializer != null) { checkForAliasedVariable(initializer, replacement, nonMappedLeavesT2, classDiff, insideExtractedOrInlinedMethod); if(initializer.toString().equals(before) || diff --git a/src/test/java/org/refactoringminer/test/TestAllRefactorings.java b/src/test/java/org/refactoringminer/test/TestAllRefactorings.java index ba6e80ccf2..c4a25eac83 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(12362, 20, 232); + test.assertExpectationsWithGitHubAPI(12363, 20, 232); } } diff --git a/src/test/resources/oracle/data.json b/src/test/resources/oracle/data.json index ecc92b32db..5c7f6f71a3 100644 --- a/src/test/resources/oracle/data.json +++ b/src/test/resources/oracle/data.json @@ -86283,6 +86283,13 @@ "validation": "TP", "detectionTools": "RefactoringMiner", "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable resolveToCallSite : boolean in method public resolve() : PsiElement from class org.intellij.erlang.psi.impl.ErlangFunctionReferenceImpl", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null }], "refDiffExecutionTime": 964 }, { diff --git a/src/test/resources/oracle/expected.txt b/src/test/resources/oracle/expected.txt index 4de087da7c..e2391f4e92 100644 --- a/src/test/resources/oracle/expected.txt +++ b/src/test/resources/oracle/expected.txt @@ -44,7 +44,7 @@ bf35b533f067b51d4c373c5e5124d88525db99f3, 19, 0, 0 6c59050b8b03adf6d8043f3fb7add0496f447edf, 3, 0, 0 e068eb7f484f24dee285d29b8a910d9019592020, 4, 0, 0 07c26a3a1dd6fcc2494c2d755ee5a2753e0df87c, 2, 0, 0 -3855f0ca82795f7481b34342c7d9e5644a1d42c3, 4, 0, 0 +3855f0ca82795f7481b34342c7d9e5644a1d42c3, 5, 0, 0 5d1a70a4d32ac4c96a32535c68c69b20288d8968, 5, 0, 0 182f4d1174036417aad9d6db908ceaf64234fd5f, 18, 0, 0 6abc40ed4850d74ee6c155f5a28f8b34881a0284, 8, 0, 0