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 ef99ec5b58..e9ae21d05c 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java @@ -707,6 +707,31 @@ else if(stringConcatMatch(initializer, before)) { } } } + if(getReplacements().isEmpty() && !fragment1.getString().equals(fragment2.getString()) && initializer != null && fragment1.getVariableDeclaration(variableName) == null) { + if(getFragment1().getString().contains(initializer.getString()) && getFragment2().getString().contains(variableName)) { + boolean mappingFound = false; + for(AbstractCodeMapping m : currentMappings) { + if(m.getFragment2().equalFragment(statement)) { + mappingFound = true; + break; + } + } + if(!mappingFound) { + ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod); + List subExpressions = getFragment1().findExpression(initializer.getString()); + 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(classDiff != null && initializer != null) { AbstractCall invocation = initializer.invocationCoveringEntireFragment(); if(invocation != null) { 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 0105a4b2f1..35fa87894c 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/UMLOperationBodyMapper.java @@ -6943,7 +6943,7 @@ else if(Math.abs(fragment1.getDepth() - fragment2.getDepth()) == 1) { private void extractInlineVariableAnalysis(List leaves1, List leaves2, AbstractCodeFragment leaf1, AbstractCodeFragment leaf2, - LeafMapping mapping, ReplacementInfo replacementInfo) throws RefactoringMinerTimedOutException { + AbstractCodeMapping mapping, ReplacementInfo replacementInfo) throws RefactoringMinerTimedOutException { UMLAbstractClassDiff classDiff = this.classDiff != null ? this.classDiff : parentMapper != null ? parentMapper.classDiff : null; for(AbstractCodeFragment leaf : leaves2) { if(leaf.equals(leaf2)) { diff --git a/src/test/java/org/refactoringminer/test/TestAllRefactorings.java b/src/test/java/org/refactoringminer/test/TestAllRefactorings.java index c4a25eac83..f9f24a0cf9 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(12363, 20, 232); + test.assertExpectationsWithGitHubAPI(12369, 20, 232); } } diff --git a/src/test/resources/oracle/data.json b/src/test/resources/oracle/data.json index 5c7f6f71a3..cfb2a1a879 100644 --- a/src/test/resources/oracle/data.json +++ b/src/test/resources/oracle/data.json @@ -29732,6 +29732,13 @@ "validation": "TP", "detectionTools": "RefactoringMiner", "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable leftConj : String in method private getNumAgreedPosTag(leftPosTag String, rightPosTag String, leftNv boolean) : String from class org.languagetool.tagging.uk.CompoundTagger", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null }], "refDiffExecutionTime": 0 }, { @@ -35110,6 +35117,20 @@ "validation": "TP", "detectionTools": "RefactoringMiner", "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable isErrorMessage : boolean in method public onMessage(message Message) : boolean from class org.springframework.integration.ip.tcp.TcpInboundGateway", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable isErrorMessage : boolean in method public onMessage(message Message) : boolean from class org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null }], "refDiffExecutionTime": 2231 }, { @@ -39610,6 +39631,13 @@ "validation": "FP", "detectionTools": "GumTreeDiff", "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable localeFilterEnabled : boolean in method private doExecute(context ExecutionContext) : int from class com.facebook.buck.android.FilterResourcesStep", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null }], "refDiffExecutionTime": 2754 }, { @@ -65790,6 +65818,13 @@ "validation": "TP", "detectionTools": "RefactoringMiner", "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable lastPos : int in method private joinFinalLeftData() : void from class org.apache.hadoop.hive.ql.exec.CommonMergeJoinOperator", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null }], "refDiffExecutionTime": 4288 }, { @@ -84491,6 +84526,13 @@ "validation": "TP", "detectionTools": "RefactoringMiner", "validators": null + }, { + "type": "Extract Variable", + "description": "Extract Variable key : DefinedProperty in method private getIndexUpdatesForRangeSeekByPrefix(descriptor IndexDescriptor, prefix String) : ReadableDiffSets from class org.neo4j.kernel.impl.api.state.TxState", + "comment": null, + "validation": "TP", + "detectionTools": "RefactoringMiner", + "validators": null }], "refDiffExecutionTime": 4473 }, { diff --git a/src/test/resources/oracle/expected.txt b/src/test/resources/oracle/expected.txt index e2391f4e92..dfaaf3c063 100644 --- a/src/test/resources/oracle/expected.txt +++ b/src/test/resources/oracle/expected.txt @@ -105,7 +105,7 @@ f6212a7e474f812f31ddbce6d4f7a7a0d498b751, 3, 0, 0 4cca684f368d3ff719c62d3fa4cac3cdb7828bff, 3, 0, 0 247232bdde24b81814a82100743f77d881aaf06b, 7, 0, 0 46b0d84de9c309bca48a99e572e6611693ed5236, 7, 0, 0 -ec5230abc7500734d7b78a176c291378e100a927, 20, 0, 0 +ec5230abc7500734d7b78a176c291378e100a927, 22, 0, 0 fd000ca2e78fce2f8aa11e6a81e4f23c2f1348e6, 1, 0, 0 f1dfb66a368760e77094ac1e3860b332cf0e4eb5, 4, 0, 0 56c273ee11296288cb15320c3de781b94a1e8eb4, 48, 0, 0 @@ -143,7 +143,7 @@ a26b61201cd86c9a8773b418d9c84b446e95a601, 70, 0, 4 74d2cc420e5590ba3bc0ffcc15b30b76a9cbef0b, 10, 0, 5 001de307492df8f84ad15f6aaa0bd1e748d4ce27, 160, 3, 8 4712de476aabe69cd762233c9641dd3cf9f8361b, 54, 0, 2 -dc199688d69416da58b370ca2aa728e935fc8e0d, 24, 1, 0 +dc199688d69416da58b370ca2aa728e935fc8e0d, 25, 1, 0 77fab3caea4495798a248035f0e928f745c7c2db, 91, 0, 2 d1a6ae2a16ba1d53b1de02eea8745d67c6a1a005, 8, 0, 0 8d9bedbf96b14beb027ebc1338bc6d5750e1feb5, 223, 0, 4 @@ -213,7 +213,7 @@ f26d234e8d3458f34454583c22e3bd5f4b2a5da8, 2, 0, 0 19a49f8f36b2f6d82534dc13504d672e41a3a8d1, 9, 0, 0 a1525ac9a0bb8f727167a8be94c81a3415128ef4, 2, 0, 0 6c93f15f502f39dff99ecb01b56dcad7dddb0f0d, 1, 0, 0 -d49765899cb9df6781fff9773ffc244b5167351c, 11, 0, 0 +d49765899cb9df6781fff9773ffc244b5167351c, 12, 0, 0 be292763b8c4cb09988023d6081b0a2d57b4c778, 10, 0, 1 db024f5ec3e9611ddf8103bdc4c3817c704f7b27, 22, 0, 0 ec5ea36faa3dd74585bb339beabdba6149ed63be, 113, 0, 2 @@ -346,7 +346,7 @@ f797bfa4da53315b49f8d97b784047f33ba1bf5f, 89, 1, 1 7eb3567e7880511b76b8b65e8eb7d373927f2fb6, 4, 0, 0 92e98858e742bbb669ccbf790a71a618c581df21, 4, 0, 0 102b23b16bf26cbf439009b4b95542490a082710, 10, 0, 0 -b8d2140fe4faccadcf1a6343ec8cd0cc58c315f9, 5, 0, 0 +b8d2140fe4faccadcf1a6343ec8cd0cc58c315f9, 6, 0, 0 3bdcaa336a6e6a9727c333b433bb9f5d3afc0fb1, 53, 0, 0 f664789737d516ac664462732664121acc111a1e, 3, 0, 0 abe6cd5d4614eb2ae3a78d85196f4d786d5886bd, 8, 0, 0 @@ -457,7 +457,7 @@ e1625136ba12907696ef4c6e922ce073293f3a2c, 3, 0, 0 cc0eaf7faa408a04b68e2b5820f3ebcc75420b5b, 5, 0, 0 6ad1dcbfef36821a71cbffa301c58d1c3ffe8d62, 18, 0, 1 1b70adbfd49e00194c4c1170ef65e8114d7a2e46, 3, 0, 0 -bec15926deb49d2b3f7b979d4cfc819947a434ec, 56, 0, 0 +bec15926deb49d2b3f7b979d4cfc819947a434ec, 57, 0, 0 7c59f2a4f9b03a9e48ca15554291a03477aa19c1, 14, 0, 1 7ed3f273ab0caf0337c22f0b721d51829bb0c877, 3, 0, 0 d12e1c16d1c73142334e689eb01f20abaeba84b0, 1, 0, 0