PsiCodeBlock (PsiElement expression) { PsiElement parent = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, PsiClassInitializer.class, PsiLambdaExpression.class); if(parent instanceof PsiMethod) { return ((PsiMethod)parent).getBody(); } if(parent instanceof PsiClassInitializer) { return ((PsiClassInitializer)parent).getBody(); } if(parent instanceof PsiLambdaExpression) { PsiElement body = ((PsiLambdaExpression)parent).getBody(); if(body instanceof PsiCodeBlock) { return (PsiCodeBlock)body; } } return null; }