void generate() {
      PsiStatement context = myStatements.get(0);
      PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
      String loopDeclaration;
      String varName;
      if (myType == null) {
        int size = myStatements.size() / myStatementCount;
        varName = new VariableNameGenerator(context, VariableKind.PARAMETER).byType(PsiTypes.intType()).generate(true);
        loopDeclaration = "for(int " + varName + "=0;" + varName + "<" + size + ";" + varName + "++)";
      }
      else {
        varName = new VariableNameGenerator(context, VariableKind.PARAMETER).byType(myType).generate(true);
        loopDeclaration = tryCollapseIntoCountingLoop(varName);
        if (loopDeclaration == null) {
          String container;
          if (myType instanceof PsiPrimitiveType) {
            container = "new " + myType.getCanonicalText() + "[]{" + StringUtil.join(myLoopElements, PsiElement::getText, ",") + "}";
          }
          else {
            container = CommonClassNames.JAVA_UTIL_ARRAYS + ".asList(" + StringUtil.join(myLoopElements, PsiElement::getText, ",") + ")";
          }
          loopDeclaration = "for(" + myType.getCanonicalText() + " " + varName + ":" + container + ")";
        }
      }
      PsiLoopStatement loop = (PsiLoopStatement)factory.createStatementFromText(loopDeclaration + " {}", context);

      PsiCodeBlock block = ((PsiBlockStatement)Objects.requireNonNull(loop.getBody())).getCodeBlock();
      PsiJavaToken brace = Objects.requireNonNull(block.getRBrace());

      PsiExpression ref = factory.createExpressionFromText(varName, context);
      myExpressionsToReplace.forEach(expr -> expr.replace(ref));
      block.addRangeBefore(myStatements.get(0), myStatements.get(myStatementCount - 1), brace);
      PsiElement origBlock = context.getParent();
      JavaCodeStyleManager.getInstance(block.getProject()).shortenClassReferences(origBlock.addBefore(loop, myStatements.get(0)));
      CommentTracker ct = new CommentTracker();
      myLoopElements.forEach(ct::markUnchanged);
      ct.delete(myStatements.subList(myStatementCount, myStatements.size()).toArray(PsiStatement.EMPTY_ARRAY));
      ct.insertCommentsBefore(myStatements.get(0));
      origBlock.deleteChildRange(myStatements.get(0), myStatements.get(myStatementCount - 1));
    }
void generate()