@Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 4;
   final A_BasicObject methodPojo = args.get(0);
   final A_Tuple methodArgs = args.get(1);
   final A_Tuple marshaledTypePojos = args.get(2);
   final A_Type expectedType = args.get(3);
   // Marshal the arguments and invoke the method.
   final Method method = (Method) methodPojo.javaObject();
   assert method != null;
   final Object[] marshaledArgs = new Object[methodArgs.tupleSize()];
   try {
     for (int i = 0; i < marshaledArgs.length; i++) {
       final Class<?> marshaledType = (Class<?>) marshaledTypePojos.tupleAt(i + 1).javaObject();
       marshaledArgs[i] = methodArgs.tupleAt(i + 1).marshalToJava(marshaledType);
     }
   } catch (final MarshalingException e) {
     return interpreter.primitiveFailure(
         PojoDescriptor.newPojo(
             RawPojoDescriptor.identityWrap(e), PojoTypeDescriptor.forClass(e.getClass())));
   }
   final Object result;
   try {
     result = method.invoke(null, marshaledArgs);
   } catch (final InvocationTargetException e) {
     final Throwable cause = e.getCause();
     return interpreter.primitiveFailure(
         PojoDescriptor.newPojo(
             RawPojoDescriptor.identityWrap(cause),
             PojoTypeDescriptor.forClass(cause.getClass())));
   } catch (final Throwable e) {
     // This is an unexpected failure.
     error("reflected method call unexpectedly failed");
     throw new Error();
   }
   if (result == null) {
     return interpreter.primitiveSuccess(PojoDescriptor.nullObject());
   }
   final AvailObject unmarshaled = PojoTypeDescriptor.unmarshal(result, expectedType);
   return interpreter.primitiveSuccess(unmarshaled);
 }
Example #2
0
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   try {
     return invokeImpl(proxy, method, args);
   } catch (TargetError te) {
     // Unwrap target exception.  If the interface declares that
     // it throws the ex it will be delivered.  If not it will be
     // wrapped in an UndeclaredThrowable
     throw te.getTarget();
   } catch (EvalError ee) {
     // Ease debugging...
     // XThis.this refers to the enclosing class instance
     if (Interpreter.DEBUG)
       Interpreter.debug(
           "EvalError in scripted interface: " + XThis.this.toString() + ": " + ee);
     throw ee;
   }
 }