TextRange (@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement container, PsiElement @NotNull [] statements) { statements = MoveDeclarationsOutHelperKt.move(container, statements, true); if (statements.length == 0) { return null; } KtTryExpression tryExpression = (KtTryExpression) new KtPsiFactory(project).createExpression(getCodeTemplate()); tryExpression = (KtTryExpression) container.addAfter(tryExpression, statements[statements.length - 1]); // TODO move a comment for first statement KtBlockExpression tryBlock = tryExpression.getTryBlock(); // Add statements in try block of created try - catch - finally addStatementsInBlock(tryBlock, statements); // Delete statements from original code container.deleteChildRange(statements[0], statements[statements.length - 1]); tryExpression = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(tryExpression); if (tryExpression == null) return null; return getTextRangeForCaret(tryExpression); }