extract method: allow to fold parameters if calls to fields are involved

This commit is contained in:
Anna Kozlova
2014-12-08 16:19:28 +01:00
parent 5ba2b4b384
commit 5a5ed0fe42
4 changed files with 28 additions and 1 deletions
@@ -270,7 +270,7 @@ public class ParametersFolder {
final PsiElement resolved = expression.resolve();
if (resolved instanceof PsiVariable) {
final PsiVariable variable = (PsiVariable)resolved;
if (!inputVariables.contains(variable)) {
if (!(variable instanceof PsiField) && !inputVariables.contains(variable)) {
localVarsUsed[0] = true;
return;
}
@@ -0,0 +1,10 @@
class Main {
private String [] args;
void foo(Main m, int i) {
<selection>if (m.args[i] != null) {
System.out.println(m.args[i]);
}</selection>
}
}
@@ -0,0 +1,14 @@
class Main {
private String [] args;
void foo(Main m, int i) {
newMethod(m.args[i]);
}
private void newMethod(String arg) {
if (arg != null) {
System.out.println(arg);
}
}
}
@@ -344,6 +344,9 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testFoldingWithFieldInvolved() throws Exception {
doTest();
}
public void testIDEADEV11748() throws Exception {
doTest();