private static void getThisClassesToMembers(final PsiElement scope, final Map<PsiClass, Set<PsiMember>> map, final PsiMember refMember) {
    if (scope instanceof PsiExpression expression &&
        (!(scope instanceof PsiReferenceExpression) || !((PsiReferenceExpression)scope).isReferenceTo(refMember))) {
      final Pair<PsiMember, PsiClass> pair = getMemberAndClassReferencedByThis(expression);
      if (pair != null) {
        PsiClass refClass = pair.getSecond();
        PsiMember member = pair.getFirst();
        if (refClass != null) {
          boolean inherited = false;
          PsiClass parentClass = PsiTreeUtil.getParentOfType(scope, PsiClass.class, true);
          while (parentClass != null && PsiTreeUtil.isAncestor(refMember, parentClass, false)) {
            if (parentClass == refClass || parentClass.isInheritor(refClass, true)) {
              inherited = true;
              break;
            }
            parentClass = PsiTreeUtil.getParentOfType(parentClass, PsiClass.class, true);
          }
          if (!inherited && !PsiTreeUtil.isAncestor(refMember, member, false)) {
            addReferencedMember(map, refClass, member);
          }
        }
      }

      if (expression instanceof PsiThisExpression thisExpression) {
        final PsiJavaCodeReferenceElement thisQualifier = thisExpression.getQualifier();
        PsiClass thisClass =
          thisQualifier == null ? PsiTreeUtil.getParentOfType(expression, PsiClass.class, true) : ((PsiClass)thisQualifier.resolve());
        if (thisClass != null && !PsiTreeUtil.isAncestor(refMember, thisClass, false)) {
          addReferencedMember(map, thisClass, null);
        }
      }
    }

    final PsiElement[] children = scope.getChildren();
    for (PsiElement child : children) {
      getThisClassesToMembers(child, map, refMember);
    }
  }
private static void getThisClassesToMembers(final PsiElement scope, final Map<PsiClass, Set<PsiMember>> map, final PsiMember refMember)