PsiExpression (@NotNull PsiExpression thenExpr, @NotNull PsiExpression elseExpr, @NotNull PsiExpression condition, @NotNull PsiVariable optValue) { PsiVariable nullChecked = ExpressionUtils.getVariableFromNullComparison(condition, true); boolean inverted = false; if (nullChecked == null) { nullChecked = ExpressionUtils.getVariableFromNullComparison(condition, false); if (nullChecked == null) return null; inverted = true; } if (!nullChecked.equals(optValue) || !ExpressionUtils.isReferenceTo(inverted ? thenExpr : elseExpr, optValue)) return null; PsiExpression defaultExpression = inverted ? elseExpr : thenExpr; if (VariableAccessUtils.variableIsUsed(optValue, defaultExpression)) return null; return defaultExpression; }