TextRange (@NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) { KtStringTemplateExpression stringTemplateExpression = (KtStringTemplateExpression) new KtPsiFactory(expression.getProject()).createExpression(getCodeTemplate(expression)); KtStringTemplateEntry templateEntry = stringTemplateExpression.getEntries()[0]; KtExpression innerExpression = templateEntry.getExpression(); assert innerExpression != null : "KtExpression should exists for " + stringTemplateExpression; innerExpression.replace(expression); expression = (KtExpression) expression.replace(stringTemplateExpression); CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(expression); int offset = expression.getTextRange().getEndOffset(); return new TextRange(offset, offset); }