PsiIfStatement (@NotNull PsiIfStatement ifStatement) { PsiElement parent = ifStatement.getParent(); if (parent instanceof PsiIfStatement) { return (PsiIfStatement)parent; } if (parent instanceof PsiCodeBlock) { if (((PsiCodeBlock)parent).getStatements()[0] != ifStatement) return null; return tryCast(parent.getParent().getParent(), PsiIfStatement.class); } return null; }