Package org.jruby.javasupport
Class JavaUtil
java.lang.Object
org.jruby.javasupport.JavaUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfacestatic interfaceDeprecated.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final Map<Class, JavaUtil.RubyConverter> Deprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.JavaConverterstatic final booleanDeprecated.static final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.JavaConverterstatic final JavaUtil.StringConverterstatic final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final Map<Class, JavaUtil.RubyConverter> Deprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated.static final JavaUtil.RubyConverterDeprecated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TClone a Java object, assuming its class has an accessibleclonemethod.static ObjectcoerceJavaObjectToType(ThreadContext context, Object javaObject, Class target) Deprecated.static ObjectcoerceNilToType(RubyNil nil, Class target) Deprecated.static ObjectcoerceOtherToType(ThreadContext context, IRubyObject arg, Class target) Deprecated.static ObjectcoerceStringToType(RubyString string, Class target) Deprecated.static ObjectconvertArgument(Ruby runtime, Object argument, Class<?> parameterType) Deprecated.static Object[]convertArguments(IRubyObject[] args, Class<?>[] types) static Object[]convertArguments(IRubyObject[] args, Class<?>[] types, int offset) static ObjectconvertArgumentToType(ThreadContext context, IRubyObject arg, Class target) Deprecated.static IRubyObjectconvertJavaArrayElementToRuby(Ruby runtime, JavaUtil.JavaConverter converter, Object array, int i) static IRubyObject[]convertJavaArrayToRuby(Ruby runtime, Object[] objects) static RubyArrayconvertJavaArrayToRubyWithNesting(ThreadContext context, Object array) static IRubyObjectconvertJavaToRuby(Ruby runtime, boolean b) static IRubyObjectconvertJavaToRuby(Ruby runtime, double d) static IRubyObjectconvertJavaToRuby(Ruby runtime, float f) static IRubyObjectconvertJavaToRuby(Ruby runtime, int i) static IRubyObjectconvertJavaToRuby(Ruby runtime, long l) static IRubyObjectconvertJavaToRuby(Ruby runtime, Object object) static IRubyObjectconvertJavaToRuby(Ruby runtime, Object object, Class javaClass) static IRubyObjectconvertJavaToRuby(Ruby runtime, JavaUtil.JavaConverter converter, Object object) Deprecated.static IRubyObjectconvertJavaToUsableRubyObject(Ruby runtime, Object object) Returns a usable RubyObject; for types that are not converted to Ruby native types, a Java proxy will be returned.static IRubyObjectconvertJavaToUsableRubyObjectWithConverter(Ruby runtime, Object object, JavaUtil.JavaConverter converter) static <T> TconvertProcToInterface(ThreadContext context, RubyBasicObject rubyObject, Class<T> targetType) static <T> TconvertProcToInterface(ThreadContext context, RubyObject rubyObject, Class<T> targetType) static ObjectconvertRubyToJava(IRubyObject rubyObject) Deprecated.static ObjectconvertRubyToJava(IRubyObject rubyObject, Class javaClass) Deprecated.static booleanconvertRubyToJavaBoolean(IRubyObject rubyObject) Deprecated.static byteconvertRubyToJavaByte(IRubyObject rubyObject) Deprecated.static charconvertRubyToJavaChar(IRubyObject rubyObject) Deprecated.static doubleconvertRubyToJavaDouble(IRubyObject rubyObject) Deprecated.static floatconvertRubyToJavaFloat(IRubyObject rubyObject) Deprecated.static intconvertRubyToJavaInt(IRubyObject rubyObject) Deprecated.static longconvertRubyToJavaLong(IRubyObject rubyObject) Deprecated.static shortconvertRubyToJavaShort(IRubyObject rubyObject) Deprecated.static IRubyObject[]convertStringArrayToRuby(Ruby runtime, String[] strings, JavaUtil.StringConverter converter) static JavaUtil.RubyConvertergetArrayConverter(Class type) Deprecated.static MethodHandlegetGetterSafe(Field field, Class caller, MethodHandles.Lookup lookup) static MethodHandlegetHandleSafe(Method method, Class caller, MethodHandles.Lookup lookup) static StringgetJavaCasedName(String javaCasedName) static Class<?> getJavaClass(RubyModule type) Deprecated.static Class<?> getJavaClass(RubyModule type, Supplier<Class<?>> ifNone) Get the associated JavaClass for a Java proxy module/class or wrapper.static Class<?> getJavaClass(ThreadContext context, RubyModule type) Get the associated JavaClass for a Java proxy module/class or wrapper.static JavaUtil.JavaConvertergetJavaConverter(Class clazz) static StringgetJavaPropertyName(String beanMethodName) For methods that match /(get|set|is)([A-Z0-9])(.*)/, return the "name" part of the property with leading lower-case.static <T> JavaUtil.NumericConverter<T> getNumericConverter(Class<T> target) static Class<?> getPrimitiveClass(String name) static StringgetRubyCasedName(String javaCasedName) Build a Ruby name from a Java name by treating '_' as divider and successive caps as all the same word.getRubyNamesForJavaName(String javaName, List<Method> methods) Given a simple Java method name and the Java Method objects that represent all its overloads, add to the given nameSet all possible Ruby names that would be valid.static MethodHandlegetSetterSafe(Field field, Class caller, MethodHandles.Lookup lookup) static RubyStringinspectObject(ThreadContext context, Object obj) static booleanisDuckTypeConvertable(Class<?> argumentType, Class<?> targetType) static booleanisJavaObject(IRubyObject object) Test if a passed instance is a wrapper Java object.static IRubyObjectjava_to_primitive(IRubyObject recv, IRubyObject object, Block unusedBlock) Deprecated.static IRubyObjectjava_to_ruby(Ruby runtime, IRubyObject object) Deprecated.static Objectstatic IRubyObjectprimitive_to_java(IRubyObject recv, IRubyObject object, Block unusedBlock) Deprecated.static Class<?> primitiveToWrapper(Class<?> type) static IRubyObjectruby_to_java(IRubyObject recv, IRubyObject object, Block unusedBlock) Deprecated.static StringtoJavaGetName(String propertyName) static StringtoJavaIsName(String propertyName) static IRubyObjecttrySimpleConversions(Ruby runtime, Object object) static <T> TunwrapIfJavaObject(IRubyObject object) Unwrap if the passed object is a Java object, otherwise return object.static <T> TunwrapJava(Object wrapped, T defaultValue) static <T> TunwrapJava(IRubyObject wrapped) Deprecated.static <T> TunwrapJava(ThreadContext context, IRubyObject wrapped) static JavaObjectunwrapJavaObject(Ruby runtime, IRubyObject convertee, String errorMessage) Deprecated.static <T> TunwrapJavaObject(IRubyObject object) Unwrap a wrapped Java object.static ObjectunwrapJavaValue(Ruby runtime, IRubyObject object, String errorMessage) Deprecated.static <T> TunwrapJavaValue(IRubyObject object)
-
Field Details
-
JAVA_DEFAULT_CONVERTER
-
JAVA_BOOLEAN_CONVERTER
-
JAVA_FLOAT_CONVERTER
-
JAVA_DOUBLE_CONVERTER
-
JAVA_CHAR_CONVERTER
-
JAVA_BYTE_CONVERTER
-
JAVA_SHORT_CONVERTER
-
JAVA_INT_CONVERTER
-
JAVA_LONG_CONVERTER
-
JAVA_BOOLEANPRIM_CONVERTER
-
JAVA_FLOATPRIM_CONVERTER
-
JAVA_DOUBLEPRIM_CONVERTER
-
JAVA_CHARPRIM_CONVERTER
-
JAVA_BYTEPRIM_CONVERTER
-
JAVA_SHORTPRIM_CONVERTER
-
JAVA_INTPRIM_CONVERTER
-
JAVA_LONGPRIM_CONVERTER
-
JAVA_STRING_CONVERTER
-
JAVA_CHARSEQUENCE_CONVERTER
-
BYTELIST_CONVERTER
-
JAVA_BIGINTEGER_CONVERTER
-
PRIMITIVE_CLASSES
-
RUBY_BOOLEAN_CONVERTER
Deprecated. -
RUBY_BYTE_CONVERTER
Deprecated. -
RUBY_SHORT_CONVERTER
Deprecated. -
RUBY_CHAR_CONVERTER
Deprecated. -
RUBY_INTEGER_CONVERTER
Deprecated. -
RUBY_LONG_CONVERTER
Deprecated. -
RUBY_FLOAT_CONVERTER
Deprecated. -
RUBY_DOUBLE_CONVERTER
Deprecated. -
RUBY_CONVERTERS
Deprecated. -
ARRAY_BOOLEAN_CONVERTER
Deprecated. -
ARRAY_BYTE_CONVERTER
Deprecated. -
ARRAY_SHORT_CONVERTER
Deprecated. -
ARRAY_CHAR_CONVERTER
Deprecated. -
ARRAY_INT_CONVERTER
Deprecated. -
ARRAY_LONG_CONVERTER
Deprecated. -
ARRAY_FLOAT_CONVERTER
Deprecated. -
ARRAY_DOUBLE_CONVERTER
Deprecated. -
ARRAY_OBJECT_CONVERTER
Deprecated. -
ARRAY_CLASS_CONVERTER
Deprecated. -
ARRAY_STRING_CONVERTER
Deprecated. -
ARRAY_BIGINTEGER_CONVERTER
Deprecated. -
ARRAY_BIGDECIMAL_CONVERTER
Deprecated. -
ARRAY_CONVERTERS
Deprecated. -
CAN_SET_ACCESSIBLE
Deprecated.- See Also:
-
-
Constructor Details
-
JavaUtil
public JavaUtil()
-
-
Method Details
-
convertJavaArrayToRuby
-
convertStringArrayToRuby
public static IRubyObject[] convertStringArrayToRuby(Ruby runtime, String[] strings, JavaUtil.StringConverter converter) -
convertJavaArrayToRubyWithNesting
-
getJavaConverter
-
convertJavaToRuby
-
convertJavaToRuby
-
convertJavaToRuby
-
convertJavaToRuby
-
convertJavaToRuby
-
convertJavaToRuby
-
convertJavaToRuby
-
convertJavaToUsableRubyObject
Returns a usable RubyObject; for types that are not converted to Ruby native types, a Java proxy will be returned.- Parameters:
runtime-object-- Returns:
- corresponding Ruby type, or a functional Java proxy
-
convertJavaToUsableRubyObjectWithConverter
public static IRubyObject convertJavaToUsableRubyObjectWithConverter(Ruby runtime, Object object, JavaUtil.JavaConverter converter) -
convertJavaArrayElementToRuby
public static IRubyObject convertJavaArrayElementToRuby(Ruby runtime, JavaUtil.JavaConverter converter, Object array, int i) -
primitiveToWrapper
-
isDuckTypeConvertable
-
convertProcToInterface
public static <T> T convertProcToInterface(ThreadContext context, RubyObject rubyObject, Class<T> targetType) -
convertProcToInterface
public static <T> T convertProcToInterface(ThreadContext context, RubyBasicObject rubyObject, Class<T> targetType) -
getNumericConverter
-
isJavaObject
Test if a passed instance is a wrapper Java object.- Parameters:
object-- Returns:
- true if the object is wrapping a Java object
-
unwrapJavaObject
Unwrap a wrapped Java object.- Parameters:
object-- Returns:
- Java object
- See Also:
-
unwrapIfJavaObject
Unwrap if the passed object is a Java object, otherwise return object.- Parameters:
object-- Returns:
- java object or passed object
- See Also:
-
unwrapJavaValue
@Deprecated public static Object unwrapJavaValue(Ruby runtime, IRubyObject object, String errorMessage) Deprecated. -
inspectObject
-
unwrapJavaValue
- Parameters:
object-Note: Returns null if not a wrapped Java value.
- Returns:
- unwrapped Java (object's) value
-
getJavaPropertyName
For methods that match /(get|set|is)([A-Z0-9])(.*)/, return the "name" part of the property with leading lower-case.Note: Does not use regular expression for performance reasons.
- Parameters:
beanMethodName- the bean method from which to extract a name- Returns:
- the bean property name (or null)
-
toJavaGetName
-
toJavaIsName
-
getRubyCasedName
Build a Ruby name from a Java name by treating '_' as divider and successive caps as all the same word.- Parameters:
javaCasedName-- Returns:
- Ruby (under-score) cased named e.g. "get_foo_bar"
-
getJavaCasedName
-
getRubyNamesForJavaName
Given a simple Java method name and the Java Method objects that represent all its overloads, add to the given nameSet all possible Ruby names that would be valid.- Parameters:
javaName-methods-- Returns:
- method names
-
convertArguments
-
convertArguments
-
clone
Clone a Java object, assuming its class has an accessibleclonemethod.- Parameters:
object-- Returns:
- cloned object or null (if method is not found or inaccessible)
-
getHandleSafe
-
getGetterSafe
-
getSetterSafe
-
trySimpleConversions
-
objectFromJavaProxy
-
getPrimitiveClass
-
convertRubyToJava
Deprecated. -
convertRubyToJava
Deprecated. -
convertRubyToJavaByte
Deprecated. -
convertRubyToJavaShort
Deprecated. -
convertRubyToJavaChar
Deprecated. -
convertRubyToJavaInt
Deprecated. -
convertRubyToJavaLong
Deprecated. -
convertRubyToJavaFloat
Deprecated. -
convertRubyToJavaDouble
Deprecated. -
convertRubyToJavaBoolean
Deprecated. -
convertArgumentToType
@Deprecated public static Object convertArgumentToType(ThreadContext context, IRubyObject arg, Class target) Deprecated. -
coerceNilToType
Deprecated. -
convertJavaToRuby
@Deprecated public static IRubyObject convertJavaToRuby(Ruby runtime, JavaUtil.JavaConverter converter, Object object) Deprecated. -
getArrayConverter
Deprecated. -
ruby_to_java
@Deprecated public static IRubyObject ruby_to_java(IRubyObject recv, IRubyObject object, Block unusedBlock) Deprecated.High-level object conversion utility. -
java_to_primitive
@Deprecated public static IRubyObject java_to_primitive(IRubyObject recv, IRubyObject object, Block unusedBlock) Deprecated. -
primitive_to_java
@Deprecated public static IRubyObject primitive_to_java(IRubyObject recv, IRubyObject object, Block unusedBlock) Deprecated. -
convertArgument
@Deprecated public static Object convertArgument(Ruby runtime, Object argument, Class<?> parameterType) Deprecated. -
java_to_ruby
Deprecated.High-level object conversion utility function 'java_to_primitive' is the low-level version -
coerceStringToType
Deprecated. -
coerceOtherToType
@Deprecated public static Object coerceOtherToType(ThreadContext context, IRubyObject arg, Class target) Deprecated. -
coerceJavaObjectToType
@Deprecated public static Object coerceJavaObjectToType(ThreadContext context, Object javaObject, Class target) Deprecated. -
unwrapJavaObject
@Deprecated public static JavaObject unwrapJavaObject(Ruby runtime, IRubyObject convertee, String errorMessage) Deprecated. -
unwrapJava
-
unwrapJava
Deprecated. -
unwrapJava
-
getJavaClass
Deprecated.- Throws:
TypeError
-
getJavaClass
Get the associated JavaClass for a Java proxy module/class or wrapper.Note: Works best when passed module/class is assumed to be a Java proxy wrapper.
- Parameters:
type-- Returns:
- class
- Throws:
TypeError
-
getJavaClass
Get the associated JavaClass for a Java proxy module/class or wrapper.- Parameters:
type-ifNone- fallback if none Java class wrapper- Returns:
- class or the result of the supplier function
-