OptionalIsPresentInspection: simplify isRaw() and isOptionalLambdaCandidate(); fix getComments(); add more tests (IDEA-CR-13980)

This commit is contained in:
Tagir Valeev
2016-09-27 12:01:07 +07:00
parent 89185189d9
commit 7e72d2fe9e
5 changed files with 39 additions and 29 deletions
@@ -5,7 +5,9 @@ import java.util.*;
public class Main {
public void testOptional(Optional<String> str) {
String val;
val = str.map(String::trim).orElse("");
val = str.map( // line comment
// another line comment
/* block comment *//*block comment*/String::trim).orElse("");
System.out.println(val);
}
}
@@ -12,6 +12,6 @@ public class Main {
public Number testOptionalComments(Optional<MyList> strList) {
/* optional is present *//* optional is absent */
return strList.map(/*return something */myList -> myList.size() > /*too big*/ 1 ? myList.get(1) : 1.0).orElse(/* return null*/null);
return strList.map( /*return something */ myList -> myList.size() > /*too big*/ 1 ? myList.get(1) : 1.0).orElse( /* return null*/ null);
}
}
@@ -6,7 +6,9 @@ public class Main {
public void testOptional(Optional<String> str) {
String val;
if (str.isPrese<caret>nt()) {
val = str.get().trim();
val = // line comment
// another line comment
str.get().trim() /* block comment *//*block comment*/;
} else {
val = "";
}
@@ -0,0 +1,14 @@
// "Replace Optional.isPresent() condition with map().orElse()" "false"
import java.util.*;
public class Main {
public String testOptional(Optional<String> str) {
int i = 5;
if (Math.random() > 0.5) i = 6;
if (str.isPre<caret>sent()) {
return str.get().substring(i);
}
return "";
}
}