boolean (PsiReference reference) { final PsiElement element = reference.getElement(); final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class); if (method.equals(containingMethod)) { // recursive call return true; } final PsiClass containingClass = ClassUtils.getContainingClass(element); if (containingClass == null) { return false; } if (myContainingClass != null) { if (!myContainingClass.equals(containingClass)) { return false; } } else if (!PsiTreeUtil.isAncestor(methodClass, containingClass, true)) { return false; } myContainingClass = containingClass; return true; }