boolean (@NotNull PsiReferenceExpression ref, @NotNull PsiElement targetClassMember) { final JavaResolveResult resolveResult = ref.advancedResolve(false); final PsiElement def = resolveResult.getElement(); if (def != null) { PsiElement parent = def.getParent(); PsiElement commonParent = parent == null ? null : PsiTreeUtil.findCommonParent(parent, targetClassMember); if (commonParent == null) { parent = resolveResult.getCurrentFileResolveScope(); } if (parent instanceof PsiClass) { final PsiClass clss = (PsiClass)parent; if (PsiTreeUtil.isAncestor(targetClassMember, clss, false)) return false; PsiClass containingClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class); while (containingClass != null) { if (containingClass.isInheritor(clss, true) && PsiTreeUtil.isAncestor(targetClassMember, containingClass, false)) { return false; } containingClass = containingClass.getContainingClass(); } } } return true; }