示例#1
0
  private Object getPropertyTryThese(String property, Object firstTry, Object secondTry) {
    try {
      // let's try getting the property on the first object
      return InvokerHelper.getProperty(firstTry, property);

    } catch (MissingPropertyException e1) {
      if (secondTry != null && firstTry != this && firstTry != secondTry) {
        try {
          // let's try getting the property on the second object
          return InvokerHelper.getProperty(secondTry, property);
        } catch (GroovyRuntimeException e2) {
          // ignore, we'll throw e1
        }
      }
      throw e1;

    } catch (MissingFieldException e2) { // see GROOVY-5875
      if (secondTry != null && firstTry != this && firstTry != secondTry) {
        try {
          // let's try getting the property on the second object
          return InvokerHelper.getProperty(secondTry, property);
        } catch (GroovyRuntimeException e3) {
          // ignore, we'll throw e2
        }
      }
      throw e2;
    }
  }
示例#2
0
 public void setProperty(String property, Object newValue) {
   if ("delegate".equals(property)) {
     setDelegate(newValue);
   } else if ("metaClass".equals(property)) {
     setMetaClass((MetaClass) newValue);
   } else if ("resolveStrategy".equals(property)) {
     setResolveStrategy(((Number) newValue).intValue());
   } else if ("directive".equals(property)) {
     setDirective(((Number) newValue).intValue());
   } else {
     switch (resolveStrategy) {
       case DELEGATE_FIRST:
         setPropertyDelegateFirst(property, newValue);
         break;
       case DELEGATE_ONLY:
         InvokerHelper.setProperty(this.delegate, property, newValue);
         break;
       case OWNER_ONLY:
         InvokerHelper.setProperty(this.owner, property, newValue);
         break;
       case TO_SELF:
         super.setProperty(property, newValue);
         break;
       default:
         setPropertyOwnerFirst(property, newValue);
     }
   }
 }
示例#3
0
 public Object getProperty(final String property) {
   if ("delegate".equals(property)) {
     return getDelegate();
   } else if ("owner".equals(property)) {
     return getOwner();
   } else if ("maximumNumberOfParameters".equals(property)) {
     return getMaximumNumberOfParameters();
   } else if ("parameterTypes".equals(property)) {
     return getParameterTypes();
   } else if ("metaClass".equals(property)) {
     return getMetaClass();
   } else if ("class".equals(property)) {
     return getClass();
   } else if ("directive".equals(property)) {
     return getDirective();
   } else if ("resolveStrategy".equals(property)) {
     return getResolveStrategy();
   } else if ("thisObject".equals(property)) {
     return getThisObject();
   } else {
     switch (resolveStrategy) {
       case DELEGATE_FIRST:
         return getPropertyDelegateFirst(property);
       case DELEGATE_ONLY:
         return InvokerHelper.getProperty(this.delegate, property);
       case OWNER_ONLY:
         return InvokerHelper.getProperty(this.owner, property);
       case TO_SELF:
         return super.getProperty(property);
       default:
         return getPropertyOwnerFirst(property);
     }
   }
 }
示例#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 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);
   }
 }
 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);
   }
 }
示例#10
0
 //  --------------------------------------------------------
 //              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);
   }
 }
示例#11
0
 public static Object getProperty(Class senderClass, Object receiver, String messageName)
     throws Throwable {
   try {
     return InvokerHelper.getProperty(receiver, messageName);
   } catch (GroovyRuntimeException gre) {
     throw unwrap(gre);
   }
 }
示例#12
0
 private void setPropertyTryThese(
     String property, Object newValue, Object firstTry, Object secondTry) {
   try {
     // let's try setting the property on the first object
     InvokerHelper.setProperty(firstTry, property, newValue);
   } catch (GroovyRuntimeException e1) {
     if (firstTry != null && firstTry != this && firstTry != secondTry) {
       try {
         // let's try setting the property on the second object
         InvokerHelper.setProperty(secondTry, property, newValue);
         return;
       } catch (GroovyRuntimeException e2) {
         // ignore, we'll throw e1
       }
     }
     throw e1;
   }
 }
示例#13
0
 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);
   }
 }
示例#14
0
 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;
 }
示例#15
0
 //  --------------------------------------------------------
 //                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);
   }
 }
示例#16
0
 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;
 }
示例#17
0
 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);
   }
 }
示例#18
0
 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);
   }
 }
示例#19
0
 /**
  * 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);
 }
示例#20
0
 public static MetaClass initMetaClass(Object object) {
   return InvokerHelper.getMetaClass(object.getClass());
 }
示例#21
0
 public static Object spreadMap(Object value) {
   return InvokerHelper.spreadMap(value);
 }
示例#22
0
 public static Object unaryMinus(Object value) throws Throwable {
   return InvokerHelper.unaryMinus(value);
 }
示例#23
0
 public static boolean matchRegex(Object left, Object right) {
   return InvokerHelper.matchRegex(left, right);
 }
示例#24
0
 public static Matcher findRegex(Object left, Object right) throws Throwable {
   return InvokerHelper.findRegex(left, right);
 }
示例#25
0
 // assert
 public static void assertFailed(Object expression, Object message) {
   InvokerHelper.assertFailed(expression, message);
 }
示例#26
0
 public static Map createMap(Object[] values) {
   return InvokerHelper.createMap(values);
 }
示例#27
0
 public static List createList(Object[] values) {
   return InvokerHelper.createList(values);
 }