PsiExpression (@NotNull PsiStatement statement, @NotNull PsiVariable optValue) { if (statement instanceof PsiIfStatement ifStatement) { PsiExpression condition = ifStatement.getCondition(); if (condition == null) return null; PsiExpression thenExpr = getReturnExpression(ifStatement.getThenBranch()); PsiExpression elseExpr = getReturnExpression(ifStatement.getElseBranch()); if (thenExpr == null || elseExpr == null) return null; return extractConditionalDefaultValue(thenExpr, elseExpr, condition, optValue); } else if (statement instanceof PsiReturnStatement returnStatement) { PsiExpression returnValue = returnStatement.getReturnValue(); PsiConditionalExpression ternary = tryCast(PsiUtil.skipParenthesizedExprDown(returnValue), PsiConditionalExpression.class); if (ternary == null) return null; PsiExpression thenExpression = ternary.getThenExpression(); PsiExpression elseExpression = ternary.getElseExpression(); if (thenExpression == null || elseExpression == null) return null; return extractConditionalDefaultValue(thenExpression, elseExpression, ternary.getCondition(), optValue); } return null; }