Class RJavaTools
- java.lang.Object
-
- RJavaTools
-
public class RJavaTools extends java.lang.ObjectTools used internally by rJava. The method lookup code is heavily based on ReflectionTools by Romain Francois <francoisromain@free.fr> licensed under GPL v2 or higher.
-
-
Constructor Summary
Constructors Constructor Description RJavaTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanclassHasClass(java.lang.Class cl, java.lang.String name, boolean staticRequired)Checks if the specified class has the given inner class.static booleanclassHasField(java.lang.Class cl, java.lang.String name, boolean staticRequired)Checks if the specified class has the given field.static booleanclassHasMethod(java.lang.Class cl, java.lang.String name, boolean staticRequired)Checks if the specified class has the given method.static java.lang.ClassgetClass(java.lang.Class cl, java.lang.String name, boolean staticRequired)Returns an inner class of the class with the given simple namestatic java.lang.Class[]getClasses(java.lang.Object o)Returns the list of classes of the objectstatic java.lang.String[]getClassNames(java.lang.Object o)Returns the list of class names of the objectstatic java.lang.StringgetCompletionName(java.lang.reflect.Member m)Completion name of a member.static java.lang.reflect.ConstructorgetConstructor(java.lang.Class o_clazz, java.lang.Class[] arg_clazz, boolean[] arg_is_null)Attempts to find the best-matching constructor of the class o_clazz with the parameter types arg_clazzstatic java.lang.String[]getFieldNames(java.lang.Class cl, boolean staticRequired)Returns the names of the fields of a given classstatic java.lang.StringgetFieldTypeName(java.lang.Class cl, java.lang.String field)static java.lang.reflect.MethodgetMethod(java.lang.Class o_clazz, java.lang.String name, java.lang.Class[] arg_clazz, boolean[] arg_is_null)Attempts to find the best-matching method of the classo_clazzwith the method namenameand arguments types defined byarg_clazz.static java.lang.String[]getMethodNames(java.lang.Class cl, boolean staticRequired)Returns the completion names of the methods of a given class.static java.lang.String[]getSimpleClassNames(java.lang.Object o, boolean addConditionClasses)Returns the list of simple class names of the objectstatic java.lang.Class[]getStaticClasses(java.lang.Class cl)Returns the static inner classes of the classstatic java.lang.reflect.Field[]getStaticFields(java.lang.Class cl)Returns the static fields of the classstatic java.lang.reflect.Method[]getStaticMethods(java.lang.Class cl)Returns the static methods of the classstatic booleanhasClass(java.lang.Object o, java.lang.String name)Checks if the class of the object has the given inner class.static booleanhasField(java.lang.Object o, java.lang.String name)Checks if the class of the object has the given field.static booleanhasMethod(java.lang.Object o, java.lang.String name)Checks if the class of the object has the given method.static java.lang.ObjectinvokeMethod(java.lang.Class o_clazz, java.lang.Object o, java.lang.String name, java.lang.Object[] args, java.lang.Class[] clazzes)Invoke a method of a given classstatic booleanisStatic(java.lang.Class clazz)Indicates if a class is staticstatic booleanisStatic(java.lang.reflect.Member member)Indicates if a member of a Class (field, method ) is staticstatic java.lang.ObjectnewInstance(java.lang.Class o_clazz, java.lang.Object[] args, java.lang.Class[] clazzes)Object creator.
-
-
-
Method Detail
-
getClass
public static java.lang.Class getClass(java.lang.Class cl, java.lang.String name, boolean staticRequired)Returns an inner class of the class with the given simple name- Parameters:
cl- classname- simple name of the inner classstaticRequired- boolean, iftruethe inner class is required to be static
-
getStaticClasses
public static java.lang.Class[] getStaticClasses(java.lang.Class cl)
Returns the static inner classes of the class- Parameters:
cl- class- Returns:
- an array of classes or null if cl does not have static inner classes
-
isStatic
public static boolean isStatic(java.lang.Class clazz)
Indicates if a class is static- Parameters:
clazz- class- Returns:
- true if the class is static
-
getStaticFields
public static java.lang.reflect.Field[] getStaticFields(java.lang.Class cl)
Returns the static fields of the class- Parameters:
cl- class- Returns:
- an array of static fields
-
getStaticMethods
public static java.lang.reflect.Method[] getStaticMethods(java.lang.Class cl)
Returns the static methods of the class- Parameters:
cl- class- Returns:
- an array of static fields
-
getFieldNames
public static java.lang.String[] getFieldNames(java.lang.Class cl, boolean staticRequired)Returns the names of the fields of a given class- Parameters:
cl- classstaticRequired- if true only static fields are returned- Returns:
- the public (and maybe only static) names of the fields.
-
getMethodNames
public static java.lang.String[] getMethodNames(java.lang.Class cl, boolean staticRequired)Returns the completion names of the methods of a given class. See the getMethodCompletionName method below- Parameters:
cl- classstaticRequired- if true only static methods are returned- Returns:
- the public (and maybe only static) names of the methods.
-
getCompletionName
public static java.lang.String getCompletionName(java.lang.reflect.Member m)
Completion name of a member.For fields, it just returns the name of the fields
For methods, this returns the name of the method plus a suffix that depends on the number of arguments of the method.
The string "()" is added if the method has no arguments, and the string "(" is added if the method has one or more arguments.
-
isStatic
public static boolean isStatic(java.lang.reflect.Member member)
Indicates if a member of a Class (field, method ) is static- Parameters:
member- class member- Returns:
- true if the member is static
-
hasField
public static boolean hasField(java.lang.Object o, java.lang.String name)Checks if the class of the object has the given field. The getFields method of Class is used so only public fields are checked- Parameters:
o- objectname- name of the field- Returns:
trueif the class ofohas the fieldname
-
hasClass
public static boolean hasClass(java.lang.Object o, java.lang.String name)Checks if the class of the object has the given inner class. The getClasses method of Class is used so only public classes are checked- Parameters:
o- objectname- (simple) name of the inner class- Returns:
trueif the class ofohas the classname
-
classHasField
public static boolean classHasField(java.lang.Class cl, java.lang.String name, boolean staticRequired)Checks if the specified class has the given field. The getFields method of Class is used so only public fields are checked- Parameters:
cl- class objectname- name of the fieldstaticRequired- iftruethen the field is required to be static- Returns:
trueif the classclhas the fieldname
-
classHasMethod
public static boolean classHasMethod(java.lang.Class cl, java.lang.String name, boolean staticRequired)Checks if the specified class has the given method. The getMethods method of Class is used so only public methods are checked- Parameters:
cl- classname- name of the methodstaticRequired- iftruethen the method is required to be static- Returns:
trueif the classclhas the methodname
-
classHasClass
public static boolean classHasClass(java.lang.Class cl, java.lang.String name, boolean staticRequired)Checks if the specified class has the given inner class. The getClasses method of Class is used so only public classes are checked- Parameters:
cl- classname- name of the inner classstaticRequired- iftruethen the method is required to be static- Returns:
trueif the classclhas the fieldname
-
hasMethod
public static boolean hasMethod(java.lang.Object o, java.lang.String name)Checks if the class of the object has the given method. The getMethods method of Class is used so only public methods are checked- Parameters:
o- objectname- name of the method- Returns:
trueif the class ofohas the fieldname
-
newInstance
public static java.lang.Object newInstance(java.lang.Class o_clazz, java.lang.Object[] args, java.lang.Class[] clazzes) throws java.lang.ThrowableObject creator. Find the best constructor based on the parameter classes and invoke newInstance on the resolved constructor- Throws:
java.lang.Throwable
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Class o_clazz, java.lang.Object o, java.lang.String name, java.lang.Object[] args, java.lang.Class[] clazzes) throws java.lang.ThrowableInvoke a method of a given classFirst the appropriate method is resolved by getMethod and then invokes the method
- Throws:
java.lang.Throwable
-
getConstructor
public static java.lang.reflect.Constructor getConstructor(java.lang.Class o_clazz, java.lang.Class[] arg_clazz, boolean[] arg_is_null) throws java.lang.SecurityException, java.lang.NoSuchMethodExceptionAttempts to find the best-matching constructor of the class o_clazz with the parameter types arg_clazz- Parameters:
o_clazz- Class to look for a constructorarg_clazz- parameter typesarg_is_null- indicates if each argument is null- Returns:
nullif no constructor is found, or the constructor- Throws:
java.lang.SecurityExceptionjava.lang.NoSuchMethodException
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Class o_clazz, java.lang.String name, java.lang.Class[] arg_clazz, boolean[] arg_is_null) throws java.lang.SecurityException, java.lang.NoSuchMethodExceptionAttempts to find the best-matching method of the classo_clazzwith the method namenameand arguments types defined byarg_clazz. The lookup is performed by finding the most specific methods that matches the supplied arguments (see alsoisMoreSpecific(java.lang.reflect.Method, java.lang.reflect.Method)).- Parameters:
o_clazz- class in which to look for the methodname- method namearg_clazz- an array of classes defining the types of argumentsarg_is_null- indicates if each argument is null- Returns:
nullif no matching method could be found or the best matching method.- Throws:
java.lang.SecurityExceptionjava.lang.NoSuchMethodException
-
getClasses
public static java.lang.Class[] getClasses(java.lang.Object o)
Returns the list of classes of the object- Parameters:
o- an Object
-
getClassNames
public static java.lang.String[] getClassNames(java.lang.Object o)
Returns the list of class names of the object- Parameters:
o- an Object
-
getSimpleClassNames
public static java.lang.String[] getSimpleClassNames(java.lang.Object o, boolean addConditionClasses)Returns the list of simple class names of the object- Parameters:
o- an Object
-
getFieldTypeName
public static java.lang.String getFieldTypeName(java.lang.Class cl, java.lang.String field)- Parameters:
cl- classfield- name of the field- Returns:
- the class name of the field of the class (or null) if the class does not have the given field)
-
-