Tuning the Java to Ruby method name translator

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Tuning the Java to Ruby method name translator

Alex jimmy Montaño fuentes
Is there any way to tune the translator that turns Java-formatted method
names into Ruby-formatted method names? I'm using JAXB-generated classes
for an XML schema to create Ruby bindings and am encountering cases
where the translation is very unintuitive.

For example, "getIndicatedTTPs" is getting turned into
"get_indicated_tt_ps" when I would prefer something like
"get_indicated_ttps".

Obviously I can solve this as a one-off by aliasing the method but "TTP"
is a common term throughout the schema (and therefore the generated
content) so I'd rather just tell it to turn "TTPs" into "ttps" as a
global case.

I briefly looked through the JRuby code and Googled but wasn't able to
find any easy way to hook into it to do this.

Thanks!

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tuning the Java to Ruby method name translator

amiracam
but you can also call it with the original method name, right ? I'm missing something , what translator do you mean ? I figured jruby did the match at invocation time , does Jruby actually insert new method keys in the method dictionary on the Java proxy class to accommodate for the snake style method naming convention ? Just curious

Charles

On Oct 8, 2013, at 9:26 AM, John W. <[hidden email]> wrote:

> Is there any way to tune the translator that turns Java-formatted method
> names into Ruby-formatted method names? I'm using JAXB-generated classes
> for an XML schema to create Ruby bindings and am encountering cases
> where the translation is very unintuitive.
>
> For example, "getIndicatedTTPs" is getting turned into
> "get_indicated_tt_ps" when I would prefer something like
> "get_indicated_ttps".
>
> Obviously I can solve this as a one-off by aliasing the method but "TTP"
> is a common term throughout the schema (and therefore the generated
> content) so I'd rather just tell it to turn "TTPs" into "ttps" as a
> global case.
>
> I briefly looked through the JRuby code and Googled but wasn't able to
> find any easy way to hook into it to do this.
>
> Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tuning the Java to Ruby method name translator

Alex jimmy Montaño fuentes
In reply to this post by Alex jimmy Montaño fuentes
Yes, you can still call it with the original method name (as well as the
poorly translated name). So it's not "broken" per se, but I'm developing
a library for others to use and would like to give them a clean and
consistent Ruby-style interface.

I can't profess to know much about the internals of JRuby but if you
inspect an instance of a Java proxy class it has both the original
Java-style methods and the translated Ruby-style methods defined.

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tuning the Java to Ruby method name translator

keithrbennett
In reply to this post by amiracam
Charles -

I posted a pry session at https://gist.github.com/keithrbennett/6912655 that shows a Java class (java.util.Locale).  Note the default=, which is a Rubified version of setDefault.  It's interesting that setDefault is not listed there, although it works, as shown in the pry session.  Anyway, to answer your question, it's not done at invocation time.

- Keith


On Oct 8, 2013, at 7:52 PM, Charles Monteiro <[hidden email]> wrote:

> but you can also call it with the original method name, right ? I'm missing something , what translator do you mean ? I figured jruby did the match at invocation time , does Jruby actually insert new method keys in the method dictionary on the Java proxy class to accommodate for the snake style method naming convention ? Just curious
>
> Charles
>
> On Oct 8, 2013, at 9:26 AM, John W. <[hidden email]> wrote:
>
>> Is there any way to tune the translator that turns Java-formatted method
>> names into Ruby-formatted method names? I'm using JAXB-generated classes
>> for an XML schema to create Ruby bindings and am encountering cases
>> where the translation is very unintuitive.
>>
>> For example, "getIndicatedTTPs" is getting turned into
>> "get_indicated_tt_ps" when I would prefer something like
>> "get_indicated_ttps".
>>
>> Obviously I can solve this as a one-off by aliasing the method but "TTP"
>> is a common term throughout the schema (and therefore the generated
>> content) so I'd rather just tell it to turn "TTPs" into "ttps" as a
>> global case.
>>
>> I briefly looked through the JRuby code and Googled but wasn't able to
>> find any easy way to hook into it to do this.
>>
>> Thanks!
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tuning the Java to Ruby method name translator

Christian MICHON
"It's interesting that setDefault is not listed there, although it works, as shown in the pry session"

