Search in sources :

Example 6 with XmlElementDescriptorImpl

use of com.intellij.xml.impl.schema.XmlElementDescriptorImpl 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

XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)6 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 XmlTag (com.intellij.psi.xml.XmlTag)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)2 MacroCallNode (com.intellij.codeInsight.template.impl.MacroCallNode)1 CompleteSmartMacro (com.intellij.codeInsight.template.macro.CompleteSmartMacro)1 RelaxedHtmlFromSchemaElementDescriptor (com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor)1 PsiElement (com.intellij.psi.PsiElement)1 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)1 XmlExtension (com.intellij.xml.XmlExtension)1 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)1 ComplexTypeDescriptor (com.intellij.xml.impl.schema.ComplexTypeDescriptor)1 TypeDescriptor (com.intellij.xml.impl.schema.TypeDescriptor)1 QName (javax.xml.namespace.QName)1 Nullable (org.jetbrains.annotations.Nullable)1