private static RubyArray buildFieldResults(final Ruby runtime, Field[] fields) { RubyArray result = runtime.newArray( fields.length ); for ( int i = 0; i < fields.length; i++ ) { result.append( new JavaField(runtime, fields[i]) ); } return result; }
@JRubyMethod(name = "public?") public RubyBoolean public_p() { return getRuntime().newBoolean(Modifier.isPublic(field.getModifiers())); }
@JRubyMethod public IRubyObject static_value() { try { return convertToRuby( getRuntime(), field.get(null) ); } catch (IllegalAccessException iae) { throw getRuntime().newTypeError("illegal static value access: " + iae.getMessage()); } }
@JRubyMethod public IRubyObject value(ThreadContext context, IRubyObject object) { final Ruby runtime = context.runtime; final Object javaObject; if ( ! Modifier.isStatic( field.getModifiers() ) ) { javaObject = unwrapJavaObject(object); } else { javaObject = null; } try { return convertToRuby(runtime, field.get(javaObject)); } catch (IllegalAccessException iae) { throw runtime.newTypeError("illegal access"); } }
@JRubyMethod public IRubyObject set_value(IRubyObject object, IRubyObject value) { final Object javaObject; if ( ! Modifier.isStatic( field.getModifiers() ) ) { javaObject = unwrapJavaObject(object); } else { javaObject = null; } final Object javaValue = convertValueToJava(value); try { field.set(javaObject, javaValue); } catch (IllegalAccessException iae) { throw getRuntime().newTypeError("illegal access on setting variable: " + iae.getMessage()); } catch (IllegalArgumentException iae) { throw getRuntime().newTypeError("wrong type for " + field.getType().getName() + ": " + ( javaValue == null ? null : javaValue.getClass().getName() ) ); } return value; }
@JRubyMethod public IRubyObject set_static_value(IRubyObject value) { if ( ! ( value instanceof JavaObject ) ) { throw getRuntime().newTypeError("not a java object:" + value); } final Object javaValue = convertValueToJava(value); try { field.set(null, javaValue); } catch (IllegalAccessException iae) { throw getRuntime().newTypeError( "illegal access on setting static variable: " + iae.getMessage()); } catch (IllegalArgumentException iae) { throw getRuntime().newTypeError("wrong type for " + field.getType().getName() + ": " + ( javaValue == null ? null : javaValue.getClass().getName() ) ); } return value; }
JavaMethod.createJavaMethodClass(runtime, javaModule); JavaConstructor.createJavaConstructorClass(runtime, javaModule); JavaField.createJavaFieldClass(runtime, javaModule);
@JRubyMethod public IRubyObject set_value(IRubyObject object, IRubyObject value) { final Object javaObject; if ( ! Modifier.isStatic( field.getModifiers() ) ) { javaObject = unwrapJavaObject(object); } else { javaObject = null; } final Object javaValue = convertValueToJava(value); try { field.set(javaObject, javaValue); } catch (IllegalAccessException iae) { throw getRuntime().newTypeError("illegal access on setting variable: " + iae.getMessage()); } catch (IllegalArgumentException iae) { throw getRuntime().newTypeError("wrong type for " + field.getType().getName() + ": " + ( javaValue == null ? null : javaValue.getClass().getName() ) ); } return value; }
@JRubyMethod public IRubyObject set_static_value(IRubyObject value) { if ( ! ( value instanceof JavaObject ) ) { throw getRuntime().newTypeError("not a java object:" + value); } final Object javaValue = convertValueToJava(value); try { field.set(null, javaValue); } catch (IllegalAccessException iae) { throw getRuntime().newTypeError( "illegal access on setting static variable: " + iae.getMessage()); } catch (IllegalArgumentException iae) { throw getRuntime().newTypeError("wrong type for " + field.getType().getName() + ": " + ( javaValue == null ? null : javaValue.getClass().getName() ) ); } return value; }
JavaMethod.createJavaMethodClass(runtime, Java); JavaConstructor.createJavaConstructorClass(runtime, Java); JavaField.createJavaFieldClass(runtime, Java);
@JRubyMethod public IRubyObject value(ThreadContext context, IRubyObject object) { final Ruby runtime = context.runtime; final Object javaObject; if ( ! Modifier.isStatic( field.getModifiers() ) ) { javaObject = unwrapJavaObject(object); } else { javaObject = null; } try { return convertToRuby(runtime, field.get(javaObject)); } catch (IllegalAccessException iae) { throw runtime.newTypeError("illegal access"); } }
@JRubyMethod(name = "final?") public RubyBoolean final_p() { return getRuntime().newBoolean(Modifier.isFinal(field.getModifiers())); }
private static RubyArray buildFieldResults(final Ruby runtime, Field[] fields) { RubyArray result = runtime.newArray( fields.length ); for ( int i = 0; i < fields.length; i++ ) { result.append( new JavaField(runtime, fields[i]) ); } return result; }
@JRubyMethod public IRubyObject static_value() { try { return convertToRuby( getRuntime(), field.get(null) ); } catch (IllegalAccessException iae) { throw getRuntime().newTypeError("illegal static value access: " + iae.getMessage()); } }
JavaMethod.createJavaMethodClass(runtime, javaModule); JavaConstructor.createJavaConstructorClass(runtime, javaModule); JavaField.createJavaFieldClass(runtime, javaModule);
@JRubyMethod(name = "final?") public RubyBoolean final_p() { return getRuntime().newBoolean(Modifier.isFinal(field.getModifiers())); }
@JRubyMethod(required = 1) public JavaField declared_field(ThreadContext context, IRubyObject name) { Class<?> javaClass = javaClass(); Ruby runtime = context.runtime; String stringName = name.asJavaString(); try { return new JavaField(runtime, javaClass.getDeclaredField(stringName)); } catch (NoSuchFieldException nsfe) { String newName = JavaUtil.getJavaCasedName(stringName); if(newName != null) { try { return new JavaField(runtime, javaClass.getDeclaredField(newName)); } catch (NoSuchFieldException nsfe2) {} } throw undefinedFieldError(runtime, javaClass.getName(), stringName); } }
JavaMethod.createJavaMethodClass(runtime, Java); JavaConstructor.createJavaConstructorClass(runtime, Java); JavaField.createJavaFieldClass(runtime, Java);
@JRubyMethod public RubyString value_type() { return getRuntime().newString(field.getType().getName()); }
@JRubyMethod(required = 1) public JavaField field(ThreadContext context, IRubyObject name) { Class<?> javaClass = javaClass(); Ruby runtime = context.runtime; String stringName = name.asJavaString(); try { return new JavaField(runtime, javaClass.getField(stringName)); } catch (NoSuchFieldException nsfe) { String newName = JavaUtil.getJavaCasedName(stringName); if(newName != null) { try { return new JavaField(runtime, javaClass.getField(newName)); } catch (NoSuchFieldException nsfe2) {} } throw undefinedFieldError(runtime, javaClass.getName(), stringName); } }