Search in sources :

Example 1 with FunctionCall

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

the class Normalizer method make_function.

private XPathExpr make_function(QName name, Collection args) {
    FunctionCall fc = new FunctionCall(name, args);
    FilterExpr fe = new FilterExpr(fc, new ArrayList());
    return new XPathExpr(0, fe);
}
Also used : FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) ArrayList(java.util.ArrayList) FunctionCall(org.eclipse.wst.xml.xpath2.processor.internal.ast.FunctionCall) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 2 with FunctionCall

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

the class DefaultEvaluator method visit.

/**
 * visit function call.
 *
 * @param e
 *            is the function call.
 * @return a new function or null
 */
public Object visit(FunctionCall e) {
    ArrayList args = new ArrayList();
    for (Iterator i = e.iterator(); i.hasNext(); ) {
        Expr arg = (Expr) i.next();
        // each argument will produce a result sequence
        args.add((ResultSequence) arg.accept(this));
    }
    try {
        Function function = e.function();
        if (function == null) {
            function = _sc.resolveFunction(e.name().asQName(), args.size());
            e.set_function(function);
        }
        return function.evaluate(args, _ec);
    } catch (DynamicError err) {
        report_error(err);
        // unreach
        return null;
    }
}
Also used : Function(org.eclipse.wst.xml.xpath2.api.Function) QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator)

Example 3 with FunctionCall

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

the class StaticNameResolver method visit.

/**
 * Validate a function call.
 *
 * @param e
 *            is the expression.
 * @return null.
 */
public Object visit(FunctionCall e) {
    QName name = e.name();
    if (!expandFunctionQName(name))
        reportBadPrefix(name.prefix());
    javax.xml.namespace.QName qName = name.asQName();
    Function f = _sc.resolveFunction(qName, e.arity());
    if (f == null)
        reportError(new StaticFunctNameError("Function does not exist: " + name.string() + " arity: " + e.arity()));
    e.set_function(f);
    _resolvedFunctions.add(qName);
    visitExprs(e.iterator());
    return null;
}
Also used : Function(org.eclipse.wst.xml.xpath2.api.Function) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) StaticFunctNameError(org.eclipse.wst.xml.xpath2.processor.internal.StaticFunctNameError)

Aggregations

ArrayList (java.util.ArrayList)2 Function (org.eclipse.wst.xml.xpath2.api.Function)2 FilterExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr)2 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)2 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 StaticFunctNameError (org.eclipse.wst.xml.xpath2.processor.internal.StaticFunctNameError)1 AddExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr)1 AndExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr)1 BinExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr)1 CastExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)1 CastableExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr)1 CmpExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr)1 CntxItemExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr)1 DivExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr)1 ExceptExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr)1 Expr (org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr)1 ForExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr)1 FunctionCall (org.eclipse.wst.xml.xpath2.processor.internal.ast.FunctionCall)1 IDivExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr)1