Search in sources :

Example 1 with CMNodeFactory

use of org.apache.xerces.impl.xs.models.CMNodeFactory in project intellij-community by JetBrains.

the class XmlConstraintsTest method testXercesGrammar.

public void testXercesGrammar() throws Exception {
    XSModel xsModel = getXSModel("test.xml", "test.xsd");
    XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration("a", "");
    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) XSComplexTypeDefinition(org.apache.xerces.xs.XSComplexTypeDefinition)

Example 2 with CMNodeFactory

use of org.apache.xerces.impl.xs.models.CMNodeFactory 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 3 with CMNodeFactory

use of org.apache.xerces.impl.xs.models.CMNodeFactory in project intellij-community by JetBrains.

the class XsContentDFA method getElementDeclaration.

@Nullable
private static XSElementDeclaration getElementDeclaration(XmlTag tag, XSModel xsModel) {
    List<XmlTag> ancestors = new ArrayList<>();
    for (XmlTag t = tag; t != null; t = t.getParentTag()) {
        ancestors.add(t);
    }
    Collections.reverse(ancestors);
    XSElementDeclaration declaration = null;
    SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(new MyXSElementDeclHelper());
    CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
    for (XmlTag ancestor : ancestors) {
        if (declaration == null) {
            declaration = xsModel.getElementDeclaration(ancestor.getLocalName(), ancestor.getNamespace());
            if (declaration == null)
                return null;
            else
                continue;
        }
        XSTypeDefinition typeDefinition = declaration.getTypeDefinition();
        if (!(typeDefinition instanceof XSComplexTypeDecl)) {
            return null;
        }
        XSCMValidator model = ((XSComplexTypeDecl) typeDefinition).getContentModel(cmBuilder);
        int[] ints = model.startContentModel();
        for (XmlTag subTag : ancestor.getParentTag().getSubTags()) {
            QName qName = createQName(subTag);
            Object o = model.oneTransition(qName, ints, fSubGroupHandler);
            if (subTag == ancestor) {
                if (o instanceof XSElementDecl) {
                    declaration = (XSElementDecl) o;
                    break;
                } else
                    return null;
            }
        }
    }
    return declaration;
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) QName(org.apache.xerces.xni.QName) ArrayList(java.util.ArrayList) CMNodeFactory(org.apache.xerces.impl.xs.models.CMNodeFactory) XSCMValidator(org.apache.xerces.impl.xs.models.XSCMValidator) CMBuilder(org.apache.xerces.impl.xs.models.CMBuilder) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with CMNodeFactory

use of org.apache.xerces.impl.xs.models.CMNodeFactory in project intellij-community by JetBrains.

the class XmlConstraintsTest method testXercesIncomplete.

public void testXercesIncomplete() throws Exception {
    XSModel xsModel = getXSModel("testIncomplete.xml", "test.xsd");
    XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration("a", "");
    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) XSComplexTypeDefinition(org.apache.xerces.xs.XSComplexTypeDefinition)

Aggregations

CMBuilder (org.apache.xerces.impl.xs.models.CMBuilder)4 CMNodeFactory (org.apache.xerces.impl.xs.models.CMNodeFactory)4 XSCMValidator (org.apache.xerces.impl.xs.models.XSCMValidator)4 XSElementDeclaration (org.apache.xerces.xs.XSElementDeclaration)4 Vector (java.util.Vector)3 XSElementDecl (org.apache.xerces.impl.xs.XSElementDecl)3 XSComplexTypeDefinition (org.apache.xerces.xs.XSComplexTypeDefinition)3 XSModel (org.apache.xerces.xs.XSModel)3 XmlTag (com.intellij.psi.xml.XmlTag)2 PsiElement (com.intellij.psi.PsiElement)1 ArrayList (java.util.ArrayList)1 QName (org.apache.xerces.xni.QName)1 XSTypeDefinition (org.apache.xerces.xs.XSTypeDefinition)1 Nullable (org.jetbrains.annotations.Nullable)1