private static PsiElement getReferenceToIterate(PsiExpression expression, PsiElement context) {
    if (expression instanceof PsiMethodCallExpression ||
        expression instanceof PsiTypeCastExpression ||
        expression instanceof PsiArrayAccessExpression ||
        expression instanceof PsiNewExpression) {
      final String variableName = getVariableName(expression);
      return createVariable(variableName, expression, context);
    }
    else if (expression instanceof PsiParenthesizedExpression parenthesizedExpression) {
      final PsiExpression innerExpression =
        parenthesizedExpression.getExpression();
      return getReferenceToIterate(innerExpression, context);
    }
    else if (expression instanceof PsiJavaCodeReferenceElement referenceElement) {
      final String variableName = getVariableName(expression);
      if (referenceElement.isQualified()) {
        return createVariable(variableName, expression, context);
      }
      final PsiElement target = referenceElement.resolve();
      if (target instanceof PsiVariable) {
        // maybe should not do this for local variables outside of
        // anonymous classes
        return referenceElement;
      }
      return createVariable(variableName, expression, context);
    }
    return expression;
  }
private static PsiElement getReferenceToIterate(PsiExpression expression, PsiElement context)