private void processReference(@NotNull PyElement node, @Nullable PsiReference reference) {
    if (!isEnabled(node) || reference == null || reference.isSoft()) {
      return;
    }
    final PyExceptPart guard = getImportErrorGuard(node);
    if (guard != null) {
      processReferenceInImportGuard(node, guard);
      return;
    }
    if (node instanceof PyQualifiedExpression qExpr) {
      final PyExpression qualifier = qExpr.getQualifier();
      final String name = node.getName();
      if (qualifier != null && name != null && PyHasAttrHelper.INSTANCE.getNamesFromHasAttrs(node, qualifier).contains(name)) {
        return;
      }
    }
    PsiElement target = null;
    final boolean unresolved;
    if (reference instanceof PsiPolyVariantReference poly) {
      final ResolveResult[] resolveResults = poly.multiResolve(false);
      unresolved = (resolveResults.length == 0);
      for (ResolveResult resolveResult : resolveResults) {
        if (target == null && resolveResult.isValidResult()) {
          target = resolveResult.getElement();
        }
        if (resolveResult instanceof ImportedResolveResult) {
          final PyImportedNameDefiner definer = ((ImportedResolveResult)resolveResult).getDefiner();
          if (definer != null) {
            myUsedImports.add(definer);
          }
        }
      }
    }
    else {
      target = reference.resolve();
      unresolved = (target == null);
    }
    if (unresolved) {
      boolean ignoreUnresolved = ignoreUnresolved(node, reference);
      if (!ignoreUnresolved) {
        final HighlightSeverity severity = reference instanceof PsiReferenceEx
                                           ? ((PsiReferenceEx)reference).getUnresolvedHighlightSeverity(myTypeEvalContext)
                                           : HighlightSeverity.ERROR;
        if (severity == null) return;
        registerUnresolvedReferenceProblem(node, reference, severity);
      }
      // don't highlight unresolved imports as unused
      if (node.getParent() instanceof PyImportElement) {
        myAllImports.remove(node.getParent());
      }
    }
    else if (reference instanceof PyImportReference &&
             target == reference.getElement().getContainingFile() &&
             !isContainingFileImportAllowed(node, (PsiFile)target)) {
      registerProblem(node, PyPsiBundle.message("INSP.unresolved.refs.import.resolves.to.its.containing.file"));
    }
  }
private void processReference(@NotNull PyElement node, @Nullable PsiReference reference)