groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ocs@ocs" <...@ocs.cz>
Subject metaclass getProperty does not work at all (2.4) (was: suggestion: ImplicitSafeNavigation annotation)
Date Thu, 16 Aug 2018 09:58:52 GMT
Jochen,

> On 15 Aug 2018, at 10:13 AM, Jochen Theodorou <blackdrag@gmx.org> wrote:
> have to do the same treatment for get/setProperty

I have tried repeatedly, but the thing simply does not work :( Any idea why?

===
585 /tmp> <q.groovy 
class q {
    static main(args) {
        def mc=new XMC(q)
        mc.initialize()
        q.metaClass=mc

        def qq=newInstance()
        println "mc used: "+qq.method()
        println "mc NOT used?!?: "+qq.prop
    }
    def method() { return 'm' }
    def prop='p'
}
class XMC extends DelegatingMetaClass {
    XMC(Class clazz) { super(clazz) }
    Object invokeMethod(Object object, String methodName, Object[] arguments) {
        println "invoking '$methodName' for $object"
        super.invokeMethod(object,methodName,arguments)
    }
    Object getProperty(Class sender, Object receiver, String property, boolean isCallToSuper,
boolean fromInsideClass) {
        println "getting property '$property' for $receiver"
        super.getProperty(sender,receiver,property,isCallToSuper,fromInsideClass)
    }
}
586 /tmp> /usr/local/groovy-2.4.15/bin/groovy q
WARNING: An illegal reflective access operation has occurred
...
invoking 'method' for q@77102b91
mc used: m
mc NOT used?!?: p
587 /tmp> 
===

Thanks,
OC



Mime
View raw message