Search in sources :

Example 6 with StepExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_step.

// this will evaluate the step expression for the whole focus and return
// the result.
// 
// i.e. It will execute the step expression for each item in the focus
// [each time changing the context item].
private ResultSequence do_step(StepExpr se) {
    ResultBuffer rs = new ResultBuffer();
    ArrayList results = new ArrayList();
    // 0: don't know yet
    int type = 0;
    // 1: atomic
    // 2: node
    Focus focus = focus();
    int original_pos = focus.position();
    // execute step for all items in focus
    while (true) {
        results.add(se.accept(this));
        // go to next
        if (!focus.advance_cp())
            break;
    }
    // make sure we didn't change focus
    focus.set_position(original_pos);
    boolean node_types = false;
    // check the results
    for (Iterator i = results.iterator(); i.hasNext(); ) {
        ResultSequence result = (ResultSequence) i.next();
        // make sure results are of same type, and add them in
        for (Iterator j = result.iterator(); j.hasNext(); ) {
            AnyType item = (AnyType) j.next();
            // first item
            if (type == 0) {
                if (item instanceof AnyAtomicType)
                    type = 1;
                else if (item instanceof NodeType)
                    type = 2;
                else
                    assert false;
            }
            // make sure we got coherent types
            switch(type) {
                // atomic... just concat
                case 1:
                    if (!(item instanceof AnyAtomicType))
                        report_error(TypeError.mixed_vals(null));
                    rs.add(item);
                    break;
                case 2:
                    node_types = true;
                    if (!(item instanceof NodeType))
                        report_error(TypeError.mixed_vals(null));
                    rs.add(item);
                    break;
                default:
                    assert false;
            }
        }
    }
    // XXX lame
    if (node_types) {
        rs = NodeType.linarize(rs);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Aggregations

StepExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr)5 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)5 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)2 ListIterator (java.util.ListIterator)2 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)2 Focus (org.eclipse.wst.xml.xpath2.processor.internal.Focus)2 AnyKindTest (org.eclipse.wst.xml.xpath2.processor.internal.ast.AnyKindTest)2 AxisStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep)2 ForwardStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep)2 ReverseStep (org.eclipse.wst.xml.xpath2.processor.internal.ast.ReverseStep)2 Step (org.eclipse.wst.xml.xpath2.processor.internal.ast.Step)2 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)2 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)2 Collection (java.util.Collection)1 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)1 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)1 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)1