ModTemplateBuilder (@NotNull PsiElement element, @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, expression)); if (result != null) { myTracker.myPositionDocument.replaceString(range.getStartOffset(), range.getEndOffset(), result.toString()); } return this; }