TextRange (@NotNull GrExpression expression, PsiElement context) { GrWhileStatement whileStatement = (GrWhileStatement) GroovyPsiElementFactory.getInstance(expression.getProject()).createStatementFromText("while(a){4\n}", context); replaceToOldExpression(whileStatement.getCondition(), expression); whileStatement = expression.replaceWithStatement(whileStatement); GrStatement body = whileStatement.getBody(); assert body instanceof GrBlockStatement; GrStatement[] statements = ((GrBlockStatement) body).getBlock().getStatements(); assert statements.length > 0; GrStatement statement = statements[0]; int offset = statement.getTextRange().getStartOffset(); statement.getNode().getTreeParent().removeChild(statement.getNode()); return new TextRange(offset, offset); }