PsiCodeBlock (@NotNull PsiElement element) { PsiElement parent = element.getParent(); PsiCodeBlock block = null; while (parent != null && !(parent instanceof PsiClass)) { if (parent instanceof PsiCodeBlock) block = (PsiCodeBlock)parent; parent = parent.getParent(); } return block; }