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

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

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

import java.lang.reflect.Field;

import org.jruby.RubyModule;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class StaticFieldSetter extends FieldMethodOne {

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

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg) {
        try {
            field.set(null, arg.toJava(field.getType()));
        } catch (IllegalAccessException iae) {
            throw context.runtime.newSecurityError(iae.getMessage());
        } catch (IllegalArgumentException iae) {
            throw context.runtime.newTypeError(iae.getMessage());
        }
        return arg;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy