[
https://issues.apache.org/jira/browse/GROOVY-10392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17468744#comment-17468744
]
William Woodman commented on GROOVY-10392:
------------------------------------------
Eric - happy new year.
i'd got into this when i was looking at how i could use MicroStream for
persisting graph of objects. This was in early December - i was looking to use
some of the dynamic features of metaClass or expando to help me whilst i though
about how best i wanted to structure this. Essentially i wanted the persisted
graphs to be static - so that any instance of Database would persist one graph
of objects, so there can be many local working copies of database for any
thread looking to persist data - but the actual tree would be one across all.
This got me started with trying to create a static map as dataroot to persist
all data and static maps for all of one class
this is no where near ready to go - but i've attached that playpen project.
however whilst trying to do this i ran into these issues relating to
metaClass.static, or Expando and finding they didnt expect as i might have
expected for static variables
I was at this point that raised the enhancement request to try and address some
or the asymmetries in the MOP. Whilst these can all be worked around and there
are other ways to address what i was trying to do - however the groovy dynamic
features was i thought a good place to me to start from and then rand into all
these issues. I'm going to go back into this project sometime soon but i need
to approach some of the basics with different approaches.
this diverted me off into what was happening and why it didnt seem to work.
This ended up in knocking up the WillsExpando to try and show what i might have
expected to see rather than current actual experience
in the end of the day a programmer is trying to do some or other project and
hopes to find the tool bag to contain standard spanners etc that dont have
mixed imperial vs metric end etc. That's what this felt like. You have an
expectation of how static and non static variables should work (whether an
ordinary class or a metaClass) and this just didn't seem to be so hence the
request to (in the background) to improve this consistency
https://github.com/woodmawa/MicroStreamDB-SampleApp/tree/master/src/main/groovy/com/softwood
https://microstream.one/
> 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)