Search in sources :

Example 36 with CMAttributeDeclaration

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;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 37 with CMAttributeDeclaration

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

Example 38 with CMAttributeDeclaration

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

Example 39 with CMAttributeDeclaration

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

Example 40 with CMAttributeDeclaration

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);
        }
    }
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) NodeList(org.w3c.dom.NodeList) List(java.util.List) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) 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