Search in sources :

Example 1 with XPathBinaryOpExpr

use of org.javarosa.xpath.expr.XPathBinaryOpExpr in project javarosa by opendatakit.

the class XPathConditional method getTriggers.

private static void getTriggers(XPathExpression x, Set<TreeReference> v, TreeReference contextRef) {
    if (x instanceof XPathPathExpr) {
        TreeReference ref = ((XPathPathExpr) x).getReference();
        TreeReference contextualized = ref;
        if (contextRef != null) {
            contextualized = ref.contextualize(contextRef);
        }
        // TODO: It's possible we should just handle this the same way as "genericize". Not entirely clear.
        if (contextualized.hasPredicates()) {
            contextualized = contextualized.removePredicates();
        }
        v.add(contextualized);
        for (int i = 0; i < ref.size(); i++) {
            List<XPathExpression> predicates = ref.getPredicate(i);
            if (predicates == null) {
                continue;
            }
            // we can't generate this properly without an absolute reference
            if (!ref.isAbsolute()) {
                throw new IllegalArgumentException("can't get triggers for relative references");
            }
            TreeReference predicateContext = ref.getSubReference(i);
            for (XPathExpression predicate : predicates) {
                getTriggers(predicate, v, predicateContext);
            }
        }
    } else if (x instanceof XPathBinaryOpExpr) {
        getTriggers(((XPathBinaryOpExpr) x).a, v, contextRef);
        getTriggers(((XPathBinaryOpExpr) x).b, v, contextRef);
    } else if (x instanceof XPathUnaryOpExpr) {
        getTriggers(((XPathUnaryOpExpr) x).a, v, contextRef);
    } else if (x instanceof XPathFuncExpr) {
        XPathFuncExpr fx = (XPathFuncExpr) x;
        for (int i = 0; i < fx.args.length; i++) getTriggers(fx.args[i], v, contextRef);
    }
}
Also used : XPathExpression(org.javarosa.xpath.expr.XPathExpression) XPathPathExpr(org.javarosa.xpath.expr.XPathPathExpr) TreeReference(org.javarosa.core.model.instance.TreeReference) XPathFuncExpr(org.javarosa.xpath.expr.XPathFuncExpr) XPathBinaryOpExpr(org.javarosa.xpath.expr.XPathBinaryOpExpr) XPathUnaryOpExpr(org.javarosa.xpath.expr.XPathUnaryOpExpr)

Aggregations

TreeReference (org.javarosa.core.model.instance.TreeReference)1 XPathBinaryOpExpr (org.javarosa.xpath.expr.XPathBinaryOpExpr)1 XPathExpression (org.javarosa.xpath.expr.XPathExpression)1 XPathFuncExpr (org.javarosa.xpath.expr.XPathFuncExpr)1 XPathPathExpr (org.javarosa.xpath.expr.XPathPathExpr)1 XPathUnaryOpExpr (org.javarosa.xpath.expr.XPathUnaryOpExpr)1