public void setMetaClass(final MetaClass metaClass) { this.wrapped.setMetaClass(metaClass); }
/** * Use the ProxyMetaClass for the given Closure. * Cares for balanced setting/unsetting ProxyMetaClass. * * @param closure piece of code to be executed with ProxyMetaClass */ public Object use(GroovyObject object, Closure closure) { // grab existing meta (usually adaptee but we may have nested use calls) MetaClass origMetaClass = object.getMetaClass(); object.setMetaClass(this); try { return closure.call(); } finally { object.setMetaClass(origMetaClass); } }
/** * Unlike general impl in superclass, ctors are not intercepted but relayed * unless interceptConstruction is set. */ public Object invokeConstructor(final Object[] arguments) { if (interceptConstruction && null == interceptor) throw new RuntimeException("cannot invoke constructor without interceptor"); if (interceptConstruction) { GroovyObject newInstance = (GroovyObject) interceptor.beforeInvoke(null, getTheClass().getSimpleName(), arguments); newInstance.setMetaClass(this); return newInstance; } return adaptee.invokeConstructor(arguments); }
/** * Set the metaclass for a GroovyObject. * @param self the object whose metaclass we want to set * @param metaClass the new metaclass value * @since 2.0.0 */ public static void setMetaClass(GroovyObject self, MetaClass metaClass) { // this method was introduced as to prevent from a stack overflow, described in GROOVY-5285 if (metaClass instanceof HandleMetaClass) metaClass = ((HandleMetaClass)metaClass).getAdaptee(); self.setMetaClass(metaClass); disablePrimitiveOptimization(self); }
public static void setMetaClass(Object object, MetaClass metaClass) { GroovyObject groovyObject = ObjectUtil.asInstance(object, GroovyObject.class); if (groovyObject != null) { groovyObject.setMetaClass(metaClass); return; } ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).setMetaClass(object, metaClass); }
@Override public void customize(GroovyObject goo) { DelegatingMetaClass dmc = new DelegatingMetaClass(goo.getMetaClass()) { @Override public Object invokeMethod(Object arg0, String mName, Object[] arg2) { if (mName.contains("Missing")) { throw new IllegalStateException("Gotcha"); } else { return super.invokeMethod(arg0, mName, arg2); } } }; dmc.initialize(); goo.setMetaClass(dmc); } }
public void setMetaClass(final MetaClass metaClass) { this.wrapped.setMetaClass(metaClass); }
public void setMetaClass(final MetaClass metaClass) { this.wrapped.setMetaClass(metaClass); }
public void setMetaClass(final MetaClass metaClass) { this.wrapped.setMetaClass(metaClass); }
public void setMetaClass(final MetaClass metaClass) { this.wrapped.setMetaClass(metaClass); }
/** * Use the ProxyMetaClass for the given Closure. * Cares for balanced setting/unsetting ProxyMetaClass. * * @param closure piece of code to be executed with ProxyMetaClass */ public Object use(GroovyObject object, Closure closure) { // grab existing meta (usually adaptee but we may have nested use calls) MetaClass origMetaClass = object.getMetaClass(); object.setMetaClass(this); try { return closure.call(); } finally { object.setMetaClass(origMetaClass); } }
/** * Use the ProxyMetaClass for the given Closure. * Cares for balanced setting/unsetting ProxyMetaClass. * * @param closure piece of code to be executed with ProxyMetaClass */ public Object use(GroovyObject object, Closure closure) { // grab existing meta (usually adaptee but we may have nested use calls) MetaClass origMetaClass = object.getMetaClass(); object.setMetaClass(this); try { return closure.call(); } finally { object.setMetaClass(origMetaClass); } }
/** * Use the ProxyMetaClass for the given Closure. * Cares for balanced setting/unsetting ProxyMetaClass. * * @param closure piece of code to be executed with ProxyMetaClass */ public Object use(GroovyObject object, Closure closure) { // grab existing meta (usually adaptee but we may have nested use calls) MetaClass origMetaClass = object.getMetaClass(); object.setMetaClass(this); try { return closure.call(); } finally { object.setMetaClass(origMetaClass); } }
/** * Use the ProxyMetaClass for the given Closure. * Cares for balanced setting/unsetting ProxyMetaClass. * * @param closure piece of code to be executed with ProxyMetaClass */ public Object use(GroovyObject object, Closure closure) { // grab existing meta (usually adaptee but we may have nested use calls) MetaClass origMetaClass = object.getMetaClass(); object.setMetaClass(this); try { return closure.call(); } finally { object.setMetaClass(origMetaClass); } }
/** * Unlike general impl in superclass, ctors are not intercepted but relayed * unless interceptConstruction is set. */ public Object invokeConstructor(final Object[] arguments) { if (interceptConstruction && null == interceptor) throw new RuntimeException("cannot invoke constructor without interceptor"); if (interceptConstruction) { GroovyObject newInstance = (GroovyObject) interceptor.beforeInvoke(null, getTheClass().getSimpleName(), arguments); newInstance.setMetaClass(this); return newInstance; } return adaptee.invokeConstructor(arguments); }
/** * Unlike general impl in superclass, ctors are not intercepted but relayed * unless interceptConstruction is set. */ public Object invokeConstructor(final Object[] arguments) { if (interceptConstruction && null == interceptor) throw new RuntimeException("cannot invoke constructor without interceptor"); if (interceptConstruction) { GroovyObject newInstance = (GroovyObject) interceptor.beforeInvoke(null, getTheClass().getSimpleName(), arguments); newInstance.setMetaClass(this); return newInstance; } return adaptee.invokeConstructor(arguments); }
/** * Ensures the meta class is correct for a given class * * @param target The GroovyObject * @param persistentClass The persistent class */ public static void ensureCorrectGroovyMetaClass(Object target, Class<?> persistentClass) { if (target instanceof GroovyObject) { GroovyObject go = ((GroovyObject)target); if (!go.getMetaClass().getTheClass().equals(persistentClass)) { go.setMetaClass(GroovySystem.getMetaClassRegistry().getMetaClass(persistentClass)); } } }
/** * Ensures the meta class is correct for a given class * * @param target The GroovyObject * @param persistentClass The persistent class */ private static void ensureCorrectGroovyMetaClass(Object target, Class<?> persistentClass) { if (target instanceof GroovyObject) { GroovyObject go = ((GroovyObject)target); if (!go.getMetaClass().getTheClass().equals(persistentClass)) { go.setMetaClass(GroovySystem.getMetaClassRegistry().getMetaClass(persistentClass)); } } }
/** * Set the metaclass for an object * @param self the object whose metaclass we want to set * @param metaClass the new metaclass value * @since 1.6.0 */ public static void setMetaClass(Object self, MetaClass metaClass) { if (metaClass instanceof HandleMetaClass) metaClass = ((HandleMetaClass)metaClass).getAdaptee(); if (self instanceof GroovyObject) { ((GroovyObject)self).setMetaClass(metaClass); } else if (self instanceof Class) { ((MetaClassRegistryImpl)GroovySystem.getMetaClassRegistry()).setMetaClass((Class)self, metaClass); } else { ((MetaClassRegistryImpl)GroovySystem.getMetaClassRegistry()).setMetaClass(self, metaClass); } }
/** * Set the metaclass for an object * @param self the object whose metaclass we want to set * @param metaClass the new metaclass value * @since 1.6.0 */ public static void setMetaClass(Object self, MetaClass metaClass) { if (metaClass instanceof HandleMetaClass) metaClass = ((HandleMetaClass)metaClass).getAdaptee(); if (self instanceof GroovyObject) ((GroovyObject)self).setMetaClass(metaClass); else if (self instanceof Class) ((MetaClassRegistryImpl)GroovySystem.getMetaClassRegistry()).setMetaClass((Class)self, metaClass); else ((MetaClassRegistryImpl)GroovySystem.getMetaClassRegistry()).setMetaClass(self, metaClass); }