@Override
    protected boolean buildTemplateAndStart(
      @NotNull Collection<PsiReference> refs,
      @NotNull Collection<Pair<PsiElement, TextRange>> stringUsages,
      @NotNull PsiElement scope,
      @NotNull PsiFile containingFile
    ) {
        myEditor.putUserData(INTRODUCE_RESTART, false);
        //noinspection ConstantConditions
        myEditor.getCaretModel().moveToOffset(getNameIdentifier().getTextOffset());
        boolean result = super.buildTemplateAndStart(refs, stringUsages, scope, containingFile);

        TemplateState templateState =
                TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
        if (templateState != null) {
            if (myDeclaration.getTypeReference() != null) {
                TemplateEditingListener postprocessor = createTypeReferencePostprocessor();
                templateState.addTemplateStateListener(new TemplateEditingAdapter() {
                    @Override
                    public void templateFinished(@NotNull Template template, boolean brokenOff) {
                        if (!myRestart) {
                            postprocessor.templateFinished(template, brokenOff);
                        }
                    }
                });
            }
            templateState.addTemplateStateListener(new TemplateEditingAdapter() {
                @Override
                public void templateFinished(@NotNull Template template, boolean brokenOff) {
                    if (brokenOff) {
                        onCancel(myRestart);
                    }
                }

                @Override
                public void templateCancelled(Template template) {
                    onCancel(myRestart);
                }
            });
        }

        return result;
    }
@Override
    protected boolean buildTemplateAndStart(
      @NotNull Collection<PsiReference> refs,
      @NotNull Collection<Pair<PsiElement, TextRange>> stringUsages,
      @NotNull PsiElement scope,
      @NotNull PsiFile containingFile
    )