TextRange ( @NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) { KtParenthesizedExpression parenthesizedExpression = (KtParenthesizedExpression) new KtPsiFactory(expression.getProject()).createExpression("(a)"); KtExpression expressionWithoutParentheses = parenthesizedExpression.getExpression(); assert expressionWithoutParentheses != null : "KtExpression should exists for " + parenthesizedExpression.getText() + " expression"; expressionWithoutParentheses.replace(expression); expression = (KtExpression) expression.replace(parenthesizedExpression); CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(expression); int offset = expression.getTextRange().getEndOffset(); return new TextRange(offset, offset); }