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

Eric Milles commented on GROOVY-10392:
--------------------------------------

I'm not sure why static properties and methods exist for MetaClass.  If this 
feature was taken away, then there would be no requirement for consistency.

For purposes of your example, why does the property need to be static.  If a 
call from any instance always returned the same value, would your expectations 
be met?  Why the rush to make it static?  (As an aside, I'm not sure why so 
many tutorials point to dynamic enhancements so quickly.)

{code:groovy}
Integer number = 1
num.metaClass.getSomething = { -> 'some value' }
// or Integer.metaClass.getSomething = { -> 'some value' }
assert number.something == 'some value'
{code}

This still gives me no insight into what is trying to be achieved.  If this is 
a script, the binding can be used in some instances to provide values.  
Category methods can be added to make "something" available as a property of 
Integer or Number or whatever.  Then there is BaseScript and other means for 
enhancing the script experience.

I agree there are a number of features that are not complete or that don't 
integrate with other features.  It has been increasingly difficult to try and 
work to bring consistency to existing features when nothing is allowed to be 
removed and there is still a thrust to add new features at a very quick pace.

I have fixed many hundred of issues like this one over the last couple years 
and there are still nearly 1300 open tickets, so I need to try and prioritize.  
I would like to understand beyond the immediate why something is required.  If 
static meta properties are not fully formed, I still need to understand why 
they are needed before I can put any effort into them.  If they are retained 
for legacy compatibility but have been replaced by traits or something else, 
then I would choose to try and make that feature as sound as it can be.

> 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