Search in sources :

Example 1 with MethodInfo

use of jakarta.el.MethodInfo in project tomcat by apache.

the class TestMethodExpressionImpl method testGetMethodInfo02.

@Test
public void testGetMethodInfo02() throws Exception {
    MethodExpression me = factory.createMethodExpression(context, "#{beanA.setName}", null, new Class[] { String.class });
    // This is the call that failed
    MethodInfo mi = me.getMethodInfo(context);
    // The rest is to check it worked correctly
    Assert.assertEquals(void.class, mi.getReturnType());
    Assert.assertEquals(1, mi.getParamTypes().length);
    Assert.assertEquals(String.class, mi.getParamTypes()[0]);
}
Also used : MethodInfo(jakarta.el.MethodInfo) MethodExpression(jakarta.el.MethodExpression) Test(org.junit.Test)

Example 2 with MethodInfo

use of jakarta.el.MethodInfo in project tomcat by apache.

the class TestMethodExpressionImpl method testGetMethodInfo01.

@Test
public void testGetMethodInfo01() throws Exception {
    MethodExpression me = factory.createMethodExpression(context, "#{beanA.setName('New value')}", null, null);
    // This is the call that failed
    MethodInfo mi = me.getMethodInfo(context);
    // The rest is to check it worked correctly
    Assert.assertEquals(void.class, mi.getReturnType());
    Assert.assertEquals(1, mi.getParamTypes().length);
    Assert.assertEquals(String.class, mi.getParamTypes()[0]);
}
Also used : MethodInfo(jakarta.el.MethodInfo) MethodExpression(jakarta.el.MethodExpression) Test(org.junit.Test)

Example 3 with MethodInfo

use of jakarta.el.MethodInfo in project tomcat by apache.

the class MethodExpressionLiteral method getMethodInfo.

@Override
public MethodInfo getMethodInfo(ELContext context) throws ELException {
    context.notifyBeforeEvaluation(getExpressionString());
    MethodInfo result = getMethodInfoInternal();
    context.notifyAfterEvaluation(getExpressionString());
    return result;
}
Also used : MethodInfo(jakarta.el.MethodInfo)

Example 4 with MethodInfo

use of jakarta.el.MethodInfo in project tomcat by apache.

the class MethodExpressionImpl method getMethodInfo.

/**
 * Evaluates the expression relative to the provided context, and returns
 * information about the actual referenced method.
 *
 * @param context
 *            The context of this evaluation
 * @return an instance of <code>MethodInfo</code> containing information
 *         about the method the expression evaluated to.
 * @throws NullPointerException
 *             if context is <code>null</code> or the base object is
 *             <code>null</code> on the last resolution.
 * @throws PropertyNotFoundException
 *             if one of the property resolutions failed because a specified
 *             variable or property does not exist or is not readable.
 * @throws MethodNotFoundException
 *             if no suitable method can be found.
 * @throws ELException
 *             if an exception was thrown while performing property or
 *             variable resolution. The thrown exception must be included as
 *             the cause property of this exception, if available.
 * @see jakarta.el.MethodExpression#getMethodInfo(jakarta.el.ELContext)
 */
@Override
public MethodInfo getMethodInfo(ELContext context) throws PropertyNotFoundException, MethodNotFoundException, ELException {
    Node n = this.getNode();
    EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, this.varMapper);
    ctx.notifyBeforeEvaluation(getExpressionString());
    MethodInfo result = n.getMethodInfo(ctx, this.paramTypes);
    ctx.notifyAfterEvaluation(getExpressionString());
    return result;
}
Also used : Node(org.apache.el.parser.Node) MethodInfo(jakarta.el.MethodInfo) EvaluationContext(org.apache.el.lang.EvaluationContext)

Example 5 with MethodInfo

use of jakarta.el.MethodInfo in project tomcat by apache.

the class AstValue method getMethodInfo.

@Override
public // Interface el.parser.Node uses raw types (and is auto-generated)
MethodInfo getMethodInfo(EvaluationContext ctx, @SuppressWarnings("rawtypes") Class[] paramTypes) throws ELException {
    Target t = getTarget(ctx);
    Class<?>[] types = null;
    if (isParametersProvided()) {
        Object[] values = ((AstMethodParameters) this.jjtGetChild(this.jjtGetNumChildren() - 1)).getParameters(ctx);
        types = getTypesFromValues(values);
    } else {
        types = paramTypes;
    }
    Method m = ReflectionUtil.getMethod(ctx, t.base, t.property, types, null);
    return new MethodInfo(m.getName(), m.getReturnType(), m.getParameterTypes());
}
Also used : MethodInfo(jakarta.el.MethodInfo) Method(java.lang.reflect.Method)

Aggregations

MethodInfo (jakarta.el.MethodInfo)6 MethodExpression (jakarta.el.MethodExpression)2 Test (org.junit.Test)2 ELException (jakarta.el.ELException)1 MethodNotFoundException (jakarta.el.MethodNotFoundException)1 PropertyNotFoundException (jakarta.el.PropertyNotFoundException)1 Method (java.lang.reflect.Method)1 EvaluationContext (org.apache.el.lang.EvaluationContext)1 Node (org.apache.el.parser.Node)1