GrMember (@NotNull GrReferenceExpression ref, @NotNull PsiClass aClass) { for (PsiElement parent = ref.getParent(); parent != null && parent != aClass; parent = parent.getParent()) { if (parent instanceof GrMember && ((GrMember)parent).getContainingClass() == aClass) { return (GrMember)parent; } } return null; }