Search in sources :

Example 16 with CMNodeList

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.

the class AttributeContextInformationProvider method getInfoForText.

/**
 * @param node
 */
IContextInformation[] getInfoForText(IDOMNode node) {
    Node parent = node.getParentNode();
    String contextString = node.getNodeName();
    // $NON-NLS-1$
    StringBuffer info = new StringBuffer(" ");
    if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
        CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) parent);
        CMContent content = decl.getContent();
        if (content instanceof CMGroup) {
            CMGroup cmGroup = (CMGroup) content;
            CMNodeList children = cmGroup.getChildNodes();
            CMNode cmNode = null;
            for (int i = 0; i < children.getLength(); i++) {
                cmNode = children.item(i);
                contextString = cmNode.getNodeName();
                if (contextString != null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    info.append("<" + cmNode.getNodeName() + ">");
                    if (i < children.getLength() - 1) {
                        // $NON-NLS-1$
                        info.append(" ");
                    }
                }
            }
        }
    }
    if (!info.toString().trim().equals("")) {
        return new IContextInformation[] { new ContextInformation(contextString, info.toString()) };
    } else {
        return EMPTY_CONTEXT_INFO;
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 17 with CMNodeList

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.

the class DOMContentBuilderImpl method visitCMGroup.

public void visitCMGroup(CMGroup e) {
    cmGroupStack.push(e);
    int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
    int min = Math.max(e.getMinOccur(), forcedMin);
    int max = 0;
    if (// unbounded
    e.getMaxOccur() == -1)
        max = getNumOfRepeatableElements();
    else
        max = Math.min(e.getMaxOccur(), getNumOfRepeatableElements());
    if (max < min)
        max = min;
    alwaysVisit = false;
    for (int i = 1; i <= max; i++) {
        if (e.getOperator() == CMGroup.CHOICE && buildFirstChoice(buildPolicy)) {
            CMNode hintNode = null;
            // todo... the CMGroup should specify the hint... but it seems
            // as though
            // the Yamato guys are making the CMElement specify the hint.
            // I do it that way for now until... we should fix this post
            // GA
            // 
            int listSize = visitedCMElementDeclarationList.size();
            if (listSize > 0) {
                CMElementDeclaration ed = (CMElementDeclaration) visitedCMElementDeclarationList.get(listSize - 1);
                // $NON-NLS-1$
                Object contentHint = ed.getProperty("contentHint");
                if (contentHint instanceof CMNode) {
                    hintNode = (CMNode) contentHint;
                }
            }
            // see if this hint corresponds to a valid choice
            // 
            CMNode cmNode = null;
            if (hintNode != null) {
                CMNodeList nodeList = e.getChildNodes();
                int nodeListLength = nodeList.getLength();
                for (int j = 0; j < nodeListLength; j++) {
                    if (hintNode == nodeList.item(j)) {
                        cmNode = hintNode;
                    }
                }
            }
            // 
            if (cmNode == null) {
                CMNodeList nodeList = e.getChildNodes();
                if (nodeList.getLength() > 0) {
                    cmNode = nodeList.item(0);
                }
            }
            if (cmNode != null) {
                // Visit the node only if it is not a GROUP (model group). If it is an element, then visit it.
                if (!(cmNode.getNodeType() == CMNode.GROUP && min > 0)) {
                    visitCMNode(cmNode);
                }
            }
        } else if (// ALL
        e.getOperator() == CMGroup.ALL || // SEQUENCE
        e.getOperator() == CMGroup.SEQUENCE) {
            // visit all of the content
            super.visitCMGroup(e);
        }
    }
    cmGroupStack.pop();
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 18 with CMNodeList

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.

the class DOMContentBuilderImpl method getSubstitution.

protected CMElementDeclaration getSubstitution(CMElementDeclaration ed) {
    CMElementDeclaration result = ed;
    // $NON-NLS-1$
    CMNodeList l = (CMNodeList) ed.getProperty("SubstitutionGroup");
    if (l != null) {
        for (int i = 0; i < l.getLength(); i++) {
            CMNode candidate = l.item(i);
            if (!isAbstract(candidate) && (candidate instanceof CMElementDeclaration)) {
                result = (CMElementDeclaration) candidate;
                break;
            }
        }
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 19 with CMNodeList

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.

the class BugFixesTest method testGlobalAttr4Documentation.

private void testGlobalAttr4Documentation(CMNamedNodeMap attributes) {
    CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("globalAttr4");
    assertNotNull("Missing globalAttr1 attribute.");
    CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
    if (documentation.getLength() == 0) {
        fail("Documentation element not returned for globalAttr4");
    }
    assertNull("globalAttr4 returned data when non expected.", ((DocumentationImpl) documentation.item(0)).getValue());
}
Also used : CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 20 with CMNodeList

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.

the class BugFixesTest method testLocalAttrDocumentation.

private void testLocalAttrDocumentation(CMNamedNodeMap attributes) {
    CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("localAttr");
    assertNotNull("Missing localAttr attribute.");
    CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
    if (documentation.getLength() == 0) {
        fail("Unable to find documentation for localAttr");
    }
    assertEquals("Wrong number of documentation annotations.", 2, documentation.getLength());
    assertEquals("Incorrect annotation for localAttr:", "PASS! Multiple documentation elements for local attribute part 1", ((DocumentationImpl) documentation.item(0)).getValue().trim());
    assertEquals("Incorrect annotation for localAttr:", "PASS! Multiple documentation elements for local attribute part 2", ((DocumentationImpl) documentation.item(1)).getValue().trim());
}
Also used : CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) DocumentationImpl(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.DocumentationImpl) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Aggregations

CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)23 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)9 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)8 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)5 CMGroup (org.eclipse.wst.xml.core.internal.contentmodel.CMGroup)5 DocumentationImpl (org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.DocumentationImpl)5 CMContent (org.eclipse.wst.xml.core.internal.contentmodel.CMContent)4 Node (org.w3c.dom.Node)3 URL (java.net.URL)2 List (java.util.List)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)1 CMDocumentation (org.eclipse.wst.xml.core.internal.contentmodel.CMDocumentation)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1