PsiCodeBlock (final Collection<? extends PsiReferenceExpression> refs) { PsiCodeBlock result = null; for (PsiReferenceExpression psiReference : refs) { if (PsiUtil.isInsideJavadocComment(psiReference)) continue; PsiCodeBlock block = PsiTreeUtil.getParentOfType(psiReference, PsiCodeBlock.class); if (result == null || block == null) { result = block; } else { final PsiElement commonParent = PsiTreeUtil.findCommonParent(result, block); result = PsiTreeUtil.getParentOfType(commonParent, PsiCodeBlock.class, false); if (result == null) return null; } } return result; }