Search in sources :

Example 11 with CMAttributeDeclaration

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());
}
Also used : CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 12 with CMAttributeDeclaration

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();
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 13 with CMAttributeDeclaration

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);
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMDescriptionBuilder(org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder)

Example 14 with CMAttributeDeclaration

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);
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 15 with CMAttributeDeclaration

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);
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Aggregations

CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)57 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)29 List (java.util.List)24 ArrayList (java.util.ArrayList)18 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)14 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)13 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)12 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)12 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)11 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)11 Attr (org.w3c.dom.Attr)11 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)10 Element (org.w3c.dom.Element)10 Iterator (java.util.Iterator)9 NodeList (org.w3c.dom.NodeList)8 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)7 HashMap (java.util.HashMap)4