PsiExpression (@NotNull PsiStatement statement, @NotNull PsiVariable optValue) { PsiIfStatement ifStatement = tryCast(statement, PsiIfStatement.class); if (ifStatement == null) return null; if (ifStatement.getElseBranch() != null) return null; PsiExpression condition = ifStatement.getCondition(); if (condition == null) return null; if (ExpressionUtils.getVariableFromNullComparison(condition, false) != optValue) return null; PsiStatement thenStatement = ControlFlowUtils.stripBraces(ifStatement.getThenBranch()); PsiExpressionStatement expressionStatement = tryCast(thenStatement, PsiExpressionStatement.class); if (expressionStatement == null) return null; return expressionStatement.getExpression(); }