Well, this seems to be a side effect of pry only (like pry applying some smart filter in case of java setters/getters?)...

If you try this (in a similar session pry session, but _not_ using pry 'ls'), you'll see it should be listed:

[10] pry(Java::JavaUtil::Locale):1> methods.grep /default/i
=> ["set_default",
 "default",
 "setDefault",
 "init_default",
 "default=",
 "getDefault",
 "initDefault",
 "get_default"]



On Thu, Oct 10, 2013 at 5:42 AM, Keith Bennett <[hidden email]> wrote:
Charles -

I posted a pry session at https://gist.github.com/keithrbennett/6912655 that shows a Java class (java.util.Locale).  Note the default=, which is a Rubified version of setDefault.  It's interesting that setDefault is not listed there, although it works, as shown in the pry session.  Anyway, to answer your question, it's not done at invocation time.

- Keith


On Oct 8, 2013, at 7:52 PM, Charles Monteiro <[hidden email]> wrote:

> but you can also call it with the original method name, right ? I'm missing something , what translator do you mean ? I figured jruby did the match at invocation time , does Jruby actually insert new method keys in the method dictionary on the Java proxy class to accommodate for the snake style method naming convention ? Just curious
>
> Charles
>
> On Oct 8, 2013, at 9:26 AM, John W. <[hidden email]> wrote:
>
>> Is there any way to tune the translator that turns Java-formatted method
>> names into Ruby-formatted method names? I'm using JAXB-generated classes
>> for an XML schema to create Ruby bindings and am encountering cases
>> where the translation is very unintuitive.
>>
>> For example, "getIndicatedTTPs" is getting turned into
>> "get_indicated_tt_ps" when I would prefer something like
>> "get_indicated_ttps".
>>
>> Obviously I can solve this as a one-off by aliasing the method but "TTP"
>> is a common term throughout the schema (and therefore the generated
>> content) so I'd rather just tell it to turn "TTPs" into "ttps" as a
>> global case.
>>
>> I briefly looked through the JRuby code and Googled but wasn't able to
>> find any easy way to hook into it to do this.
>>
>> Thanks!
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
Christian
Reply | Threaded
Open this post in threaded view
|

Re: Tuning the Java to Ruby method name translator

amiracam
In reply to this post by keithrbennett
thanks

So I guess when one utilizes an external jar , Jruby must at least lazily cache the selectors.


Charles



On Oct 9, 2013, at 11:42 PM, Keith Bennett <[hidden email]> wrote:

> Charles -
>
> I posted a pry session at https://gist.github.com/keithrbennett/6912655 that shows a Java class (java.util.Locale).  Note the default=, which is a Rubified version of setDefault.  It's interesting that setDefault is not listed there, although it works, as shown in the pry session.  Anyway, to answer your question, it's not done at invocation time.
>
> - Keith
>
>
> On Oct 8, 2013, at 7:52 PM, Charles Monteiro <[hidden email]> wrote:
>
>> but you can also call it with the original method name, right ? I'm missing something , what translator do you mean ? I figured jruby did the match at invocation time , does Jruby actually insert new method keys in the method dictionary on the Java proxy class to accommodate for the snake style method naming convention ? Just curious
>>
>> Charles
>>
>> On Oct 8, 2013, at 9:26 AM, John W. <[hidden email]> wrote:
>>
>>> Is there any way to tune the translator that turns Java-formatted method
>>> names into Ruby-formatted method names? I'm using JAXB-generated classes
>>> for an XML schema to create Ruby bindings and am encountering cases
>>> where the translation is very unintuitive.
>>>
>>> For example, "getIndicatedTTPs" is getting turned into
>>> "get_indicated_tt_ps" when I would prefer something like
>>> "get_indicated_ttps".
>>>
>>> Obviously I can solve this as a one-off by aliasing the method but "TTP"
>>> is a common term throughout the schema (and therefore the generated
>>> content) so I'd rather just tell it to turn "TTPs" into "ttps" as a
>>> global case.
>>>
>>> I briefly looked through the JRuby code and Googled but wasn't able to
>>> find any easy way to hook into it to do this.
>>>
>>> Thanks!
>>>
>>> --
>>> Posted via http://www.ruby-forum.com/.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>  http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email