TextRange (@NotNull GrExpression expression, PsiElement context) { GrIfStatement ifStatement = (GrIfStatement) GroovyPsiElementFactory.getInstance(expression.getProject()).createStatementFromText("if(a){4\n} else{\n}", context); replaceToOldExpression(ifStatement.getCondition(), expression); ifStatement = expression.replaceWithStatement(ifStatement); GrStatement psiElement = ifStatement.getThenBranch(); assert psiElement instanceof GrBlockStatement; GrStatement[] statements = ((GrBlockStatement) psiElement).getBlock().getStatements(); assert statements.length > 0; GrStatement statement = statements[0]; int endOffset = statement.getTextRange().getStartOffset(); statement.getNode().getTreeParent().removeChild(statement.getNode()); return new TextRange(endOffset, endOffset); }