All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jruby.java.invokers.InstanceFieldGetter Maven / Gradle / Ivy

There is a newer version: 9.4.7.0
Show newest version
package org.jruby.java.invokers;

import java.lang.reflect.Field;
import org.jruby.RubyModule;
import org.jruby.java.proxies.JavaProxy;
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class InstanceFieldGetter extends FieldMethodZero {

    public InstanceFieldGetter(String name, RubyModule host, Field field) {
        super(name, host, field);
    }

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
        try {
            JavaProxy proxy = InstanceMethodInvoker.castJavaProxy(self);
            return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), field.get(proxy.getObject()));
        } catch (IllegalAccessException iae) {
            throw context.getRuntime().newTypeError("illegal access getting variable: " + iae.getMessage());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy