Description
Traits don't take into account closure delegates, this completely breaks any builder or dynamic behaviour. The following example:
import groovy.xml.* trait MyBuilder { def build2() { def mkp = new MarkupBuilder() mkp.foo { bar() } } } class Foo implements MyBuilder { def build1() { def mkp = new MarkupBuilder() mkp.foo { bar() } } } foo = new Foo() foo.build1() foo.build2()
Fails with:
roovy.lang.MissingMethodException: No signature of method: Foo.bar() is applicable for argument types: () values: [] Possible solutions: wait(), any(), wait(long), use([Ljava.lang.Object;), any(groovy.lang.Closure), is(java.lang.Object) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:56) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114) at MyBuilder$Trait$Helper$_build2_closure1.doCall(ConsoleScript1:8) at MyBuilder$Trait$Helper$_build2_closure1.doCall(ConsoleScript1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:292) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016) at groovy.lang.Closure.call(Closure.java:423) at groovy.lang.Closure.call(Closure.java:417) at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:143) at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122) at MyBuilder$Trait$Helper.build2(ConsoleScript1:7)