PsiIfStatement (PsiCodeBlock block, PsiElement commonParent) { while (true) { PsiIfStatement ifStatement = PsiTreeUtil.getNonStrictParentOfType(commonParent, PsiIfStatement.class); if (ifStatement == null) return null; PsiElement parent = ifStatement.getParent(); if (parent == block) return ifStatement; commonParent = parent; } }