public static PsiClass getContextClass(@NotNull PsiElement element) {
    PsiElement prev = element;
    PsiElement scope = element.getContext();
    while (scope != null) {
      // skip the class if coming from its extends/implements list: those references only rely on the outer context for resolve
      if (scope instanceof PsiClass && (prev instanceof PsiMember || prev instanceof PsiDocComment)) {
        return (PsiClass)scope;
      }
      prev = scope;
      scope = scope.getContext();
    }
    return null;
  }
public static PsiClass getContextClass(@NotNull PsiElement element)