use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project groovy by apache.
the class InvokerHelper method setProperty.
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((Class) object, property, newValue);
} else {
((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue);
}
}
use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project groovy by apache.
the class MetaClassImpl method invokePropertyOrMissing.
private Object invokePropertyOrMissing(Object object, String methodName, Object[] originalArguments, boolean fromInsideClass, boolean isCallToSuper) {
// if no method was found, try to find a closure defined as a field of the class and run it
Object value = null;
final MetaProperty metaProperty = this.getMetaProperty(methodName, false);
if (metaProperty != null)
value = metaProperty.getProperty(object);
else {
if (object instanceof Map)
value = ((Map) object).get(methodName);
}
if (value instanceof Closure) {
// This test ensures that value != this If you ever change this ensure that value != this
Closure closure = (Closure) value;
MetaClass delegateMetaClass = closure.getMetaClass();
return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass);
}
if (object instanceof Script) {
Object bindingVar = ((Script) object).getBinding().getVariables().get(methodName);
if (bindingVar != null) {
MetaClass bindingVarMC = ((MetaClassRegistryImpl) registry).getMetaClass(bindingVar);
return bindingVarMC.invokeMethod(bindingVar, CLOSURE_CALL_METHOD, originalArguments);
}
}
return invokeMissingMethod(object, methodName, originalArguments, null, isCallToSuper);
}
Aggregations