3939import org .jruby .RubyObject ;
4040import org .jruby .RubyString ;
4141import org .jruby .anno .JRubyMethod ;
42+ import org .jruby .runtime .ThreadContext ;
4243import org .jruby .runtime .builtin .IRubyObject ;
4344
4445public abstract class JavaAccessibleObject extends RubyObject {
@@ -69,25 +70,25 @@ public int hashCode() {
6970 }
7071
7172 @ JRubyMethod
72- public RubyFixnum hash () {
73- return getRuntime () .newFixnum (hashCode ());
73+ public RubyFixnum hash (ThreadContext context ) {
74+ return context . runtime .newFixnum (hashCode ());
7475 }
7576
7677 @ JRubyMethod (name = {"==" , "eql?" })
77- public RubyBoolean op_equal (final IRubyObject other ) {
78- return RubyBoolean .newBoolean (getRuntime () , equals (other ));
78+ public RubyBoolean op_equal (ThreadContext context , final IRubyObject other ) {
79+ return RubyBoolean .newBoolean (context . runtime , equals (other ));
7980 }
8081
8182 @ JRubyMethod (name = "equal?" )
82- public RubyBoolean same (final IRubyObject other ) {
83+ public RubyBoolean same (ThreadContext context , final IRubyObject other ) {
8384 final boolean same = other instanceof JavaAccessibleObject && same ((JavaAccessibleObject ) other );
84- return same ? getRuntime (). getTrue () : getRuntime () .getFalse ();
85+ return same ? context . runtime . getTrue () : context . runtime .getFalse ();
8586 }
8687
8788 @ JRubyMethod (name = "accessible?" )
8889 @ Deprecated
89- public RubyBoolean isAccessible () {
90- return RubyBoolean .newBoolean (getRuntime () , accessibleObject ().isAccessible ());
90+ public RubyBoolean isAccessible (ThreadContext context ) {
91+ return RubyBoolean .newBoolean (context . runtime , accessibleObject ().isAccessible ());
9192 }
9293
9394 @ JRubyMethod (name = "accessible=" )
@@ -98,72 +99,80 @@ public IRubyObject setAccessible(IRubyObject object) {
9899
99100 @ SuppressWarnings ("unchecked" )
100101 @ JRubyMethod
101- public IRubyObject annotation (final IRubyObject annoClass ) {
102- if ( ! ( annoClass instanceof JavaClass ) ) {
103- throw getRuntime ().newTypeError (annoClass , getRuntime ().getJavaSupport ().getJavaClassClass ());
102+ public IRubyObject annotation (ThreadContext context , final IRubyObject annoClass ) {
103+ final Class annotation ;
104+ if (annoClass instanceof RubyClass && ((RubyClass ) annoClass ).getJavaProxy ()) {
105+ annotation = ((RubyClass ) annoClass ).getJavaClass ();
106+ } else if (annoClass instanceof JavaClass ) {
107+ annotation = ((JavaClass ) annoClass ).javaClass ();
108+ } else {
109+ throw context .runtime .newTypeError ("expected a Java (proxy) class, got: " + annoClass );
104110 }
105- final Class annotation = ((JavaClass ) annoClass ).javaClass ();
106- return Java .getInstance (getRuntime (), accessibleObject ().getAnnotation (annotation ));
111+ return Java .getInstance (context .runtime , accessibleObject ().getAnnotation (annotation ));
107112 }
108113
109114 @ JRubyMethod
110- public IRubyObject annotations () {
111- return Java .getInstance (getRuntime () , accessibleObject ().getAnnotations ());
115+ public IRubyObject annotations (ThreadContext context ) {
116+ return Java .getInstance (context . runtime , accessibleObject ().getAnnotations ());
112117 }
113118
114119 @ JRubyMethod (name = "annotations?" )
115- public RubyBoolean annotations_p () {
116- return getRuntime () .newBoolean (accessibleObject ().getAnnotations ().length > 0 );
120+ public RubyBoolean annotations_p (ThreadContext context ) {
121+ return context . runtime .newBoolean (accessibleObject ().getAnnotations ().length > 0 );
117122 }
118123
119124 @ JRubyMethod
120- public IRubyObject declared_annotations () {
121- return Java .getInstance (getRuntime () , accessibleObject ().getDeclaredAnnotations ());
125+ public IRubyObject declared_annotations (ThreadContext context ) {
126+ return Java .getInstance (context . runtime , accessibleObject ().getDeclaredAnnotations ());
122127 }
123128
124129 @ JRubyMethod (name = "declared_annotations?" )
125- public RubyBoolean declared_annotations_p () {
126- return getRuntime () .newBoolean (accessibleObject ().getDeclaredAnnotations ().length > 0 );
130+ public RubyBoolean declared_annotations_p (ThreadContext context ) {
131+ return context . runtime .newBoolean (accessibleObject ().getDeclaredAnnotations ().length > 0 );
127132 }
128133
129134 @ SuppressWarnings ("unchecked" )
130135 @ JRubyMethod (name = "annotation_present?" )
131- public IRubyObject annotation_present_p (final IRubyObject annoClass ) {
132- if ( ! ( annoClass instanceof JavaClass ) ) {
133- throw getRuntime ().newTypeError (annoClass , getRuntime ().getJavaSupport ().getJavaClassClass ());
136+ public IRubyObject annotation_present_p (ThreadContext context , final IRubyObject annoClass ) {
137+ final Class annotation ;
138+ if (annoClass instanceof RubyClass && ((RubyClass ) annoClass ).getJavaProxy ()) {
139+ annotation = ((RubyClass ) annoClass ).getJavaClass ();
140+ } else if (annoClass instanceof JavaClass ) {
141+ annotation = ((JavaClass ) annoClass ).javaClass ();
142+ } else {
143+ throw context .runtime .newTypeError ("expected a Java (proxy) class, got: " + annoClass );
134144 }
135- final Class annotation = ((JavaClass ) annoClass ).javaClass ();
136- return getRuntime ().newBoolean ( accessibleObject ().isAnnotationPresent (annotation ) );
145+ return context .runtime .newBoolean ( accessibleObject ().isAnnotationPresent (annotation ) );
137146 }
138147
139148 // for our purposes, Accessibles are also Members, and vice-versa,
140149 // so we'll include Member methods here.
141150 @ JRubyMethod
142151 @ SuppressWarnings ("deprecation" )
143- public IRubyObject declaring_class () {
152+ public IRubyObject declaring_class (ThreadContext context ) {
144153 Class <?> clazz = ((Member ) accessibleObject ()).getDeclaringClass ();
145- if ( clazz != null ) return JavaClass . get ( getRuntime () , clazz );
146- return getRuntime () .getNil ();
154+ if ( clazz != null ) return Java . getProxyClass ( context . runtime , clazz );
155+ return context . runtime .getNil ();
147156 }
148157
149158 @ JRubyMethod
150- public IRubyObject modifiers () {
151- return getRuntime () .newFixnum (((Member ) accessibleObject ()).getModifiers ());
159+ public IRubyObject modifiers (ThreadContext context ) {
160+ return context . runtime .newFixnum (((Member ) accessibleObject ()).getModifiers ());
152161 }
153162
154163 @ JRubyMethod
155- public IRubyObject name () {
156- return getRuntime () .newString (((Member ) accessibleObject ()).getName ());
164+ public IRubyObject name (ThreadContext context ) {
165+ return context . runtime .newString (((Member ) accessibleObject ()).getName ());
157166 }
158167
159168 @ JRubyMethod (name = "synthetic?" )
160- public IRubyObject synthetic_p () {
161- return getRuntime () .newBoolean (((Member ) accessibleObject ()).isSynthetic ());
169+ public IRubyObject synthetic_p (ThreadContext context ) {
170+ return context . runtime .newBoolean (((Member ) accessibleObject ()).isSynthetic ());
162171 }
163172
164173 @ JRubyMethod (name = {"to_s" , "to_string" })
165- public RubyString to_string () {
166- return getRuntime () .newString ( toString () );
174+ public RubyString to_string (ThreadContext context ) {
175+ return context . runtime .newString ( toString () );
167176 }
168177
169178 @ Override
0 commit comments