1 29 package org.jruby.javasupport; 30 31 import java.lang.reflect.AccessibleObject ; 32 33 import org.jruby.Ruby; 34 import org.jruby.RubyBoolean; 35 import org.jruby.RubyClass; 36 import org.jruby.RubyObject; 37 import org.jruby.runtime.CallbackFactory; 38 import org.jruby.runtime.builtin.IRubyObject; 39 40 public abstract class JavaAccessibleObject extends RubyObject { 41 42 protected JavaAccessibleObject(Ruby runtime, RubyClass rubyClass) { 43 super(runtime, rubyClass); 44 } 45 46 public static void registerRubyMethods(Ruby runtime, RubyClass result) { 47 CallbackFactory callbackFactory = runtime.callbackFactory(JavaAccessibleObject.class); 48 49 result.defineFastMethod("accessible?", callbackFactory.getFastMethod("isAccessible")); 50 result.defineFastMethod("accessible=", callbackFactory.getFastMethod("setAccessible", IRubyObject.class)); 51 } 52 protected abstract AccessibleObject accesibleObject(); 53 54 public RubyBoolean isAccessible() { 55 return new RubyBoolean(getRuntime(),accesibleObject().isAccessible()); 56 } 57 58 public IRubyObject setAccessible(IRubyObject object) { 59 accesibleObject().setAccessible(object.isTrue()); 60 return object; 61 } 62 63 } 64 | Popular Tags |