public static Object bitwiseNegate(Object value) throws Throwable {
   try {
     return InvokerHelper.bitwiseNegate(value);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static Object unaryPlus(Object value) throws Throwable {
   try {
     return InvokerHelper.unaryPlus(value);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static void setPropertyOnSuperSpreadSafe(
     Object messageArgument, Class senderClass, GroovyObject receiver, String messageName)
     throws Throwable {
   for (Iterator it = InvokerHelper.asIterator(receiver); it.hasNext(); ) {
     setPropertySafe(messageArgument, senderClass, it.next(), messageName);
   }
 }
Beispiel #4
0
  /**
   * Asserts that the given object can be converted into a collection and iterator of the given size
   */
  protected void assertAsCollection(Object collectionObject, int count) {
    Collection collection = DefaultTypeTransformation.asCollection(collectionObject);
    assertTrue("Collection is not null", collection != null);
    assertEquals("Collection size", count, collection.size());

    assertIterator("collections iterator", collection.iterator(), count);
    assertIterator("InvokerHelper.asIterator", InvokerHelper.asIterator(collectionObject), count);
    assertIterator(
        "InvokerHelper.asIterator(InvokerHelper.asCollection)",
        InvokerHelper.asIterator(collection),
        count);
    assertIterator(
        "InvokerHelper.asIterator(InvokerHelper.asIterator)",
        InvokerHelper.asIterator(InvokerHelper.asIterator(collectionObject)),
        count);
  }
 public static Object getProperty(Class senderClass, Object receiver, String messageName)
     throws Throwable {
   try {
     return InvokerHelper.getProperty(receiver, messageName);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static Object getPropertyOnSuperSpreadSafe(
     Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
   List answer = new ArrayList();
   for (Iterator it = InvokerHelper.asIterator(receiver); it.hasNext(); ) {
     answer.add(getPropertySafe(senderClass, it.next(), messageName));
   }
   return answer;
 }
 public static void setGroovyObjectFieldSpreadSafe(
     Object messageArgument, Class senderClass, GroovyObject receiver, String messageName)
     throws Throwable {
   if (receiver == null) return;
   for (Iterator it = InvokerHelper.asIterator(receiver); it.hasNext(); ) {
     setFieldSafe(messageArgument, senderClass, it.next(), messageName);
   }
 }
 //  --------------------------------------------------------
 //              normal constructor invocation (via new)
 //  --------------------------------------------------------
 public static Object invokeNewN(Class senderClass, Class receiver, Object arguments)
     throws Throwable {
   try {
     return InvokerHelper.invokeConstructorOf(receiver, arguments);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static void setPropertyOnSuper(
     Object messageArgument, Class senderClass, GroovyObject receiver, String messageName)
     throws Throwable {
   try {
     InvokerHelper.setAttribute(receiver, messageName, messageArgument);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static Object getFieldSpreadSafe(Class senderClass, Object receiver, String messageName)
     throws Throwable {
   if (receiver == null) return null;
   List answer = new ArrayList();
   for (Iterator it = InvokerHelper.asIterator(receiver); it.hasNext(); ) {
     answer.add(getFieldSafe(senderClass, it.next(), messageName));
   }
   return answer;
 }
 //  --------------------------------------------------------
 //                static normal method invocation
 //  --------------------------------------------------------
 public static Object invokeStaticMethodN(
     Class senderClass, Class receiver, String messageName, Object[] messageArguments)
     throws Throwable {
   try {
     return InvokerHelper.invokeStaticMethod(receiver, messageName, messageArguments);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static Object invokeMethodOnSuperNSpreadSafe(
     Class senderClass, GroovyObject receiver, String messageName, Object[] messageArguments)
     throws Throwable {
   List answer = new ArrayList();
   for (Iterator it = InvokerHelper.asIterator(receiver); it.hasNext(); ) {
     answer.add(invokeMethodNSafe(senderClass, it.next(), messageName, messageArguments));
   }
   return answer;
 }
 public static void setProperty(
     Object messageArgument, Class senderClass, Object receiver, String messageName)
     throws Throwable {
   try {
     if (receiver == null) receiver = NullObject.getNullObject();
     InvokerHelper.setProperty(receiver, messageName, messageArgument);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 public static Object getFieldOnSuper(Class senderClass, Object receiver, String messageName)
     throws Throwable {
   try {
     if (receiver instanceof Class) {
       return InvokerHelper.getAttribute(receiver, messageName);
     } else {
       MetaClass mc = ((GroovyObject) receiver).getMetaClass();
       return mc.getAttribute(senderClass, receiver, messageName, true);
     }
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
 /**
  * Returns the method pointer for the given object name
  *
  * @param object the object containing the method
  * @param methodName the name of the method of interest
  * @return the resulting Closure
  */
 public static Closure getMethodPointer(Object object, String methodName) {
   return InvokerHelper.getMethodPointer(object, methodName);
 }
 public static MetaClass initMetaClass(Object object) {
   return InvokerHelper.getMetaClass(object.getClass());
 }
 public static Object spreadMap(Object value) {
   return InvokerHelper.spreadMap(value);
 }
 public static Object unaryMinus(Object value) throws Throwable {
   return InvokerHelper.unaryMinus(value);
 }
 public static boolean matchRegex(Object left, Object right) {
   return InvokerHelper.matchRegex(left, right);
 }
 public static Matcher findRegex(Object left, Object right) throws Throwable {
   return InvokerHelper.findRegex(left, right);
 }
 // assert
 public static void assertFailed(Object expression, Object message) {
   InvokerHelper.assertFailed(expression, message);
 }
 public static Map createMap(Object[] values) {
   return InvokerHelper.createMap(values);
 }
 public static List createList(Object[] values) {
   return InvokerHelper.createList(values);
 }