public static void generateTag(@NotNull XmlTag newTag, Editor editor) { generateRaw(newTag); final XmlTag restored = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(newTag); if (restored == null) { LOG.error("Could not restore tag: " + newTag.getText()); } TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(restored); replaceElements(restored, builder); builder.run(editor, false); }
private static void replaceElements(XmlTag tag, TemplateBuilder builder) { for (XmlAttribute attribute : tag.getAttributes()) { XmlAttributeValue value = attribute.getValueElement(); if (value != null) { builder.replaceElement(value, TextRange.from(1, 0), new MacroCallNode(new CompleteMacro())); } } if ("<".equals(tag.getText())) { builder.replaceElement( tag, TextRange.from(1, 0), new MacroCallNode(new CompleteSmartMacro())); } else if (tag.getSubTags().length == 0) { int i = tag.getText().indexOf("></"); if (i > 0) { builder.replaceElement( tag, TextRange.from(i + 1, 0), new MacroCallNode(new CompleteMacro())); } } for (XmlTag subTag : tag.getSubTags()) { replaceElements(subTag, builder); } }