use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class TestFixedCMDocuments 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 XMLLabelProvider method getText.
public String getText(Object o) {
StringBuffer text = new StringBuffer(super.getText(o));
if (o instanceof Node) {
Node node = (Node) o;
if ((node.getNodeType() == Node.ELEMENT_NODE) && fShowAttributes) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444
if (node.hasAttributes()) {
Element element = (Element) node;
NamedNodeMap attributes = element.getAttributes();
Node idTypedAttribute = null;
Node requiredAttribute = null;
boolean hasId = false;
boolean hasName = false;
Node shownAttribute = null;
// try to get content model element
// declaration
CMElementDeclaration elementDecl = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if (mq != null) {
elementDecl = mq.getCMElementDeclaration(element);
}
// ID
if (elementDecl != null) {
int i = 0;
while ((i < attributes.getLength()) && (idTypedAttribute == null)) {
Node attr = attributes.item(i);
String attrName = attr.getNodeName();
CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) elementDecl.getAttributes().getNamedItem(attrName);
if (attrDecl != null) {
if ((attrDecl.getAttrType() != null) && (CMDataType.ID.equals(attrDecl.getAttrType().getDataTypeName()))) {
idTypedAttribute = attr;
} else if ((attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) && (requiredAttribute == null)) {
// as a backup, keep tabs on
// any required
// attributes
requiredAttribute = attr;
} else {
// $NON-NLS-1$
hasId = hasId || attrName.equals("id");
// $NON-NLS-1$
hasName = hasName || attrName.equals("name");
}
}
++i;
}
}
/*
* If no suitable attribute was found, try using a
* required attribute, if none, then prefer "id" or
* "name", otherwise just use first attribute
*/
if (idTypedAttribute != null) {
shownAttribute = idTypedAttribute;
} else if (requiredAttribute != null) {
shownAttribute = requiredAttribute;
} else if (hasId) {
// $NON-NLS-1$
shownAttribute = attributes.getNamedItem("id");
} else if (hasName) {
// $NON-NLS-1$
shownAttribute = attributes.getNamedItem("name");
}
if (shownAttribute == null) {
shownAttribute = attributes.item(0);
}
// display the attribute and value (without quotes)
String attributeName = shownAttribute.getNodeName();
if ((attributeName != null) && (attributeName.length() > 0)) {
// $NON-NLS-1$
text.append(" " + attributeName);
String attributeValue = shownAttribute.getNodeValue();
if ((attributeValue != null) && (attributeValue.length() > 0)) {
// $NON-NLS-1$
text.append("=" + StringUtils.strip(attributeValue));
}
}
}
}
}
return text.toString();
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class MarkupTagInfoProvider method printDefaultInfo.
/**
* Adds the default info (element name, content model, data type) of
* CMNode to the string buffer, sb
*/
protected void printDefaultInfo(CMNode node, StringBuffer sb) {
{
if (node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
CMElementDeclaration ed = (CMElementDeclaration) node;
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Element____1 + SPACE + BOLD_END);
sb.append(node.getNodeName());
sb.append(PARAGRAPH_END);
printDocumentation(sb, node);
if (ed.getContentType() == CMElementDeclaration.PCDATA) {
CMDataType dataType = ed.getDataType();
if (dataType != null) {
printDataTypeInfo(sb, dataType);
}
} else {
CMDescriptionBuilder builder = new CMDescriptionBuilder();
String description = builder.buildDescription(node);
if ((description != null) && (description.length() > 0)) {
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Content_Model____2 + SPACE + BOLD_END);
sb.append(description + PARAGRAPH_END);
}
}
} else if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
CMAttributeDeclaration ad = (CMAttributeDeclaration) node;
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Attribute____3 + SPACE + BOLD_END);
sb.append(node.getNodeName());
sb.append(PARAGRAPH_END);
printDocumentation(sb, node);
CMDataType dataType = ad.getAttrType();
if (dataType != null) {
printDataTypeInfo(sb, dataType);
}
} else if (node.getNodeType() == CMNode.DATA_TYPE) {
sb.append(PARAGRAPH_START + BOLD_START + XMLUIMessages.Data_Type____4 + SPACE + BOLD_END);
sb.append(node.getNodeName());
sb.append(PARAGRAPH_END);
printDocumentation(sb, node);
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XMLTagInfoHoverProcessor method computeTagAttNameHelp.
/**
* Computes the hover help for the attribute name
*/
protected String computeTagAttNameHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) {
CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode);
String attName = flatNode.getText(region);
CMAttributeDeclaration attDecl = getCMAttributeDeclaration(xmlnode, elementDecl, attName);
return getAdditionalInfo(elementDecl, attDecl);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XMLTagInfoHoverProcessor method computeTagAttValueHelp.
/**
* Computes the hover help for the attribute value (this is the same as
* the attribute name's help)
*/
protected String computeTagAttValueHelp(IDOMNode xmlnode, IDOMNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) {
CMElementDeclaration elementDecl = getCMElementDeclaration(xmlnode);
ITextRegion attrNameRegion = getAttrNameRegion(xmlnode, region);
String attName = flatNode.getText(attrNameRegion);
CMAttributeDeclaration attDecl = getCMAttributeDeclaration(xmlnode, elementDecl, attName);
return getAdditionalInfo(elementDecl, attDecl);
}
Aggregations