StaticFieldGetter.java

  1. package org.jruby.java.invokers;

  2. import java.lang.reflect.Field;

  3. import org.jruby.RubyModule;
  4. import org.jruby.javasupport.JavaUtil;
  5. import org.jruby.runtime.ThreadContext;
  6. import org.jruby.runtime.builtin.IRubyObject;

  7. public class StaticFieldGetter extends FieldMethodZero {

  8.     public StaticFieldGetter(String name, RubyModule host, Field field) {
  9.         super(name, host, field);
  10.     }

  11.     @Override
  12.     public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
  13.         try {
  14.             return JavaUtil.convertJavaToUsableRubyObject(context.runtime, field.get(null));
  15.         } catch (IllegalAccessException iae) {
  16.             throw context.runtime.newTypeError("illegal access getting variable: " + iae.getMessage());
  17.         }
  18.     }
  19. }