PyForStatement (final PyListCompExpression expression, final PyElementGenerator elementGenerator, final String result) { final List<PyComprehensionComponent> components = expression.getComponents(); final StringBuilder stringBuilder = new StringBuilder(); int slashNum = 1; for (PyComprehensionComponent component : components) { if (component instanceof PyComprehensionForComponent) { stringBuilder.append("for "); stringBuilder.append(((PyComprehensionForComponent)component).getIteratorVariable().getText()); stringBuilder.append(" in "); stringBuilder.append(((PyComprehensionForComponent)component).getIteratedList().getText()); stringBuilder.append(":\n"); } if (component instanceof PyComprehensionIfComponent) { final PyExpression test = ((PyComprehensionIfComponent)component).getTest(); if (test != null) { stringBuilder.append("if "); stringBuilder.append(test.getText()); stringBuilder.append(":\n"); } } stringBuilder.append("\t".repeat(slashNum)); ++slashNum; } stringBuilder.append(result); return elementGenerator.createFromText(LanguageLevel.forElement(expression), PyForStatement.class, stringBuilder.toString()); }