PsiClass (PsiReferenceExpression refExpr, PsiMember refMember) { LOG.assertTrue(refExpr.getQualifierExpression() == null); final PsiClass refMemberClass = refMember.getContainingClass(); if (refMemberClass == null) return null; PsiElement parent = refExpr.getContext(); while(parent != null){ if (parent instanceof PsiClass){ if (parent.equals(refMemberClass) || ((PsiClass)parent).isInheritor(refMemberClass, true)){ return (PsiClass)parent; } } parent = parent.getContext(); } return refMemberClass; }