@Override
    public @NotNull ModTemplateBuilder templateBuilder() {
      if (!myTemplateFields.isEmpty()) {
        throw new IllegalStateException("Template was already created");
      }
      return new ModTemplateBuilder() {
        @Override
        public @NotNull ModTemplateBuilder field(@NotNull PsiElement element, @NotNull Expression expression) {
          return createField(element, null, expression);
        }

        @Override
        public @NotNull ModTemplateBuilder field(@NotNull PsiElement element, @NotNull String varName, @NotNull Expression expression) {
          return createField(element, varName, expression);
        }

        private @NotNull ModTemplateBuilder createField(@NotNull PsiElement element, @Nullable String varName, @NotNull Expression expression) {
          TextRange elementRange = getRange(element);
          if (elementRange == null) {
            throw new IllegalStateException("Unable to restore element for template");
          }
          TextRange range = mapRange(elementRange);
          Result result = expression.calculateResult(new DummyContext(range, element));
          myTemplateFields.add(new ModStartTemplate.ExpressionField(range, varName, expression));
          if (result != null) {
            myTracker.myDocument.replaceString(elementRange.getStartOffset(), elementRange.getEndOffset(), result.toString());
          }
          return this;
        }

        @Override
        public @NotNull ModTemplateBuilder field(@NotNull PsiElement element,
                                                 @NotNull String varName,
                                                 @NotNull String dependantVariableName,
                                                 boolean alwaysStopAt) {
          TextRange elementRange = getRange(element);
          if (elementRange == null) {
            throw new IllegalStateException("Unable to restore element for template");
          }
          TextRange range = mapRange(elementRange);
          myTemplateFields.add(new ModStartTemplate.DependantVariableField(range, varName, dependantVariableName, alwaysStopAt));
          return this;
        }

        @Override
        public @NotNull ModTemplateBuilder finishAt(int offset) {
          TextRange range = mapRange(TextRange.create(offset, offset));
          myTemplateFields.add(new ModStartTemplate.EndField(range));
          return this;
        }
      };
    }
@Override
    public @NotNull ModTemplateBuilder templateBuilder()