Field can be local: added support for nested and local classes (IDEA-206647)

This commit is contained in:
Artemiy Sartakov
2019-02-07 17:27:00 +07:00
parent 164e3869e1
commit 043c2d563e
12 changed files with 161 additions and 5 deletions
@@ -0,0 +1,12 @@
// "Convert field to local variable in method 'test'" "true"
class Foo {
void test() {
class Bar {
void test() {
int x = 2; // could be local
System.out.println(x);
}
}
}
}
@@ -0,0 +1,19 @@
// "Convert to local" "true"
class Outer {
void test() {
class Local {
void foo() {
String s = "1";
System.out.println(s);
}
void bar() {
String s = "2";
System.out.println(s);
}
}
}
}
@@ -0,0 +1,10 @@
// "Convert field to local variable in method 'test'" "true"
class Foo {
static class Bar {
void test() {
int x = 2; // could be local
System.out.println(x);
}
}
}
@@ -0,0 +1,7 @@
// "Convert to local" "true"
class Test {
private Runnable r = () -> {
String field = "foo";
}
}
@@ -0,0 +1,15 @@
// "Fix all 'Field can be local' problems in file" "false"
class Outer {
void test(Inner inner) {
System.out.println(inner.field);
}
class Inner {
private final String f<caret>ield;
Inner(String field) {
this.field = field;
}
}
}
@@ -0,0 +1,13 @@
// "Convert field to local variable in method 'test'" "true"
class Foo {
void test() {
class Bar {
private int <caret>x;
void test() {
x = 2; // could be local
System.out.println(x);
}
}
}
}
@@ -0,0 +1,20 @@
// "Convert to local" "true"
class Outer {
void test() {
class Local {
private String <caret>s;
void foo() {
s = "1";
System.out.println(s);
}
void bar() {
s = "2";
System.out.println(s);
}
}
}
}
@@ -0,0 +1,11 @@
// "Convert field to local variable in method 'test'" "true"
class Foo {
static class Bar {
private int <caret>x;
void test() {
x = 2; // could be local
System.out.println(x);
}
}
}
@@ -0,0 +1,9 @@
// "Convert to local" "true"
class Test {
private String <caret>field;
private Runnable r = () -> {
field = "foo";
}
}