예제 #1
0
 /**
  * Set the property on the given object to the new value.
  *
  * @param object on which to set the property
  * @param newValue the new value of the property
  * @throws RuntimeException if the property could not be set
  */
 public void setProperty(Object object, Object newValue) {
   MetaMethod setter = getSetter();
   if (setter == null) {
     if (field != null && !Modifier.isFinal(field.getModifiers())) {
       field.setProperty(object, newValue);
       return;
     }
     throw new GroovyRuntimeException("Cannot set read-only property: " + name);
   }
   newValue = DefaultTypeTransformation.castToType(newValue, getType());
   setter.invoke(object, new Object[] {newValue});
 }
예제 #2
0
 /**
  * Provides a hook for type casting of the given object to the required type
  *
  * @param type of object to convert the given object to
  * @param object the object to be converted
  * @return the original object or a new converted value
  * @throws Throwable if the type casting fails
  */
 public static Object castToType(Object object, Class type) throws Throwable {
   return DefaultTypeTransformation.castToType(object, type);
 }