LambdaGenerationUtil#canBeUncheckedLambda: supports statements; checks control-flow breaks;

Fix for IDEA-165369 Replace Optional.isPresent() should be disabled if the thenBranch contains non-local control flow
This commit is contained in:
Tagir Valeev
2016-12-14 15:44:59 +07:00
parent 1cc292570c
commit dddfd5d7b6
8 changed files with 226 additions and 39 deletions
@@ -4,6 +4,7 @@ import java.util.*;
public class Main {
public void testOptional(Optional<String> str) {
if (str == null) str = Optional.empty();
str.ifPresent(System.out::println);
}
}
@@ -0,0 +1,27 @@
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
import java.util.Optional;
public class Test {
public static void main(String[] args) {
for(String arg : args) {
Optional<String> opt = Optional.of("xyz");
opt.ifPresent(s -> {
System.out.println(s);
System.out.println(s);
Runnable r = () -> {
return;
};
for (int i = 0; i < 10; i++) {
if (i == 3) continue;
System.out.println(arg);
if (i == 5)
break;
}
System.out.println(s);
throw new RuntimeException();
});
}
}
}
@@ -4,6 +4,7 @@ import java.util.*;
public class Main {
public void testOptional(Optional<String> str) {
if (str == null) str = Optional.empty();
if (str.isPrese<caret>nt()) {
System.out.println(str.get());
}
@@ -0,0 +1,25 @@
// "Replace Optional.isPresent() condition with functional style expression" "false"
import java.util.Optional;
public class Test {
public static void main(String[] args) {
for(String arg : args) {
Optional<String> opt = Optional.of("xyz");
if (opt.isPre<caret>sent()) {
System.out.println(opt.get());
System.out.println(opt.get());
Runnable r = () -> {return;};
for(int i=0; i<10; i++) {
if(i == 3) continue;
System.out.println(arg);
if(i == 5)
break;
}
System.out.println(opt.get());
break;
}
}
}
}
@@ -0,0 +1,25 @@
// "Replace Optional.isPresent() condition with functional style expression" "false"
import java.util.Optional;
public class Test {
public static void main(String[] args) {
for(String arg : args) {
Optional<String> opt = Optional.of("xyz");
if (opt.isPre<caret>sent()) {
System.out.println(opt.get());
System.out.println(opt.get());
Runnable r = () -> {return;};
for(int i=0; i<10; i++) {
if(i == 3) continue;
System.out.println(arg);
if(i == 5)
break;
}
System.out.println(opt.get());
continue;
}
}
}
}
@@ -0,0 +1,25 @@
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
import java.util.Optional;
public class Test {
public static void main(String[] args) {
for(String arg : args) {
Optional<String> opt = Optional.of("xyz");
if (opt.isPre<caret>sent()) {
System.out.println(opt.get());
System.out.println(opt.get());
Runnable r = () -> {return;};
for(int i=0; i<10; i++) {
if(i == 3) continue;
System.out.println(arg);
if(i == 5)
break;
}
System.out.println(opt.get());
throw new RuntimeException();
}
}
}
}