use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class AttributeContextInformationProvider method getInfoForElement.
/**
* @param node
*/
private IContextInformation[] getInfoForElement(IDOMNode node) {
IContextInformation[] results = EMPTY_CONTEXT_INFO;
CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) node);
if (decl != null) {
CMNamedNodeMap attributes = decl.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, decl, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
attributes = allAttributes;
String attrContextString = node.getNodeName();
// $NON-NLS-1$
StringBuffer attrInfo = new StringBuffer(" ");
// $NON-NLS-1$
String name = "";
HashMap attrPosMap = new HashMap();
int pos = 0;
int length = 0;
int numPerLine = 8;
CMAttributeDeclaration[] sortedAttrs = getSortedAttributes(attributes);
for (int i = 0; i < sortedAttrs.length; i++) {
name = sortedAttrs[i].getAttrName();
length = name.length();
pos = attrInfo.length();
attrInfo.append(name);
if (sortedAttrs[i].getUsage() == CMAttributeDeclaration.REQUIRED) {
// $NON-NLS-1$
attrInfo.append("*");
length++;
}
if (i < attributes.getLength() - 1) {
// $NON-NLS-1$
attrInfo.append(" ");
if ((i != 0) && (i % numPerLine == 0)) {
// $NON-NLS-1$
attrInfo.append("\n ");
}
}
attrPosMap.put(name, new Position(pos, length));
}
if (!attrInfo.toString().trim().equals("")) {
return new IContextInformation[] { new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap) };
}
}
return results;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class HTML5ContentModelTest method verifyAttributeDeclaration.
private void verifyAttributeDeclaration(CMElementDeclaration elemDecl, CMNode attr) {
assertTrue(attr.getNodeType() == CMNode.ATTRIBUTE_DECLARATION);
assertNotNull("no name on an attribute declaration", attr.getNodeName());
CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attr;
assertNotNull("no attribute 'type' on an attribute declaration " + elemDecl.getNodeName() + "/" + attr.getNodeName(), attrDecl.getAttrType());
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration 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.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class BaseAssociationProvider method getCMAttributeDeclaration.
public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr) {
CMAttributeDeclaration result = null;
Element element = attr.getOwnerElement();
if (element != null) {
CMElementDeclaration ed = getCMElementDeclaration(element);
if (ed != null) {
result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(attr.getName());
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method getInsertAttributeActions.
protected void getInsertAttributeActions(Element parent, CMElementDeclaration ed, int validityChecking, List actionList) {
// get actions for each insertable attribute
//
List availableAttributeList = modelQuery.getAvailableContent(parent, ed, ModelQuery.INCLUDE_ATTRIBUTES);
for (Iterator i = availableAttributeList.iterator(); i.hasNext(); ) {
CMAttributeDeclaration ad = (CMAttributeDeclaration) i.next();
if (modelQuery.canInsert(parent, ed, ad, 0, validityChecking)) {
Action action = new Action(ModelQueryAction.INSERT, parent, ad);
actionList.add(action);
}
}
}
Aggregations