@NotNull
  private TemplateImpl substituteTemplate(@NotNull TemplateImpl template, @NotNull Editor editor) {
    PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
    if (psiFile == null) {
      return template;
    }
    for (TemplateSubstitutor substitutor : TemplateSubstitutor.EP_NAME.getExtensionList()) {
      final TemplateImpl substituted = substitutor.substituteTemplate(new TemplateSubstitutionContext(myProject, editor), template);
      if (substituted != null) {
        template = substituted;
      }
    }
    return template;
  }
@NotNull
  private TemplateImpl substituteTemplate(@NotNull TemplateImpl template, @NotNull Editor editor)