Java Code Examples for groovy.lang.GroovyObject#setProperty()

The following examples show how to use groovy.lang.GroovyObject#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptBytecodeAdapter.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static void setGroovyObjectProperty(Object messageArgument, Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
    try {
        receiver.setProperty(messageName, messageArgument);
    } catch (GroovyRuntimeException gre) {
        throw unwrap(gre);
    }
}
 
Example 2
Source File: InvokerHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static void setProperty(Object object, String property, Object newValue) {
    if (object == null) {
        object = NullObject.getNullObject();
    }

    if (object instanceof GroovyObject) {
        GroovyObject pogo = (GroovyObject) object;
        pogo.setProperty(property, newValue);
    } else if (object instanceof Class) {
        metaRegistry.getMetaClass((Class) object).setProperty(object, property, newValue);
    } else {
        ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue);
    }
}
 
Example 3
Source File: GetPropertyTest.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void testProperty() throws Exception {
    GroovyObject object = compile("src/test/org/codehaus/groovy/classgen/MyBean.groovy");
    System.out.println("Got object: " + object);

    Object value = object.getProperty("name");
    assertEquals("name property", "James", value);

    object.setProperty("name", "Bob");
    assertEquals("name property", "Bob", object.getProperty("name"));
}
 
Example 4
Source File: ScriptBytecodeAdapter.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static void setGroovyObjectPropertySafe(Object messageArgument, Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
    if (receiver == null) return;
    receiver.setProperty(messageName, messageArgument);
}
 
Example 5
Source File: InvokerHelper.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * This is so we don't have to reorder the stack when we call this method.
 * At some point a better name might be in order.
 */
public static void setGroovyObjectProperty(Object newValue, GroovyObject object, String property) {
    object.setProperty(property, newValue);
}