Search in sources :

Example 1 with StepExpr

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

the class Normalizer method make_descendant_or_self.

private XPathExpr make_descendant_or_self() {
    Step desc_self_node = new ForwardStep(ForwardStep.DESCENDANT_OR_SELF, new AnyKindTest());
    StepExpr se = new AxisStep(desc_self_node, new ArrayList());
    return new XPathExpr(0, se);
}
Also used : ForwardStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) ArrayList(java.util.ArrayList) AxisStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep) ForwardStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep) ReverseStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.ReverseStep) Step(org.eclipse.wst.xml.xpath2.processor.internal.ast.Step) AxisStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep) AnyKindTest(org.eclipse.wst.xml.xpath2.processor.internal.ast.AnyKindTest) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 2 with StepExpr

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

the class Normalizer method make_root_self_node.

private XPathExpr make_root_self_node() {
    // self::node()
    Step self_node = new ForwardStep(ForwardStep.SELF, new AnyKindTest());
    StepExpr self_node_expr = new AxisStep(self_node, new ArrayList());
    XPathExpr self_node_xpath = new XPathExpr(0, self_node_expr);
    // fn:root(self::node())
    Collection args = new ArrayList();
    args.add(self_node_xpath);
    XPathExpr xpe = make_function(new QName("fn", "root", FnFunctionLibrary.XPATH_FUNCTIONS_NS), args);
    return xpe;
}
Also used : ForwardStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AxisStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep) ForwardStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForwardStep) ReverseStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.ReverseStep) Step(org.eclipse.wst.xml.xpath2.processor.internal.ast.Step) AxisStep(org.eclipse.wst.xml.xpath2.processor.internal.ast.AxisStep) AnyKindTest(org.eclipse.wst.xml.xpath2.processor.internal.ast.AnyKindTest) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 3 with StepExpr

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

the class Normalizer method visit.

/**
 * @param e
 *            is the xpath expression.
 * @return result.
 */
public Object visit(XPathExpr e) {
    XPathExpr xp = e;
    // indicates how many / we traversed
    int depth = 0;
    XPathExpr result = e;
    while (xp != null) {
        int slashes = xp.slashes();
        StepExpr se = xp.expr();
        if (slashes == 1) {
            // this is a single slash and nothing else...
            if (se == null)
                return make_root_self_node();
            // /RelativePathExpr
            if (depth == 0) {
                XPathExpr xpe = make_root_self_node();
                xpe.set_next(e);
                result = xpe;
            }
        }
        if (slashes == 2) {
            // //RelativePathExpr
            if (depth == 0) {
                XPathExpr desc = make_descendant_or_self();
                desc.set_slashes(1);
                e.set_slashes(1);
                desc.set_next(e);
                XPathExpr root_self = make_root_self_node();
                root_self.set_next(desc);
                return root_self;
            }
        }
        if (se != null)
            se.accept(this);
        XPathExpr next = xp.next();
        // peek if the next guy will have 2 slashes...
        if (next != null) {
            // StepExpr//StepExpr
            if (next.slashes() == 2) {
                // create the node to stick between the
                // slashes
                XPathExpr desc = make_descendant_or_self();
                desc.set_slashes(1);
                // current node / desc / next
                xp.set_next(desc);
                desc.set_next(next);
                next.set_slashes(1);
            }
        }
        xp = next;
        depth++;
    }
    return result;
}
Also used : StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 4 with StepExpr

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

the class StaticNameResolver method visit.

/**
 * Validate an xpath expression.
 *
 * @param e
 *            is the expression.
 * @return null.
 */
public Object visit(XPathExpr e) {
    XPathExpr xp = e;
    boolean firstStep = true;
    while (xp != null) {
        if (firstStep && xp.slashes() != 0)
            _rootUsed = true;
        firstStep = false;
        StepExpr se = xp.expr();
        if (se != null)
            se.accept(this);
        xp = xp.next();
    }
    return null;
}
Also used : StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 5 with StepExpr

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

the class DefaultEvaluator method visit.

/**
 * visit XPath expression
 *
 * @param e
 *            is the XPath expression.
 * @return a new function
 */
public Object visit(XPathExpr e) {
    XPathExpr xp = e;
    ResultSequence rs = null;
    Focus original_focus = focus();
    // do all the steps
    while (xp != null) {
        StepExpr se = xp.expr();
        if (se != null) {
            // this is not the first step
            if (rs != null) {
                // results...
                if (rs.size() == 0)
                    break;
                // nodes!
                for (Iterator i = rs.iterator(); i.hasNext(); ) {
                    AnyType item = (AnyType) i.next();
                    if (!(item instanceof NodeType)) {
                        report_error(TypeError.step_conatins_atoms(null));
                        // unreach
                        return null;
                    }
                }
                // check if we got a //
                if (xp.slashes() == 2) {
                    rs = descendant_or_self_node(rs);
                    if (rs.size() == 0)
                        break;
                }
                // make result of previous step the new
                // focus
                set_focus(new Focus(rs));
                // do the step for all item in context
                rs = do_step(se);
            } else // this is first step...
            // note... we may be called from upstream...
            // like in the expression sorbo/*[2] ... we may
            // be called to evaluate the 2... the caller
            // will iterate through the whole outer focus
            // for us
            {
                // XXX ???
                if (xp.slashes() == 1) {
                    rs = root_self_node();
                    set_focus(new Focus(rs));
                    rs = do_step(se);
                } else if (xp.slashes() == 2) {
                    rs = root_self_node();
                    rs = descendant_or_self_node(rs);
                    set_focus(new Focus(rs));
                    rs = do_step(se);
                } else
                    rs = (ResultSequence) se.accept(this);
            }
        } else // the expression is "/"
        {
            assert xp.slashes() == 1;
            rs = root_self_node();
        }
        xp = xp.next();
    }
    // restore focus
    set_focus(original_focus);
    return rs;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

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