boolean (@NotNull PsiExpression expression) { if (!(expression instanceof PsiConditionalExpression) && !PsiTypes.booleanType().equals(expression.getType())) return false; PsiElement parent = expression.getParent(); if (parent instanceof PsiLambdaExpression && !LambdaUtil.isSafeLambdaBodyReplacement((PsiLambdaExpression)parent, () -> createSimplifiedReplacement(expression))) { return false; } final ExpressionVisitor expressionVisitor = new ExpressionVisitor(expression.getManager(), false); final Ref<Boolean> canBeSimplified = new Ref<>(Boolean.FALSE); expression.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (!canBeSimplified.get().booleanValue()) { super.visitElement(element); } } @Override public void visitExpression(@NotNull PsiExpression expression) { super.visitExpression(expression); expressionVisitor.clear(); expression.accept(expressionVisitor); if (expressionVisitor.canBeSimplifiedFlag) { canBeSimplified.set(Boolean.TRUE); } } }); return canBeSimplified.get().booleanValue(); }