Search in sources :

Example 1 with ModelQueryAction

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method getAvailableChildElementDeclarations.

/**
 * returns a list of CMNodes that are available within this parent context
 * Given the grammar shown below and a snippet of XML code (where the '|'
 * indicated the cursor position)
 * the list would return all of the element declarations that are
 * potential child elements of Foo.
 *
 * grammar : Foo -> (A, B, C)
 * snippet : <Foo><A>|
 * result : {A, B, C}
 *
 * TODO cs... do we need to pass in the 'kindOfAction'? Seems to me we
 * could assume it's always an insert.
 *
 * @param parent
 * @param childPosition
 * @param kindOfAction
 * @return
 */
private List getAvailableChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
    List modelQueryActions = getAvailableModelQueryActionsAtIndex(parent, childPosition, ModelQuery.VALIDITY_NONE);
    Iterator iterator = modelQueryActions.iterator();
    List cmnodes = new Vector();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
            CMNode actionCMNode = action.getCMNode();
            if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
                cmnodes.add(actionCMNode);
            }
        }
    }
    return cmnodes;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Example 2 with ModelQueryAction

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method getValidChildElementDeclarations.

/**
 * returns a list of CMNodes that can be validly inserted at this
 * childPosition
 * Given the grammar shown below and a snippet of XML code (where the '|'
 * indicated the cursor position)
 * the list would return only the element declarations can be inserted
 * while maintaing validity of the content.
 *
 * grammar : Foo -> (A, B, C)
 * snippet : <Foo><A>|
 * result : {B}
 *
 * @param parent
 * @param childPosition
 * @param kindOfAction
 * @return
 */
private List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
    List modelQueryActions = getAvailableModelQueryActionsAtIndex(parent, childPosition, ModelQuery.VALIDITY_STRICT);
    Iterator iterator = modelQueryActions.iterator();
    List cmnodes = new Vector();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
            CMNode actionCMNode = action.getCMNode();
            if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
                cmnodes.add(actionCMNode);
            }
        }
    }
    return cmnodes;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Example 3 with ModelQueryAction

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction in project webtools.sourceediting by eclipse.

the class CMValidatorValidationTest method verify.

private void verify(Element parentElement, String[] childElementsAvailable) {
    List list = new ArrayList();
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parentElement.getOwnerDocument());
    CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(parentElement);
    modelQuery.getInsertActions(parentElement, cmElementDeclaration, -1, ModelQuery.INCLUDE_CHILD_NODES, ModelQuery.VALIDITY_STRICT, list);
    assertEquals(childElementsAvailable.length, list.size());
    List availableNodeNameList = new ArrayList();
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        availableNodeNameList.add(((ModelQueryAction) iterator.next()).getCMNode().getNodeName());
    }
    for (int i = 0; i < childElementsAvailable.length; i++) {
        if (availableNodeNameList.indexOf(childElementsAvailable[i]) == -1) {
            fail();
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 4 with ModelQueryAction

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method getValidChildElementDeclarations.

// returns a list of CMNodes that can be validly inserted at this
// childPosition
// Given the grammar shown below and a snippet of XML code (where the '|'
// indicated the cursor position)
// the list would return only the element declarations can be inserted
// while maintaing validity of the content.
// 
// grammar : Foo -> (A, B, C)
// snippet : <Foo><A>|
// result : {B}
// 
protected List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
    List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_STRICT);
    Iterator iterator = modelQueryActions.iterator();
    List cmnodes = new Vector();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
            CMNode actionCMNode = action.getCMNode();
            if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
                cmnodes.add(actionCMNode);
            }
        }
    }
    return cmnodes;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Example 5 with ModelQueryAction

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method getAvailableChildElementDeclarations.

// returns a list of CMNodes that are available within this parent context
// Given the grammar shown below and a snippet of XML code (where the '|'
// indicated the cursor position)
// the list would return all of the element declarations that are
// potential child elements of Foo.
// 
// grammar : Foo -> (A, B, C)
// snippet : <Foo><A>|
// result : {A, B, C}
// 
// TODO cs... do we need to pass in the 'kindOfAction'? Seems to me we
// could assume it's always an insert.
protected List getAvailableChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
    List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_NONE);
    Iterator iterator = modelQueryActions.iterator();
    List cmnodes = new Vector();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
            CMNode actionCMNode = action.getCMNode();
            if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
                cmnodes.add(actionCMNode);
            }
        }
    }
    return cmnodes;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Aggregations

ArrayList (java.util.ArrayList)8 Iterator (java.util.Iterator)8 List (java.util.List)8 ModelQueryAction (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction)8 Vector (java.util.Vector)6 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)5 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)5 NodeList (org.w3c.dom.NodeList)4 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)1