private static void checkUsedElements(PsiMember member,
                                 PsiElement scope,
                                 @NotNull Set<? extends PsiMember> membersToMove,
                                 @Nullable Set<? extends PsiMethod> abstractMethods,
                                 @Nullable PsiClass targetClass,
                                 PsiClass accessClass,
                                 @NotNull PsiElement context,
                                 MultiMap<PsiElement, @DialogMessage String> conflicts) {
    final Set<PsiMember> moving = new HashSet<>(membersToMove);
    if (abstractMethods != null) {
      moving.addAll(abstractMethods);
    }
    if (scope instanceof PsiReferenceExpression refExpr) {
      PsiElement refElement = refExpr.resolve();
      if (refElement instanceof PsiMember) {
        PsiExpression qualifier = refExpr.getQualifierExpression();
        PsiClass qualifierAccessClass = (PsiClass)(qualifier != null && !(qualifier instanceof PsiSuperExpression) ? PsiUtil.getAccessObjectClass(qualifier).getElement()
                                                                                                                   : accessClass != null && PsiTreeUtil.isAncestor(((PsiMember)refElement).getContainingClass(), accessClass, true) ? null : accessClass);
        if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false) &&
            (qualifierAccessClass == null || !RefactoringHierarchyUtil.willBeInTargetClass(qualifierAccessClass, moving, targetClass, false))) {
          analyzeAccessibilityAfterMove((PsiMember)refElement, context, qualifierAccessClass, member, conflicts);
        }
      }
    }
    else if (scope instanceof PsiNewExpression newExpression) {
      final PsiAnonymousClass anonymousClass = newExpression.getAnonymousClass();
      if (anonymousClass != null) {
        if (!RefactoringHierarchyUtil.willBeInTargetClass(anonymousClass, moving, targetClass, false)) {
          analyzeAccessibilityAfterMove(anonymousClass, context, anonymousClass, member, conflicts);
        }
      }
      else {
        final PsiMethod refElement = newExpression.resolveConstructor();
        if (refElement != null) {
          if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
            analyzeAccessibilityAfterMove(refElement, context, accessClass, member, conflicts);
          }
        }
      }
    }
    else if (scope instanceof PsiJavaCodeReferenceElement refExpr) {
      PsiElement refElement = refExpr.resolve();
      if (refElement instanceof PsiMember) {
        if (!RefactoringHierarchyUtil.willBeInTargetClass(refElement, moving, targetClass, false)) {
          analyzeAccessibilityAfterMove((PsiMember)refElement, context, accessClass, member, conflicts);
        }
      }
    }

    for (PsiElement child = scope.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child instanceof PsiWhiteSpace || child instanceof PsiComment) continue;
      checkUsedElements(member, child, membersToMove, abstractMethods, targetClass,
                        child instanceof PsiClass ? (PsiClass)child : accessClass, context, conflicts);
    }
  }
private static void checkUsedElements(PsiMember member,
                                 PsiElement scope,
                                 @NotNull Set<? extends PsiMember> membersToMove,
                                 @Nullable Set<? extends PsiMethod> abstractMethods,
                                 @Nullable PsiClass targetClass,
                                 PsiClass accessClass,
                                 @NotNull PsiElement context,
                                 MultiMap<PsiElement, @DialogMessage String> conflicts)