Search in sources :

Example 26 with XmlTag

use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.

the class DomInvocationHandler method getCollectionChildren.

public List<? extends DomElement> getCollectionChildren(final AbstractCollectionChildDescription description) {
    if (myStub != null && description.isStubbed()) {
        if (description instanceof DomChildDescriptionImpl) {
            XmlName xmlName = ((DomChildDescriptionImpl) description).getXmlName();
            List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
            return ContainerUtil.map(stubs, stub -> stub.getOrCreateHandler((DomChildDescriptionImpl) description, myManager).getProxy());
        } else if (description instanceof CustomDomChildrenDescriptionImpl) {
            List<DomStub> stubs = myStub.getChildrenStubs();
            return ContainerUtil.mapNotNull(stubs, (NullableFunction<DomStub, DomElement>) stub -> {
                if (stub instanceof ElementStub && stub.isCustom()) {
                    EvaluatedXmlName name = new DummyEvaluatedXmlName(stub.getName(), "");
                    return new CollectionElementInvocationHandler(name, (CustomDomChildrenDescriptionImpl) description, myManager, (ElementStub) stub).getProxy();
                }
                return null;
            });
        }
    }
    XmlTag tag = getXmlTag();
    if (tag == null)
        return Collections.emptyList();
    final List<XmlTag> subTags = getCollectionSubTags(description, tag);
    if (subTags.isEmpty())
        return Collections.emptyList();
    List<DomElement> elements = new ArrayList<>(subTags.size());
    for (XmlTag subTag : subTags) {
        final SemKey<? extends DomInvocationHandler> key = description instanceof CustomDomChildrenDescription ? DomManagerImpl.DOM_CUSTOM_HANDLER_KEY : DomManagerImpl.DOM_COLLECTION_HANDLER_KEY;
        final DomInvocationHandler semElement = myManager.getSemService().getSemElement(key, subTag);
        if (semElement == null) {
            String msg = "No child for subTag '" + subTag.getName() + "' in tag '" + tag.getName() + "' using key " + key + "; subtag count=" + subTags.size();
            DomInvocationHandler anyDom = myManager.getDomHandler(subTag);
            if (anyDom != null) {
                msg += "\n sub-dom=" + anyDom + " with " + anyDom.getChildDescription();
            }
            throw new AssertionError(msg);
        } else {
            elements.add(semElement.getProxy());
        }
    }
    return Collections.unmodifiableList(elements);
}
Also used : ArrayList(java.util.ArrayList) DomStub(com.intellij.util.xml.stubs.DomStub) ArrayList(java.util.ArrayList) List(java.util.List) ElementStub(com.intellij.util.xml.stubs.ElementStub) XmlTag(com.intellij.psi.xml.XmlTag)

Example 27 with XmlTag

use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.

the class DomInvocationHandler method getAttributeChild.

@NotNull
final AttributeChildInvocationHandler getAttributeChild(final AttributeChildDescriptionImpl description) {
    final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(description.getXmlName());
    if (myStub != null && description.isStubbed()) {
        AttributeStub stub = myStub.getAttributeStub(description.getXmlName());
        StubParentStrategy strategy = StubParentStrategy.createAttributeStrategy(stub, myStub);
        return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, strategy, stub);
    }
    final XmlTag tag = getXmlTag();
    if (tag != null) {
        // TODO: this seems ugly
        String ns = evaluatedXmlName.getNamespace(tag, getFile());
        final XmlAttribute attribute = tag.getAttribute(description.getXmlName().getLocalName(), ns.equals(tag.getNamespace()) ? null : ns);
        if (attribute != null) {
            PsiUtilCore.ensureValid(attribute);
            AttributeChildInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
            if (semElement == null) {
                final AttributeChildInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
                throw new AssertionError("No DOM at XML. Parent=" + tag + "; attribute=" + attribute + "; second attempt=" + take2);
            }
            return semElement;
        }
    }
    return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, new VirtualDomParentStrategy(this), null);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AttributeStub(com.intellij.util.xml.stubs.AttributeStub) StubParentStrategy(com.intellij.util.xml.stubs.StubParentStrategy) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with XmlTag

use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.

the class DomRootInvocationHandler method checkValidity.

@Override
protected String checkValidity() {
    final XmlTag tag = (XmlTag) getXmlElement();
    if (tag != null && !tag.isValid()) {
        return "invalid root tag";
    }
    final String s = myParent.checkValidity();
    if (s != null) {
        return "root: " + s;
    }
    return null;
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag)

Example 29 with XmlTag

use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.

the class DomRootInvocationHandler method setEmptyXmlTag.

@Override
protected XmlTag setEmptyXmlTag() {
    final XmlTag[] result = new XmlTag[] { null };
    getManager().runChange(() -> {
        try {
            final String namespace = getXmlElementNamespace();
            @NonNls final String nsDecl = StringUtil.isEmpty(namespace) ? "" : " xmlns=\"" + namespace + "\"";
            final XmlFile xmlFile = getFile();
            final XmlTag tag = XmlElementFactory.getInstance(xmlFile.getProject()).createTagFromText("<" + getXmlElementName() + nsDecl + "/>");
            result[0] = ((XmlDocument) xmlFile.getDocument().replace(((XmlFile) tag.getContainingFile()).getDocument())).getRootTag();
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    });
    return result[0];
}
Also used : NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlTag(com.intellij.psi.xml.XmlTag)

Example 30 with XmlTag

use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.

the class DomRootInvocationHandler method undefineInternal.

@Override
public void undefineInternal() {
    try {
        final XmlTag tag = getXmlTag();
        if (tag != null) {
            deleteTag(tag);
            detach();
            fireUndefinedEvent();
        }
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlTag (com.intellij.psi.xml.XmlTag)673 XmlFile (com.intellij.psi.xml.XmlFile)151 PsiElement (com.intellij.psi.PsiElement)130 XmlAttribute (com.intellij.psi.xml.XmlAttribute)121 Nullable (org.jetbrains.annotations.Nullable)99 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)89 NotNull (org.jetbrains.annotations.NotNull)89 PsiFile (com.intellij.psi.PsiFile)71 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)52 VirtualFile (com.intellij.openapi.vfs.VirtualFile)50 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)50 Project (com.intellij.openapi.project.Project)48 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)47 ArrayList (java.util.ArrayList)43 XmlDocument (com.intellij.psi.xml.XmlDocument)39 DomElement (com.intellij.util.xml.DomElement)35 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 TextRange (com.intellij.openapi.util.TextRange)32 Result (com.intellij.openapi.application.Result)24 Document (com.intellij.openapi.editor.Document)24