TextRange (@NotNull GrExpression expression, PsiElement context) { GrMethodCallExpression call = (GrMethodCallExpression) GroovyPsiElementFactory.getInstance(expression.getProject()).createStatementFromText("with(a){4\n}", context); replaceToOldExpression(call.getExpressionArguments()[0], expression); call = expression.replaceWithStatement(call); GrClosableBlock block = call.getClosureArguments()[0]; GrStatement statementInBody = block.getStatements()[0]; int offset = statementInBody.getTextRange().getStartOffset(); statementInBody.getParent().getNode().removeChild(statementInBody.getNode()); return new TextRange(offset, offset); }