RemoveUnusedVariableUtil: code generation fixes

1. Support Java 12 switch rules and switch expressions (IDEA-203692)
2. Support void expression lambdas
3. Fix PSI structure when expression list statement is reduced to single expression
This commit is contained in:
Tagir Valeev
2018-12-20 13:49:11 +07:00
parent aaa8b07b1b
commit 04f7352faa
10 changed files with 96 additions and 20 deletions

View File

@@ -0,0 +1,6 @@
// "Remove variable 'i'" "true"
public class Main {
void test(String s) {
foo(1);
}
}

View File

@@ -0,0 +1,8 @@
// "Remove field 'x'" "true"
public class Main {
void test() {
Runnable r = () -> {
};
}
}

View File

@@ -0,0 +1,8 @@
// "Remove variable 'i'" "true"
public class Main {
int test(String s) {
return switch(s) {
default -> 1;
}
}
}

View File

@@ -0,0 +1,9 @@
// "Remove variable 'i'" "true"
public class Main {
void test(String s) {
switch(s) {
case "foo" -> {
}
}
}
}

View File

@@ -0,0 +1,7 @@
// "Remove variable 'i'" "true"
public class Main {
void test(String s) {
int <caret>i;
foo(i = 1);
}
}

View File

@@ -0,0 +1,8 @@
// "Remove field 'x'" "true"
public class Main {
private int <caret>x;
void test() {
Runnable r = () -> x = 1;
}
}

View File

@@ -0,0 +1,9 @@
// "Remove variable 'i'" "true"
public class Main {
int test(String s) {
int <caret>i;
return switch(s) {
default -> i = 1;
}
}
}

View File

@@ -0,0 +1,9 @@
// "Remove variable 'i'" "true"
public class Main {
void test(String s) {
int <caret>i;
switch(s) {
case "foo" -> i = 1;
}
}
}