Element (@NotNull TemplateImpl template, @Nullable TemplateImpl defaultTemplate, @NotNull Lazy<Map<String, TemplateContextType>> idToType) { Element element = new Element(TEMPLATE); final String id = template.getId(); if (id != null) { element.setAttribute(ID, id); } element.setAttribute(NAME, template.getKey()); element.setAttribute(VALUE, template.getString()); if (template.getShortcutChar() == TAB_CHAR) { element.setAttribute(SHORTCUT, TAB); } else if (template.getShortcutChar() == ENTER_CHAR) { element.setAttribute(SHORTCUT, ENTER); } else if (template.getShortcutChar() == SPACE_CHAR) { element.setAttribute(SHORTCUT, SPACE); } else if (template.getShortcutChar() == NONE_CHAR) { element.setAttribute(SHORTCUT, NONE); } if (template.getDescription() != null) { element.setAttribute(DESCRIPTION, template.getDescription()); } element.setAttribute(TO_REFORMAT, Boolean.toString(template.isToReformat())); element.setAttribute(TO_SHORTEN_FQ_NAMES, Boolean.toString(template.isToShortenLongNames())); if (template.getValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE) != Template.getDefaultValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE)) { element.setAttribute(USE_STATIC_IMPORT, Boolean.toString(template.getValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE))); } if (template.isDeactivated()) { element.setAttribute(DEACTIVATED, Boolean.toString(true)); } for (int i = 0; i < template.getVariableCount(); i++) { Element variableElement = new Element(VARIABLE); variableElement.setAttribute(NAME, template.getVariableNameAt(i)); variableElement.setAttribute(EXPRESSION, template.getExpressionStringAt(i)); variableElement.setAttribute(DEFAULT_VALUE, template.getDefaultValueStringAt(i)); variableElement.setAttribute(ALWAYS_STOP_AT, Boolean.toString(template.isAlwaysStopAt(i))); element.addContent(variableElement); } Element contextElement = template.getTemplateContext().writeTemplateContext(defaultTemplate == null ? null : defaultTemplate.getTemplateContext(), idToType); if (contextElement != null) { element.addContent(contextElement); } return element; }