Stream<PsiExpression> (@NotNull PsiExpression expression) { return StreamEx.ofTree(expression, e -> { if (e instanceof PsiConditionalExpression ternary) { return StreamEx.of(ternary.getThenExpression(), ternary.getElseExpression()).nonNull(); } if (e instanceof PsiParenthesizedExpression parens) { return StreamEx.ofNullable(parens.getExpression()); } if (e instanceof PsiSwitchExpression switchExpression) { PsiCodeBlock switchBody = switchExpression.getBody(); if (switchBody == null) return StreamEx.empty(); List<PsiExpression> result = new ArrayList<>(); PsiStatement[] statements = switchBody.getStatements(); for (PsiStatement statement : statements) { if (statement instanceof PsiSwitchLabeledRuleStatement rule) { PsiStatement ruleBody = rule.getBody(); if (ruleBody instanceof PsiBlockStatement blockStatement) { collectYieldExpressions(blockStatement, switchExpression, result); } else if (ruleBody instanceof PsiExpressionStatement expr) { result.add(expr.getExpression()); } } else { collectYieldExpressions(statement, switchExpression, result); } } return StreamEx.of(result); } return null; }).remove(e -> e instanceof PsiConditionalExpression || e instanceof PsiParenthesizedExpression || e instanceof PsiSwitchExpression) .map(e -> { if (e instanceof PsiTypeCastExpression cast) { PsiExpression operand = cast.getOperand(); if (operand != null && !(e.getType() instanceof PsiPrimitiveType) && (!(operand.getType() instanceof PsiPrimitiveType) || PsiTypes.nullType().equals(operand.getType()))) { // Ignore to-primitive/from-primitive casts as they may actually change the value return PsiUtil.skipParenthesizedExprDown(operand); } } return e; }) .nonNull() .flatMap(e -> { if (e instanceof PsiMethodCallExpression call && GET_OR_DEFAULT.test(call)) { return StreamEx.of(e, call.getArgumentList().getExpressions()[1]); } return StreamEx.of(e); }); }