void (Environment env, Project project, Editor editor, PsiExpression expression) { var handler = new InplaceIntroduceVariableTest.MyIntroduceVariableHandler(); Disposable disposable = Disposer.newDisposable(); env.logMessage(String.format("Introduce variable using inline introducer; expression: %s at %d", expression.getText(), expression.getTextRange().getStartOffset())); try { UiInterceptors.register(new RandomActivityInterceptor(env, disposable)); TemplateManagerImpl.setTemplateTesting(disposable); handler.invokeImpl(project, expression, editor); TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state != null) { // Could be null if template wasn't started (e.g. too many occurrences) state.gotoEnd(false); } } catch (CommonRefactoringUtil.RefactoringErrorHintException hint) { env.logMessage("Introduce variable failed gracefully with: " + hint.getMessage()); } finally { Disposer.dispose(disposable); } }