Test and comment for IDEA-176340 "Optional.isPresent not highlighted"

Actually was fixed in 0234c70
This commit is contained in:
Tagir Valeev
2017-07-21 17:12:02 +07:00
parent f290cffefc
commit 926a541520
3 changed files with 6 additions and 4 deletions

View File

@@ -194,6 +194,8 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
if (!hasOptionalReference.get() || !(lambdaCandidate instanceof PsiExpression)) return ProblemType.INFO;
PsiExpression expression = (PsiExpression)lambdaCandidate;
if (falseExpression != null && NullnessUtil.getExpressionNullness(expression) != Nullness.NOT_NULL) {
// falseExpression == null is "consumer" case (to be replaced with ifPresent()),
// in this case we don't care about expression nullness
return ProblemType.INFO;
}
return ProblemType.WARNING;

View File

@@ -1,4 +1,4 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
import java.util.*;
@@ -6,6 +6,6 @@ public class Main {
String myString;
public void testOptional(Optional<String> str) {
str.ifPresent(s -> myString = s);
str.ifPresent(s -> myString = s.isEmpty() ? null : s);
}
}

View File

@@ -1,4 +1,4 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
import java.util.*;
@@ -7,7 +7,7 @@ public class Main {
public void testOptional(Optional<String> str) {
if (str.isPrese<caret>nt()) {
myString = str.get();
myString = str.get().isEmpty() ? null : str.get();
}
}
}