From: Jeff E. <jem...@fr...> - 2004-12-04 18:19:48
|
I understand now. I'm curious. In (P|J)ython classes are dynamic, and so are types. Java class signatures are static. How would you know to generate getFoo/setFoo methods for a Jython class? How would you know what type to use for the argument/return value in the generated getFoo/setFoo methods? I can imagine some syntax that would allow a compiler to generate methods, but it wouldn't be Python. I'm not familiar with the workings of jythonc to know whether you could somehow pre-process your Jython classes to automatically generate the get/set methods with signature comments before jythonc compiles them. Owen Densmore wrote: > Hi Jeff, thanks. This is a good summary of the cleaner Jython way to > get/set "properties" .. which are basically instance variables from > the Java point of view. > > But my interest was sorta the reverse: how to make Jython classes use > its nifty properties facility to implement the Java getter/setter > protocol automatically. (This is only necessary if your Jython > instances are being used by Java frameworks which expect the get/set > style. I have this a LOT!) > > In other words, I'd like to avoid building get/set methods in my > Jython class instances which are being used by a Java program as a > "bean". For this to work, there would have to be something that > automatically built get/set methods for classes (as Groovy does), or > there would have to be a run-time mechanism that sees a getFoo/setFoo > call and converts it to a simpler property usage. > > The whole point is this: Java is way, way too verbose. Groovy and a > few other scripting systems are trying to reduce this to make Java and > its platform independence more approachable by more people. Jython > does this, with the benefit of the rich Python tradition and well > crafted language. Getter/setters are part of the verbosity, Groovy > manages this, thus the natural question: how would Jython deal with > removing this "noise". > > Possibly the error handlers could do this? Or we could invent a new > function called "create_get_set_methods"? > > Owen > > On Dec 4, 2004, at 9:55 AM, Jeff Emanuel wrote: > >> >> http://www.jython.org/docs/properties.html >> See jython source org/python/core/PyJavaClass.java >> >> >> Owen Densmore wrote: >> >>> I'm using Jython within a Java framework which uses bean >>> getter/setters. Thus when I build a class in Jython to be used by >>> this framework, I need to build getter/setter methods in the Jython >>> class. >>> >>> My question is: is there a way to have Jython auto-generate these? >>> Groovy, for example, intercepts getter/setters from Java and >>> automatically converts them to property/attribute requests. I >>> presume because Jython has foo.var abbreviations, it might somehow >>> do a similar thing, removing the need for the annoying getter/setter >>> hand-made code. >>> >>> Owen >> > |
From: Samuele P. <ped...@bl...> - 2004-12-04 18:45:40
|
Jeff Emanuel wrote: > I understand now. I'm curious. In (P|J)ython classes are dynamic, and > so are types. Java > class signatures are static. How would you know to generate > getFoo/setFoo methods for > a Jython class? How would you know what type to use for the > argument/return value in > the generated getFoo/setFoo methods? I can imagine some syntax that > would allow a > compiler to generate methods, but it wouldn't be Python. I'm not > familiar with the workings > of jythonc to know whether you could somehow pre-process your Jython > classes to > automatically generate the get/set methods with signature comments > before jythonc compiles > them. You would need to build this on top of @sig like functionality in the interpreter. > > > > Owen Densmore wrote: > >> Hi Jeff, thanks. This is a good summary of the cleaner Jython way to >> get/set "properties" .. which are basically instance variables from >> the Java point of view. >> >> But my interest was sorta the reverse: how to make Jython classes use >> its nifty properties facility to implement the Java getter/setter >> protocol automatically. (This is only necessary if your Jython >> instances are being used by Java frameworks which expect the get/set >> style. I have this a LOT!) >> >> In other words, I'd like to avoid building get/set methods in my >> Jython class instances which are being used by a Java program as a >> "bean". For this to work, there would have to be something that >> automatically built get/set methods for classes (as Groovy does), or >> there would have to be a run-time mechanism that sees a getFoo/setFoo >> call and converts it to a simpler property usage. >> >> The whole point is this: Java is way, way too verbose. Groovy and a >> few other scripting systems are trying to reduce this to make Java and >> its platform independence more approachable by more people. Jython >> does this, with the benefit of the rich Python tradition and well >> crafted language. Getter/setters are part of the verbosity, Groovy >> manages this, thus the natural question: how would Jython deal with >> removing this "noise". >> >> Possibly the error handlers could do this? Or we could invent a new >> function called "create_get_set_methods"? >> >> Owen >> >> On Dec 4, 2004, at 9:55 AM, Jeff Emanuel wrote: >> >>> >>> http://www.jython.org/docs/properties.html >>> See jython source org/python/core/PyJavaClass.java >>> >>> >>> Owen Densmore wrote: >>> >>>> I'm using Jython within a Java framework which uses bean >>>> getter/setters. Thus when I build a class in Jython to be used by >>>> this framework, I need to build getter/setter methods in the Jython >>>> class. >>>> >>>> My question is: is there a way to have Jython auto-generate these? >>>> Groovy, for example, intercepts getter/setters from Java and >>>> automatically converts them to property/attribute requests. I >>>> presume because Jython has foo.var abbreviations, it might somehow >>>> do a similar thing, removing the need for the annoying getter/setter >>>> hand-made code. >>>> >>>> Owen >>> >>> >> > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Jython-dev mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-dev > |