1 package org
.jruby
.javasupport
;
4 import org
.jruby
.RubyClass
;
5 import org
.jruby
.RubyModule
;
6 import org
.jruby
.RubyObject
;
7 import org
.jruby
.anno
.JRubyMethod
;
8 import org
.jruby
.javasupport
.util
.RuntimeHelpers
;
9 import org
.jruby
.runtime
.Block
;
10 import org
.jruby
.runtime
.CallType
;
11 import org
.jruby
.runtime
.ThreadContext
;
12 import org
.jruby
.runtime
.builtin
.IRubyObject
;
14 public class JavaProxyMethods
{
15 public static RubyModule
createJavaProxyMethods(ThreadContext context
) {
16 Ruby runtime
= context
.getRuntime();
17 RubyModule javaProxyMethods
= runtime
.defineModule("JavaProxyMethods");
19 javaProxyMethods
.addReadWriteAttribute(context
, "java_object");
21 javaProxyMethods
.defineAnnotatedMethods(JavaProxyMethods
.class);
23 return javaProxyMethods
;
27 public static IRubyObject
java_class(ThreadContext context
, IRubyObject recv
) {
28 RubyClass metaClass
= recv
.getMetaClass();
29 // TODO: can't we dig this out without a method call?
30 return RuntimeHelpers
.invoke(context
, metaClass
, "java_class");
33 @JRubyMethod(name
= {"=="})
34 public static IRubyObject
op_equal(IRubyObject recv
, IRubyObject rhs
) {
35 return ((JavaObject
)recv
.dataGetStruct()).op_equal(rhs
);
39 public static IRubyObject
to_s(IRubyObject recv
) {
40 if(recv
.dataGetStruct() != null) {
41 return ((JavaObject
)recv
.dataGetStruct()).to_s();
43 return ((RubyObject
)recv
).to_s();
47 @JRubyMethod(name
= "eql?")
48 public static IRubyObject
op_eql(IRubyObject recv
, IRubyObject rhs
) {
49 return ((JavaObject
)recv
.dataGetStruct()).op_equal(rhs
);
53 public static IRubyObject
hash(IRubyObject recv
) {
54 return ((JavaObject
)recv
.dataGetStruct()).hash();
58 public static IRubyObject
to_java_object(IRubyObject recv
) {
59 return (JavaObject
)recv
.dataGetStruct();
62 @JRubyMethod(name
= "synchronized")
63 public static IRubyObject
rbSynchronized(ThreadContext context
, IRubyObject recv
, Block block
) {
64 return ((JavaObject
)recv
.dataGetStruct()).ruby_synchronized(context
, block
);