PsiExpression (PsiElement root, PsiStatement statement) { PsiExpression condition = null; if (statement instanceof PsiConditionalLoopStatement) { condition = ((PsiConditionalLoopStatement)statement).getCondition(); } else if (statement instanceof PsiIfStatement) { condition = ((PsiIfStatement)statement).getCondition(); } return PsiTreeUtil.isAncestor(condition, root, false) ? condition : null; }