private void processAllExpressions(final @NotNull TemplateImpl template) {
    Runnable action = () -> {
      if (!template.isInline()) getDocument().insertString(myTemplateRange.getStartOffset(), template.getTemplateText());
      for (int i = 0; i < template.getSegmentsCount(); i++) {
        int segmentOffset = myTemplateRange.getStartOffset() + template.getSegmentOffset(i);
        getSegments().addSegment(segmentOffset, segmentOffset);
      }

      LOG.assertTrue(myTemplateRange.isValid(), getRangesDebugInfo());
      calcResults(false);
      LOG.assertTrue(myTemplateRange.isValid(), getRangesDebugInfo());
      calcResults(false);  //Fixed SCR #[vk500] : all variables should be recalced twice on start.
      LOG.assertTrue(myTemplateRange.isValid(), getRangesDebugInfo());
      doReformat();

      int nextVariableNumber = getNextVariableNumber(-1);

      if (nextVariableNumber >= 0) {
        fireWaitingForInput();
      }

      if (nextVariableNumber == -1) {
        if (requiresWriteAction()) {
          myEventPublisher.templateStarted(this);
        }

        finishTemplate(false);
      }
      else {
        setCurrentVariableNumber(nextVariableNumber);
        if (isInteractiveModeSupported()) {
          initTabStopHighlighters();
          initListeners();
        }
        if (requiresWriteAction()) {
          myEventPublisher.templateStarted(this);
        }

        focusCurrentExpression();
        fireCurrentVariableChanged(-1);

        if (!isInteractiveModeSupported()) {
          finishTemplate(false);
        }
      }
    };
    performWrite(action);
  }
private void processAllExpressions(final @NotNull TemplateImpl template)