[ 
https://issues.apache.org/jira/browse/GROOVY-10392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17472134#comment-17472134
 ] 

William Woodman commented on GROOVY-10392:
------------------------------------------

ok - i've tidied up the sample project a little as follows 

 

latest WillsMetaClass is now here 
[https://github.com/woodmawa/GroovyV4sample/blob/master/src/main/groovy/mop/WillsMetaClass.java]

 

staticExpandoProperty as before is here (this creates the static getter/setters 
along with the backing map entries) 
[https://github.com/woodmawa/GroovyV4sample/blob/master/src/main/groovy/mop/StaticExpandoProperty.groovy]

 

tried to right some tests to show its working as it should 

[https://github.com/woodmawa/GroovyV4sample/blob/master/src/test/groovy/mop/WillsMetaClassTest.groovy]

 

and a couple of tests for the new StaticExpandoProperty 

[https://github.com/woodmawa/GroovyV4sample/blob/master/src/test/groovy/mop/StaticExpandoPropertyTest.groovy]

 

not a complete guarantee that i've followed all the behaviour checks full 
rebuild back into core code stream.  there is alot of convoluted code in 
expandoMetaClass and metaClassImpl, so its very easy to get lost so i didnt 
want to go to far down the rabbit hole 

 

however this is the basic fix for what i felt is inconsistent behaviour that 
current ExpandoMetaClass does when you try and work with metaClass.'static'.  I 
feel this is somewhat closer and behaves as you'd expect things to at a 
semantic level 

 

I hope this helps 

 

regards Will 

 

 

> Inconsistent metaClass capability for .static properties and methods vs 
> ordinary dynamic properties and methods  
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10392
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10392
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler
>    Affects Versions: 3.0.9, 4.0.0-beta-2
>            Reporter: William Woodman
>            Priority: Minor
>             Fix For: 3.x, 4.x
>
>
> runtime addition and working with static dynamic properties and methods is 
> inconsistent and doesnt work the same as the equivalent capability for 
> ordinary dynamic properties and methods.
> I've tried to show the problem in the script code below 
> {code:groovy}
> package script
> class SomeClass {
> static String classDeclaredStatName = "in class definition static name"
> String name = "instance level name"
> }
> //add a new property to metaclass - works fine
> SomeClass.metaClass.dynProp = "dynamic property added"
> SomeClass.metaClass.dynMethod = \{"dynamic method added as closure"}
> SomeClass.metaClass.static.dynStaticProp = "dynamic static property added"
> SomeClass.metaClass.static.dynStaticMethod = \{"dynamic static method added"}
> assert SomeClass.classDeclaredStatName == "in class definition static name"
> assert SomeClass.dynStaticMethod() == "dynamic static method added"
> //this forces conversion of metaClassImpl to expandoMetaClass
> SomeClass myc = new SomeClass()
> assert myc.name == "instance level name"
> assert myc.classDeclaredStatName == "in class definition static name"
> assert myc.dynProp == "dynamic property added"
> assert myc.dynMethod() == "dynamic method added as closure"
> assert myc.dynStaticMethod() == "dynamic static method added"
> def res
> res = myc.metaClass.properties //returns list of metaBeanProperty
> res = myc.metaClass.getMetaMethods() //works and returns list of metaMethods
> //This is the only method for static's in MOP - this works but you have to 
> know the name of the method in advance
> res = myc.metaClass.getStaticMetaMethod("dynStaticMethod", [] as ArrayList)
> //these functions are missing from MOP and would enable you to query for 
> static props/methods 
> res = myc.metaClass.getStaticMetaMethods()     //this method doesnt exist in 
> MOP api
> res = myc.metaClass.getStaticProperties()           //this method doesnt 
> exist in MOP api either
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to