As I understand it, methodMissing / propertyMissing don't really work on
inner classes as things are currently designed. You might find these
helpful
http://stackoverflow.com/questions/12222944/how-do-i-delegate-methodmissing-calls-to-nested-classes
https://issues.apache.org/jira/browse/GROOVY-4862
At some point we might improve the implementation, but I doubt it'll be any
time soon.
-Keegan
On Mon, Jul 27, 2015 at 8:07 AM, Fernando Ariel Niwes Naufal <
fernando@soluciones3f.com.ar> wrote:
> I am not sure if the following code should, or should not work. As right
> now, with Groovy Version: 2.4.3 JVM: 1.8.0_31 Vendor: Oracle Corporation
> OS: Mac OS X does not.
>
> class OuterClass {
> class DelegateClass {
> def calls = [:]
> def methodMissing(String value, args) { calls[value] = args;
> return this }
> }
>
> def run() {
> def closure = { method1 'calling1' method2 'calling2' }
>
> def delegate = new DelegateClass()
> closure.delegate = delegate
> closure()
>
> return delegate.calls
> }
> }
>
> assert new OuterClass().run() == [method1: ['calling1'], method2:
> ['calling2']]
>
> The same code, but with DelegateClass as a independent class does works
> correctly.
> Even more, if I replace methodMissing with two methods called method1, and
> method2 does works correctly too.
>
> Seems like a bug to me (specially because it fails only with
> methodMissing) but I am not sure.
>
>
|