@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); } } };
@Override public Object invokeStaticMethod(final Object object, final String name, final Object args[]) { try { return super.invokeStaticMethod(object, name, args); } catch (MissingMethodException mme) { return callGlobal(name, args, context); } } });
if (mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee() instanceof ExpandoMetaClass) { ((ExpandoMetaClass)((DelegatingMetaClass) mc).getAdaptee()).define(closure); return mc; if (mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee().getClass() == MetaClassImpl.class) { ExpandoMetaClass emc = new ExpandoMetaClass(self, false, true); emc.initialize(); emc.define(closure); ((DelegatingMetaClass) mc).setAdaptee(emc); return mc;
public void setProperty(String property, Object newValue) { try { getMetaClass().setProperty(this, property, newValue); } catch (MissingPropertyException e) { if (delegate instanceof GroovyObject) ((GroovyObject) delegate).setProperty(property, newValue); else throw e; } }
/** * Adds a "metaClass" property to all class objects so you can use the syntax * <code>String.metaClass.myMethod = { println "foo" }</code> * * @param c The java.lang.Class instance * @return An MetaClass instance * @since 1.5.0 */ public static MetaClass getMetaClass(Class c) { MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry(); MetaClass mc = metaClassRegistry.getMetaClass(c); if (mc instanceof ExpandoMetaClass || mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee() instanceof ExpandoMetaClass) return mc; else { return new HandleMetaClass(mc); } }
@Override public Object getProperty(Object object, String property) { if (object instanceof NodeList) { NodeList nl = (NodeList) object; return nl.getAt(property); } return super.getProperty(object, property); } };
public String toString() { return super.toString() + "[" + delegate.toString()+ "]"; }
public boolean equals(Object obj) { return super.equals(obj) || getAdaptee().equals(obj) || (obj instanceof HandleMetaClass && equals(((HandleMetaClass)obj).getAdaptee())); }
public Object getProperty(String property) { try { return getMetaClass().getProperty(this, property); } catch (MissingPropertyException e) { if (delegate instanceof GroovyObject) return ((GroovyObject) delegate).getProperty(property); else throw e; } }
if (emc instanceof DelegatingMetaClass && ((DelegatingMetaClass)emc).getAdaptee() instanceof ExpandoMetaClass) { ((ExpandoMetaClass)((DelegatingMetaClass)emc).getAdaptee()).define(closure); return emc;
@Override public Object getProperty(Object object, String property) { if (object instanceof Node) { Node n = (Node) object; return n.get(property); } return super.getProperty(object, property); }
public String toString() { return super.toString() + "[" + delegate.toString()+ "]"; }
public boolean equals(Object obj) { return super.equals(obj) || getAdaptee().equals(obj) || (obj instanceof HandleMetaClass && equals(((HandleMetaClass)obj).getAdaptee())); } }
@Override public Object invokeMethod(Object object, String methodName, Object[] args) { if (object instanceof Relationship) { if ("leftShift".equals(methodName) && args.length == 1) { if (args[0] instanceof SessionFile) { return this.leftShift((Relationship) object, (SessionFile) args[0]); } else if (args[0] instanceof Collection) { return this.leftShift((Relationship) object, (Collection) args[0]); } } } return super.invokeMethod(object, methodName, args); }
@Override public Object invokeStaticMethod(Object object, String name, Object[] args) { try { return super.invokeStaticMethod(object, name, args); } catch (MissingMethodException mme) { return callGlobal(name, args, ctx); } } });
public Object invokeMethod(String name, Object args) { try { return getMetaClass().invokeMethod(this, name, args); } catch (MissingMethodException e) { if (delegate instanceof GroovyObject) return ((GroovyObject) delegate).invokeMethod(name, args); else throw e; } }
if (mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee() instanceof ExpandoMetaClass) { ((ExpandoMetaClass)((DelegatingMetaClass) mc).getAdaptee()).define(closure); return mc; if (mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee().getClass() == MetaClassImpl.class) { ExpandoMetaClass emc = new ExpandoMetaClass(self, false, true); emc.initialize(); emc.define(closure); ((DelegatingMetaClass) mc).setAdaptee(emc); return mc;
if (self instanceof DelegatingMetaClass && ((DelegatingMetaClass) self).getAdaptee() instanceof ExpandoMetaClass) { self = ((DelegatingMetaClass) self).getAdaptee(); } else { throw new GroovyRuntimeException("Can't mixin methods to meta class: " + self);
@Override public Object getProperty(Object object, String property) { if (object instanceof Node) { Node n = (Node) object; return n.get(property); } return super.getProperty(object, property); }
public String toString() { return super.toString() + "[" + delegate.toString()+ "]"; }