IDEA-151867 ExtractMethodObject drops declaration of local variable when it is shared with a return value

This commit is contained in:
Egor.Ushakov
2016-02-25 20:47:12 +03:00
parent 18ea3ac04b
commit 4caabe011d
4 changed files with 64 additions and 1 deletions
@@ -335,7 +335,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
if (Comparing.strEqual(var.getName(), variable.getName())) {
final PsiExpression initializer = var.getInitializer();
if (initializer == null) {
replacementMap.put(statement, null);
replacementMap.put(declaredElement, null);
}
else {
replacementMap.put(var, var);
@@ -0,0 +1,10 @@
class Test {
public int context1() {
<selection>int i, j;
i = 0;
j = 1;
if (j > 0) return i;
</selection>
return 0;
}
}
@@ -0,0 +1,33 @@
class Test {
public int context1() {
Inner inner = new Inner().invoke();
if (inner.is()) return inner.getI();
return 0;
}
private class Inner {
private boolean myResult;
private int i;
boolean is() {
return myResult;
}
public int getI() {
return i;
}
public Inner invoke() {
int j;
i = 0;
j = 1;
if (j > 0) {
myResult = true;
return this;
}
myResult = false;
return this;
}
}
}
@@ -1,3 +1,19 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* User: anna
* Date: 06-May-2008
@@ -72,6 +88,10 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightRefactor
doTest();
}
public void testMultilineDeclarationsWithReturn() throws Exception {
doTest();
}
public void testConditionalExit() throws Exception {
doTest();
}