Search in sources :

Example 96 with CMElementDeclaration

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

the class HTML5ContentModelTest method checkAttrValues.

private void checkAttrValues(String documentKey, String elementName, String attrName, String[] attrValues) {
    CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey);
    CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
    assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
    assertNotNull("missing element declaration:" + elementName, elementDeclaration);
    CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
    final CMNode node = attributes.getNamedItem(attrName);
    assertNotNull("No attribute [" + attrName + "]", node);
    final String[] actualValues = ((HTMLAttributeDeclaration) node).getAttrType().getEnumeratedValues();
    assertEquals(attrValues.length, actualValues.length);
    Set valueSet = new HashSet(actualValues.length);
    for (int i = 0; i < actualValues.length; i++) {
        valueSet.add(actualValues[i]);
    }
    for (int i = 0; i < attrValues.length; i++) {
        if (!valueSet.remove(attrValues[i]))
            fail("Type did not contain attribute value [" + attrValues[i] + "]");
    }
    assertTrue("Type had unexpected attribute values", valueSet.isEmpty());
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Set(java.util.Set) HashSet(java.util.HashSet) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) HashSet(java.util.HashSet)

Example 97 with CMElementDeclaration

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

the class HTML5ContentModelTest method checkAttrNames.

/**
 * @param cm_doc_type
 * @param elementName
 * @param attrNameImport
 */
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
    CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey);
    CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
    assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
    assertNotNull("missing element declaration:" + elementName, elementDeclaration);
    CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
    for (int i = 0; i < attrNames.length; i++) {
        assertNotNull("missing attribute declaration:" + attrNames[i] + " for element: " + elementName, attributes.getNamedItem(attrNames[i]));
    }
    assertEquals("Attributes defined in content model that are not expected by the test for element: " + elementName, attributes.getLength(), attrNames.length);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 98 with CMElementDeclaration

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

the class HTMLTagInfoTest method checkAttributeTagInfo.

private void checkAttributeTagInfo(Element element, Attr attribute) {
    // check taginfo
    CMElementDeclaration elementDecl = getCMElementDeclaration(element);
    // $NON-NLS-1$
    assertNotNull("Cannot check taginfo because no element declaration for " + element.getNodeName(), elementDecl);
    if (elementDecl != null) {
        CMAttributeDeclaration attDecl = getCMAttributeDeclaration(elementDecl, attribute.getName());
        // $NON-NLS-1$
        assertNotNull("Cannot check taginfo because no attribute declaration for " + attribute.getName(), attDecl);
        // $NON-NLS-1$
        String tagInfo = (String) attDecl.getProperty("tagInfo");
        // $NON-NLS-1$
        assertNull("Unexpected taginfo found for " + attDecl.getNodeName(), tagInfo);
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 99 with CMElementDeclaration

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

the class HTMLTagInfoTest method checkElementTagInfo.

private void checkElementTagInfo(Element node) {
    // check taginfo
    CMElementDeclaration elementDecl = getCMElementDeclaration(node);
    // $NON-NLS-1$
    assertNotNull("Cannot check taginfo because no cm element declaration for " + node.getNodeName(), elementDecl);
    if (elementDecl != null) {
        // $NON-NLS-1$
        String tagInfo = (String) elementDecl.getProperty("tagInfo");
        // $NON-NLS-1$
        assertNotNull("No taginfo found for " + elementDecl.getNodeName(), tagInfo);
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)

Example 100 with CMElementDeclaration

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

the class HTMLTagInfoTest method getCMElementDeclaration.

/**
 * Retreives CMElementDeclaration for given node
 *
 * @return CMElementDeclaration - CMElementDeclaration of node or
 *         <code>null</code> if not possible
 */
private CMElementDeclaration getCMElementDeclaration(Element element) {
    CMElementDeclaration result = null;
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if (modelQuery != null)
        result = modelQuery.getCMElementDeclaration(element);
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Aggregations

CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)147 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)53 List (java.util.List)46 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)43 Element (org.w3c.dom.Element)41 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)38 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)37 ArrayList (java.util.ArrayList)35 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)33 Node (org.w3c.dom.Node)32 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)30 NodeList (org.w3c.dom.NodeList)28 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)24 Iterator (java.util.Iterator)19 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 Image (org.eclipse.swt.graphics.Image)15 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)15