mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-177515 Optional.isPresent() refactoring should not be suggested for ternary with incompatible branch types
This commit is contained in:
@@ -368,8 +368,12 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
|
||||
if(!(trueElement instanceof PsiExpression) || !(falseElement instanceof PsiExpression)) return ProblemType.NONE;
|
||||
PsiExpression trueExpression = (PsiExpression)trueElement;
|
||||
PsiExpression falseExpression = (PsiExpression)falseElement;
|
||||
return (isSimpleOrUnchecked(falseExpression)) ?
|
||||
getTypeByLambdaCandidate(optionalVariable, trueExpression, falseExpression) : ProblemType.NONE;
|
||||
PsiType trueType = trueExpression.getType();
|
||||
PsiType falseType = falseExpression.getType();
|
||||
if (trueType == null || falseType == null || !trueType.isAssignableFrom(falseType) || !isSimpleOrUnchecked(falseExpression)) {
|
||||
return ProblemType.NONE;
|
||||
}
|
||||
return getTypeByLambdaCandidate(optionalVariable, trueExpression, falseExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Optional;
|
||||
|
||||
public class OptionalTest {
|
||||
Optional<LocalDate> date = Optional.of(LocalDate.now());
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final String x = "{date:" + (date.isPres<caret>ent() ? date.get() : "<missing>") + '}';
|
||||
return x;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user