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());
}
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);
}
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);
}
}
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);
}
}
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;
}
Aggregations