예제 #1
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final A_Atom propertyKey = args.get(0);
   final A_Atom atom = args.get(1);
   if (atom.isAtomSpecial()) {
     return interpreter.primitiveFailure(E_SPECIAL_ATOM);
   }
   final A_BasicObject propertyValue = atom.getAtomProperty(propertyKey);
   return interpreter.primitiveSuccess(
       AtomDescriptor.objectFromBoolean(!propertyValue.equalsNil()));
 }
예제 #2
0
 @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);
 }