Callback mechanism doesn't support static Java implementation of Ruby instance
method
-------------------------------------------------------------------------------------
Key: JRUBY-2172
URL: http://jira.codehaus.org/browse/JRUBY-2172
Project: JRuby
Issue Type: Improvement
Components: Core Classes/Modules
Reporter: Bill Dortch
Priority: Critical
Fix For: JRuby 1.1+
The JRuby callback mechanism doesn't support static Java implementations of
Ruby instance methods. (Actually, it does in one place: ReflectionCallback
takes an isStaticMethod parameter, but you can't specify it through a
CallbackFactory, and in general static impls of instance methods don't seem to
be supported).
This prevents us from easily defining method implementations in a single place
without resorting to subclassing. We can live without this capability for 1.1,
but we'll absolutely need it after that if we are to break out of the
RubyObject class hierarchy stranglehold and support things like lightweights
and external ivars. (For instance, all (Ruby) Object methods will need to be
implemented statically; Ruby inheritance will not imply Java implementation
inheritance.)
Here's what I was trying to do today: Add java.lang.reflect.Member methods to
methods/fields/ctors without defining them separately for each, or interposing
yet another abstract subclass. Here's what it looks like (it's short, so I'll
just include the whole thing):
{code}
package org.jruby.javasupport;
import java.lang.reflect.Member;
import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.runtime.CallbackFactory;
import org.jruby.runtime.builtin.IRubyObject;
public class MemberMethods {
public static IRubyObject declaring_class(IRubyObject self) {
return Java.getInstance(self.getRuntime(),
((Member)((JavaObject)self).getValue()).getDeclaringClass());
}
public static IRubyObject modifiers(IRubyObject self) {
return
self.getRuntime().newFixnum(((Member)((JavaObject)self).getValue()).getModifiers());
}
public static IRubyObject name(IRubyObject self) {
return
self.getRuntime().newString(((Member)((JavaObject)self).getValue()).getName());
}
public static IRubyObject synthetic_p(IRubyObject self) {
return
self.getRuntime().newBoolean(((Member)((JavaObject)self).getValue()).isSynthetic());
}
public static void defineMemberMethods(Ruby runtime, RubyModule module) {
CallbackFactory factory = runtime.callbackFactory(MemberMethods.class);
module.defineFastMethod("declaring_class",
factory.getFastMethod("declaring_class"));
module.defineFastMethod("modifiers",
factory.getFastMethod("modifiers"));
module.defineFastMethod("name", factory.getFastMethod("name"));
module.defineFastMethod("synthetic?",
factory.getFastMethod("synthetic_p"));
}
}
{code}
Then, in (for example) JavaConstructor:
{code}
RubyClass result = javaModule.defineClassUnder("JavaConstructor", ...);
CallbackFactory callbackFactory =
runtime.callbackFactory(JavaConstructor.class);
//...
result.defineFastMethod( ...);
MemberMethods.defineMemberMethods(runtime, result);
{code}
I can work around this today, but we won't be able to down the road.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email