public static void expandTemplate(@NotNull String key,
                                    @NotNull CustomTemplateCallback callback,
                                    @NotNull Editor editor,
                                    @NotNull PostfixTemplateProvider provider,
                                    @NotNull PostfixTemplate postfixTemplate) {
    ThreadingAssertions.assertEventDispatchThread();
    FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.postfix");
    final PsiFile file = callback.getContext().getContainingFile();
    if (isApplicableTemplate(provider, key, file, editor, postfixTemplate)) {
      int offset = deleteTemplateKey(file, editor, key);
      try {
        provider.preExpand(file, editor);
        PsiElement context = CustomTemplateCallback.getContext(file, positiveOffset(offset));
        expandTemplate(postfixTemplate, editor, context);
      }
      finally {
        provider.afterExpand(file, editor);
      }
    }
    // don't care about errors in multiCaret mode
    else if (editor.getCaretModel().getAllCarets().size() == 1) {
      LOG.error("Template not found by key: " + key + "; offset = " + callback.getOffset(),
                CoreAttachmentFactory.createAttachment(callback.getFile().getVirtualFile()));
    }
  }
public static void expandTemplate(@NotNull String key,
                                    @NotNull CustomTemplateCallback callback,
                                    @NotNull Editor editor,
                                    @NotNull PostfixTemplateProvider provider,
                                    @NotNull PostfixTemplate postfixTemplate)