private static @Nullable IntentionState createState(@NotNull PyReferenceExpression refExprUnderCaret) {
    final PyImportElement importElement = PsiTreeUtil.getParentOfType(refExprUnderCaret, PyImportElement.class);
    if (importElement != null) {
      return new IntentionState(importElement, null);
    }
    PyReferenceExpression reference =
      Objects.requireNonNullElse(PsiTreeUtil.getTopmostParentOfType(refExprUnderCaret, PyReferenceExpression.class), refExprUnderCaret);
    while (reference.getQualifier() instanceof PyReferenceExpression refQualifier) {
      for (ResolveResult rr : refQualifier.getReference().multiResolve(false)) {
        if (rr.isValidResult() &&
            rr instanceof ImportedResolveResult irr &&
            irr.getDefiner() instanceof PyImportElement importDefiner &&
            importDefiner.getContainingFile() == refExprUnderCaret.getContainingFile()) {
          return new IntentionState(importDefiner, reference.asQualifiedName());
        }
      }
      reference = refQualifier;
    }
    return null;
  }
private static @Nullable IntentionState createState(@NotNull PyReferenceExpression refExprUnderCaret)