Search in sources :

Example 1 with Optional

use of org.apache.el.stream.Optional in project tomcat by apache.

the class AstValue method getValue.

@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    Object base = this.children[0].getValue(ctx);
    int propCount = this.jjtGetNumChildren();
    int i = 1;
    Object suffix = null;
    ELResolver resolver = ctx.getELResolver();
    while (base != null && i < propCount) {
        suffix = this.children[i].getValue(ctx);
        if (i + 1 < propCount && (this.children[i + 1] instanceof AstMethodParameters)) {
            AstMethodParameters mps = (AstMethodParameters) this.children[i + 1];
            if (base instanceof Optional && "orElseGet".equals(suffix) && mps.jjtGetNumChildren() == 1) {
                Node paramFoOptional = mps.jjtGetChild(0);
                if (!(paramFoOptional instanceof AstLambdaExpression || paramFoOptional instanceof LambdaExpression)) {
                    throw new ELException(MessageFactory.get("stream.optional.paramNotLambda", suffix));
                }
            }
            // This is a method
            Object[] paramValues = mps.getParameters(ctx);
            base = resolver.invoke(ctx, base, suffix, getTypesFromValues(paramValues), paramValues);
            i += 2;
        } else {
            // This is a property
            if (suffix == null) {
                return null;
            }
            ctx.setPropertyResolved(false);
            base = resolver.getValue(ctx, base, suffix);
            i++;
        }
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled", base, suffix));
    }
    return base;
}
Also used : ELResolver(javax.el.ELResolver) PropertyNotFoundException(javax.el.PropertyNotFoundException) Optional(org.apache.el.stream.Optional) ELException(javax.el.ELException) LambdaExpression(javax.el.LambdaExpression)

Aggregations

ELException (javax.el.ELException)1 ELResolver (javax.el.ELResolver)1 LambdaExpression (javax.el.LambdaExpression)1 PropertyNotFoundException (javax.el.PropertyNotFoundException)1 Optional (org.apache.el.stream.Optional)1