static PsiVariable getIterableVariable(PsiStatement statement, boolean ignoreUntypedCollections) {
    if (!(statement instanceof PsiDeclarationStatement declaration)) {
      return null;
    }
    final PsiElement[] declaredElements = declaration.getDeclaredElements();
    if (declaredElements.length != 1) {
      return null;
    }
    final PsiElement declaredElement = declaredElements[0];
    if (!(declaredElement instanceof PsiVariable variable)) {
      return null;
    }
    if (!TypeUtils.variableHasTypeOrSubtype(variable, CommonClassNames.JAVA_UTIL_ITERATOR, "java.util.ListIterator")) {
      return null;
    }
    final PsiExpression initialValue = PsiUtil.skipParenthesizedExprDown(variable.getInitializer());
    if (!(initialValue instanceof PsiMethodCallExpression initialCall)) {
      return null;
    }
    if (!initialCall.getArgumentList().isEmpty()) {
      return null;
    }
    final PsiReferenceExpression initialMethodExpression = initialCall.getMethodExpression();
    final @NonNls String initialCallName = initialMethodExpression.getReferenceName();
    if (!HardcodedMethodConstants.ITERATOR.equals(initialCallName) && !"listIterator".equals(initialCallName)) {
      return null;
    }
    final PsiExpression qualifier = ExpressionUtils.getEffectiveQualifier(initialMethodExpression);
    if (qualifier == null || qualifier instanceof PsiSuperExpression) {
      return null;
    }
    final PsiType qualifierType = qualifier.getType();
    if (!(qualifierType instanceof PsiClassType classType)) {
      return null;
    }
    final PsiClass qualifierClass = classType.resolve();
    if (ignoreUntypedCollections) {
      final PsiClassType type = (PsiClassType)variable.getType();
      final PsiType[] parameters = type.getParameters();
      final PsiType[] parameters1 = classType.getParameters();
      if (parameters.length == 0 && parameters1.length == 0) {
        return null;
      }
    }
    if (!InheritanceUtil.isInheritor(qualifierClass, CommonClassNames.JAVA_LANG_ITERABLE)) {
      return null;
    }
    return variable;
  }
static PsiVariable getIterableVariable(PsiStatement statement, boolean ignoreUntypedCollections)