public static void runNonInteractively(PsiFile file, Document document, Template template, RangeMarker containerElement) {
    TemplateState state = new TemplateState(file.getProject(), null, document, new NonInteractiveTemplateStateProcessor());

    //noinspection unchecked
    state.getProperties().put(ExpressionContext.SELECTION, null);

    Runnable r = () -> {
      state.start((TemplateImpl) template, null, null, containerElement.getStartOffset());
      while (!state.isFinished()) {
        state.nextTab();
      }
    };
    CommandProcessor.getInstance().executeCommand(file.getProject(),
                                                  r,
                                                  AnalysisBundle.message("insert.code.template.command"),
                                                  null);
  }
public static void runNonInteractively(PsiFile file, Document document, Template template, RangeMarker containerElement)