package org.apache.commons.jexl.parser;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.jexl.util.introspection.VelMethod;
import org.apache.commons.jexl.util.introspection.Info;

public class ASTMethod extends SimpleNode
{
    public ASTMethod(int id)
    {
        super(id);
    }

    public ASTMethod(Parser p, int id)
    {
        super(p, id);
    }


    /** Accept the visitor. **/
    public Object jjtAccept(ParserVisitor visitor, Object data)
    {
        return visitor.visit(this, data);
    }

    /**
     *  returns the value of itself applied to the object.
     *   We assume that an identifier can be gotten via a get(String)
     */
    public Object execute(Object obj, JexlContext jc) 
        throws Exception
    {
        String methodName = ((ASTIdentifier)jjtGetChild(0)).val;

        int paramCount = jjtGetNumChildren()-1;

        /*
         *  get our params
         */

        Object params[] = new Object[paramCount];

        try
        {
            for (int i=0; i<paramCount; i++)
            {
                params[i] = ( (SimpleNode) jjtGetChild(i+1)).value(jc);
            }
    
            VelMethod vm = Introspector.getUberspect().getMethod(obj, methodName,
                params, new Info("",1,1));
    
            if (vm == null)
                return null;
    
            return vm.invoke(obj, params);
        }
        catch(InvocationTargetException e)
        {
            Throwable t = e.getTargetException();

            if (t instanceof Exception)
            {
                throw (Exception) t;
            }

            throw e;
        }
        catch(Exception e)
        {
            System.out.println("ASTMethod : "+ e);
            e.printStackTrace();;
            throw e;
         }
    }
}

@@ -828,18 +828,17 @@
 text jc)
- 
 %0A
+
         
@@ -1244,21 +1244,17 @@
       %7D%0A
-    
 %0A
+
         
@@ -1370,21 +1370,17 @@
 ,1,1));%0A
-    
 %0A
+
         
@@ -1432,13 +1432,9 @@
 ll;%0A
-    
 %0A
+
     
@@ -1727,162 +1727,8 @@
   %7D%0A
-        catch(Exception e)%0A        %7B%0A            System.out.println(%22ASTMethod : %22+ e);%0A            e.printStackTrace();;%0A            throw e;%0A         %7D%0A
     

Patch from Mark Wilkinson to remove unneeded e.printStackTrace()