Search in sources :

Example 1 with CastExpr

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

the class DefaultEvaluator method visit.

/**
 * visit cast expression
 *
 * @param cexp
 *            is the cast expression.
 * @return a new function
 */
public Object visit(CastExpr cexp) {
    ResultSequence rs = (ResultSequence) cexp.left().accept(this);
    SingleType st = (SingleType) cexp.right();
    rs = FnData.atomize(rs);
    if (rs.size() > 1)
        report_error(TypeError.invalid_type(null));
    if (rs.empty()) {
        if (st.qmark())
            return rs;
        else
            report_error(TypeError.invalid_type(null));
    }
    AnyType at = (AnyType) rs.item(0);
    if (!(at instanceof AnyAtomicType))
        report_error(TypeError.invalid_type(null));
    AnyAtomicType aat = (AnyAtomicType) at;
    QName type = st.type();
    // prepare args from function
    Collection args = new ArrayList();
    args.add(ResultSequenceFactory.create_new(aat));
    try {
        Function function = cexp.function();
        if (function == null) {
            function = _sc.resolveFunction(type.asQName(), args.size());
            cexp.set_function(function);
        }
        if (function == null)
            report_error(TypeError.invalid_type(null));
        return function.evaluate(args, _ec);
    } catch (DynamicError err) {
        report_error(err);
        // unreach
        return null;
    }
}
Also used : Function(org.eclipse.wst.xml.xpath2.api.Function) SingleType(org.eclipse.wst.xml.xpath2.processor.internal.ast.SingleType) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 2 with CastExpr

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

the class DefaultEvaluator method visit.

/**
 * visit castable expression
 *
 * @param cexp
 *            is the castable expression.
 * @return a new function
 */
public Object visit(CastableExpr cexp) {
    boolean castable = false;
    try {
        CastExpr ce = new CastExpr((Expr) cexp.left(), (SingleType) cexp.right());
        visit(ce);
        castable = true;
    } catch (Throwable t) {
        castable = false;
    }
    return ResultSequenceFactory.create_new(new XSBoolean(castable));
}
Also used : XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)

Example 3 with CastExpr

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

the class StaticNameResolver method visit.

/**
 * Validate a cast expression.
 *
 * @param cexp
 *            is the expression.
 * @return null.
 */
public Object visit(CastExpr cexp) {
    printBinExpr("CAST", cexp);
    SingleType st = (SingleType) cexp.right();
    QName type = st.type();
    javax.xml.namespace.QName qName = type.asQName();
    Function f = _sc.resolveFunction(qName, 1);
    if (f == null)
        reportError(new StaticFunctNameError("Type does not exist: " + type.toString()));
    cexp.set_function(f);
    _resolvedFunctions.add(qName);
    return null;
}
Also used : Function(org.eclipse.wst.xml.xpath2.api.Function) SingleType(org.eclipse.wst.xml.xpath2.processor.internal.ast.SingleType) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) StaticFunctNameError(org.eclipse.wst.xml.xpath2.processor.internal.StaticFunctNameError)

Aggregations

Function (org.eclipse.wst.xml.xpath2.api.Function)2 SingleType (org.eclipse.wst.xml.xpath2.processor.internal.ast.SingleType)2 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)1 StaticFunctNameError (org.eclipse.wst.xml.xpath2.processor.internal.StaticFunctNameError)1 CastExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)1 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)1 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)1 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)1