mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-151867 ExtractMethodObject drops declaration of local variable when it is shared with a return value
This commit is contained in:
+1
-1
@@ -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);
|
||||
|
||||
+10
@@ -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;
|
||||
}
|
||||
}
|
||||
+33
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user