void (@NotNull PsiElement element, @NotNull ActionContext context, @NotNull ModPsiUpdater updater) { final GrForStatement parentStatement = (GrForStatement) element; final GrForInClause clause = (GrForInClause) parentStatement.getClause(); final GrVariable var = clause.getDeclaredVariable(); final GrStatement body = parentStatement.getBody(); final String bodyText; if (body instanceof GrBlockStatement) { final String text = body.getText(); bodyText = text.substring(1, text.length() - 1); } else { bodyText = body.getText(); } GrExpression collection = clause.getIteratedExpression(); assert collection != null; @NonNls final String statement = "x.each{" + var.getText() + " -> " + bodyText + " }"; final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(parentStatement.getProject()); final GrMethodCallExpression eachExpression = (GrMethodCallExpression) factory.createTopElementFromText(statement); ((GrReferenceExpression) eachExpression.getInvokedExpression()).getQualifierExpression().replaceWithExpression(collection, true); parentStatement.replaceWithStatement(eachExpression); }