Search in sources :

Example 16 with XmlTag

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

the class XmlConstraintsTest method testXercesForCompletion.

public void testXercesForCompletion() throws Exception {
    XSModel xsModel = getXSModel("testCompletion.xml", "test.xsd");
    PsiElement element = myFixture.getFile().findElementAt(getEditor().getCaretModel().getOffset());
    XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
    assert tag != null;
    XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration(tag.getLocalName(), tag.getNamespace());
    XSComplexTypeDefinition typeDefinition = (XSComplexTypeDefinition) elementDeclaration.getTypeDefinition();
    CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
    XSCMValidator validator = cmBuilder.getContentModel((XSComplexTypeDecl) typeDefinition, true);
    int[] ints = validator.startContentModel();
    Vector vector = validator.whatCanGoHere(ints);
    XSElementDecl o = (XSElementDecl) vector.get(0);
    assertEquals("b", o.getName());
}
Also used : CMBuilder(org.apache.xerces.impl.xs.models.CMBuilder) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) XSModel(org.apache.xerces.xs.XSModel) CMNodeFactory(org.apache.xerces.impl.xs.models.CMNodeFactory) XSElementDecl(org.apache.xerces.impl.xs.XSElementDecl) XSCMValidator(org.apache.xerces.impl.xs.models.XSCMValidator) Vector(java.util.Vector) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) XSComplexTypeDefinition(org.apache.xerces.xs.XSComplexTypeDefinition)

Example 17 with XmlTag

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

the class DomAnchorImpl method diagnoseNegativeIndex2.

private static <T extends DomElement> void diagnoseNegativeIndex2(T t, DomElement parent, AbstractDomChildrenDescription description, List<? extends DomElement> values) {
    final XmlTag parentTag = parent.getXmlTag();
    StringBuilder diag = new StringBuilder("Index<0: description=" + description + "\nparent=" + parent + "\nt=" + t + "\nvalues=" + values + "\n");
    for (int i = 0, size = values.size(); i < size; i++) {
        DomElement value = values.get(i);
        if (value.toString().equals(t.toString())) {
            final XmlElement tElement = t.getXmlElement();
            final XmlElement valElement = value.getXmlElement();
            diag.append(" hasSame, i=" + i + "; same=" + (value == t) + ", equal=" + value.equals(t) + ", equal2=" + t.equals(value) + ", t.physical=" + (tElement == null ? "null" : String.valueOf(tElement.isPhysical())) + ", value.physical=" + (valElement == null ? "null" : String.valueOf(valElement.isPhysical())) + ", sameElements=" + (tElement == value.getXmlElement()) + "\n");
            if (tElement != null && valElement != null) {
                diag.append("  sameFile=" + (tElement.getContainingFile() == valElement.getContainingFile()) + ", sameParent=" + (tElement.getParent() == valElement.getParent()) + "\n");
            }
        }
    }
    if (parentTag != null) {
        diag.append("Parent tag: ").append(parentTag.getName()).append("\n");
        if (t instanceof GenericAttributeValue) {
            for (XmlAttribute attribute : parentTag.getAttributes()) {
                diag.append(", attr: ").append(attribute.getName());
            }
            diag.append("\n");
        } else {
            for (XmlTag tag : parentTag.getSubTags()) {
                diag.append("\n subtag: ").append(tag.getName());
            }
            diag.append("\n");
        }
    }
    diag.append("Child name: ").append(t.getXmlElementName()).append(";").append(t.getXmlElementNamespaceKey());
    LOG.error(diag);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlElement(com.intellij.psi.xml.XmlElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 18 with XmlTag

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

the class DomDescriptorProvider method getDescriptor.

@Override
@Nullable
public XmlElementDescriptor getDescriptor(final XmlTag tag) {
    Project project = tag.getProject();
    if (project.isDefault())
        return null;
    final DomInvocationHandler<?, ?> handler = DomManagerImpl.getDomManager(project).getDomHandler(tag);
    if (handler != null) {
        final DefinesXml definesXml = handler.getAnnotation(DefinesXml.class);
        if (definesXml != null) {
            return new DomElementXmlDescriptor(handler);
        }
        final PsiElement parent = tag.getParent();
        if (parent instanceof XmlTag) {
            final XmlElementDescriptor descriptor = ((XmlTag) parent).getDescriptor();
            if (descriptor instanceof DomElementXmlDescriptor) {
                return descriptor.getElementDescriptor(tag, (XmlTag) parent);
            }
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) DomElementXmlDescriptor(com.intellij.xml.impl.dom.DomElementXmlDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) DefinesXml(com.intellij.util.xml.DefinesXml) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with XmlTag

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

the class DomImplUtil method getFile.

static XmlFile getFile(DomElement domElement) {
    if (domElement instanceof DomFileElement) {
        return ((DomFileElement) domElement).getFile();
    }
    DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(domElement);
    assert handler != null : domElement;
    while (true) {
        if (handler instanceof DomRootInvocationHandler) {
            return ((DomRootInvocationHandler) handler).getParent().getFile();
        }
        XmlTag tag = handler.getXmlTag();
        if (tag != null) {
            return getContainingFile(tag);
        }
        DomInvocationHandler parent = handler.getParentHandler();
        if (parent == null) {
            throw new AssertionError("No parent for " + handler.toStringEx());
        }
        handler = parent;
    }
}
Also used : XmlTag(com.intellij.psi.xml.XmlTag)

Example 20 with XmlTag

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

the class DomImplUtil method getContainingFile.

private static XmlFile getContainingFile(XmlTag tag) {
    while (true) {
        final PsiElement parentTag = PhysicalDomParentStrategy.getParentTagCandidate(tag);
        if (!(parentTag instanceof XmlTag)) {
            return (XmlFile) tag.getContainingFile();
        }
        tag = (XmlTag) parentTag;
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiElement(com.intellij.psi.PsiElement) 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