Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / src / org / jruby / javasupport / JavaProxyMethods.java
blobe901a346f5e23c1350b59452c85476a67df43d75
1 package org.jruby.javasupport;
3 import org.jruby.Ruby;
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;
26 @JRubyMethod
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);
38 @JRubyMethod
39 public static IRubyObject to_s(IRubyObject recv) {
40 if(recv.dataGetStruct() != null) {
41 return ((JavaObject)recv.dataGetStruct()).to_s();
42 } else {
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);
52 @JRubyMethod
53 public static IRubyObject hash(IRubyObject recv) {
54 return ((JavaObject)recv.dataGetStruct()).hash();
57 @JRubyMethod
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);