Search in sources :

Example 1 with CompleteSmartMacro

use of com.intellij.codeInsight.template.macro.CompleteSmartMacro in project intellij-community by JetBrains.

the class XmlTagInsertHandler method addRequiredSubTags.

private static boolean addRequiredSubTags(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context) {
    if (!WebEditorOptions.getInstance().isAutomaticallyInsertRequiredSubTags())
        return false;
    List<XmlElementDescriptor> requiredSubTags = GenerateXmlTagAction.getRequiredSubTags(descriptor);
    if (!requiredSubTags.isEmpty()) {
        template.addTextSegment(">");
        template.setToReformat(true);
    }
    for (XmlElementDescriptor subTag : requiredSubTags) {
        if (subTag == null) {
            // placeholder for smart completion
            template.addTextSegment("<");
            template.addVariable(new MacroCallNode(new CompleteSmartMacro()), true);
            continue;
        }
        String qname = subTag.getName();
        if (subTag instanceof XmlElementDescriptorImpl) {
            String prefixByNamespace = context.getPrefixByNamespace(((XmlElementDescriptorImpl) subTag).getNamespace());
            if (StringUtil.isNotEmpty(prefixByNamespace)) {
                qname = prefixByNamespace + ":" + subTag.getName();
            }
        }
        template.addTextSegment("<" + qname);
        addRequiredAttributes(subTag, null, template, file);
        completeTagTail(template, subTag, file, context, false);
    }
    if (!requiredSubTags.isEmpty()) {
        addTagEnd(template, descriptor, context);
    }
    return !requiredSubTags.isEmpty();
}
Also used : MacroCallNode(com.intellij.codeInsight.template.impl.MacroCallNode) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl) CompleteSmartMacro(com.intellij.codeInsight.template.macro.CompleteSmartMacro)

Aggregations

MacroCallNode (com.intellij.codeInsight.template.impl.MacroCallNode)1 CompleteSmartMacro (com.intellij.codeInsight.template.macro.CompleteSmartMacro)1 XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)1