public class RJavaTools
extends java.lang.Object
Constructor and Description |
---|
RJavaTools() |
Modifier and Type | Method and Description |
---|---|
static boolean |
classHasClass(java.lang.Class cl,
java.lang.String name,
boolean staticRequired)
Checks if the specified class has the given inner class.
|
static boolean |
classHasField(java.lang.Class cl,
java.lang.String name,
boolean staticRequired)
Checks if the specified class has the given field.
|
static boolean |
classHasMethod(java.lang.Class cl,
java.lang.String name,
boolean staticRequired)
Checks if the specified class has the given method.
|
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
|
static java.lang.Class[] |
getClasses(java.lang.Object o)
Returns the list of classes of the object
|
static java.lang.String[] |
getClassNames(java.lang.Object o)
Returns the list of class names of the object
|
static java.lang.String |
getCompletionName(java.lang.reflect.Member m)
Completion name of a member.
|
static java.lang.reflect.Constructor |
getConstructor(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_clazz
|
static java.lang.String[] |
getFieldNames(java.lang.Class cl,
boolean staticRequired)
Returns the names of the fields of a given class
|
static java.lang.String |
getFieldTypeName(java.lang.Class cl,
java.lang.String field) |
static java.lang.reflect.Method |
getMethod(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 class
o_clazz with the method name name and arguments types defined by arg_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 object
|
static java.lang.Class[] |
getStaticClasses(java.lang.Class cl)
Returns the static inner classes of the class
|
static java.lang.reflect.Field[] |
getStaticFields(java.lang.Class cl)
Returns the static fields of the class
|
static java.lang.reflect.Method[] |
getStaticMethods(java.lang.Class cl)
Returns the static methods of the class
|
static boolean |
hasClass(java.lang.Object o,
java.lang.String name)
Checks if the class of the object has the given inner class.
|
static boolean |
hasField(java.lang.Object o,
java.lang.String name)
Checks if the class of the object has the given field.
|
static boolean |
hasMethod(java.lang.Object o,
java.lang.String name)
Checks if the class of the object has the given method.
|
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)
Invoke a method of a given class
First the appropriate method is resolved by getMethod and
then invokes the method
|
static boolean |
isStatic(java.lang.Class clazz)
Indicates if a class is static
|
static boolean |
isStatic(java.lang.reflect.Member member)
Indicates if a member of a Class (field, method ) is static
|
static java.lang.Object |
newInstance(java.lang.Class o_clazz,
java.lang.Object[] args,
java.lang.Class[] clazzes)
Object creator.
|
public static java.lang.Class getClass(java.lang.Class cl, java.lang.String name, boolean staticRequired)
cl
- classname
- simple name of the inner classstaticRequired
- boolean, if true
the inner class is required to be staticpublic static java.lang.Class[] getStaticClasses(java.lang.Class cl)
cl
- classpublic static boolean isStatic(java.lang.Class clazz)
clazz
- classpublic static java.lang.reflect.Field[] getStaticFields(java.lang.Class cl)
cl
- classpublic static java.lang.reflect.Method[] getStaticMethods(java.lang.Class cl)
cl
- classpublic static java.lang.String[] getFieldNames(java.lang.Class cl, boolean staticRequired)
cl
- classstaticRequired
- if true only static fields are returnedpublic static java.lang.String[] getMethodNames(java.lang.Class cl, boolean staticRequired)
cl
- classstaticRequired
- if true only static methods are returnedpublic static java.lang.String getCompletionName(java.lang.reflect.Member m)
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.
public static boolean isStatic(java.lang.reflect.Member member)
member
- class memberpublic static boolean hasField(java.lang.Object o, java.lang.String name)
o
- objectname
- name of the fieldtrue
if the class of o
has the field name
public static boolean hasClass(java.lang.Object o, java.lang.String name)
o
- objectname
- (simple) name of the inner classtrue
if the class of o
has the class name
public static boolean classHasField(java.lang.Class cl, java.lang.String name, boolean staticRequired)
cl
- class objectname
- name of the fieldstaticRequired
- if true
then the field is required to be statictrue
if the class cl
has the field name
public static boolean classHasMethod(java.lang.Class cl, java.lang.String name, boolean staticRequired)
cl
- classname
- name of the methodstaticRequired
- if true
then the method is required to be statictrue
if the class cl
has the method name
public static boolean classHasClass(java.lang.Class cl, java.lang.String name, boolean staticRequired)
cl
- classname
- name of the inner classstaticRequired
- if true
then the method is required to be statictrue
if the class cl
has the field name
public static boolean hasMethod(java.lang.Object o, java.lang.String name)
o
- objectname
- name of the methodtrue
if the class of o
has the field name
public static java.lang.Object newInstance(java.lang.Class o_clazz, java.lang.Object[] args, java.lang.Class[] clazzes) throws java.lang.Throwable
java.lang.Throwable
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.Throwable
First the appropriate method is resolved by getMethod and then invokes the method
java.lang.Throwable
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.NoSuchMethodException
o_clazz
- Class to look for a constructorarg_clazz
- parameter typesarg_is_null
- indicates if each argument is nullnull
if no constructor is found, or the constructorjava.lang.SecurityException
java.lang.NoSuchMethodException
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.NoSuchMethodException
o_clazz
with the method name name
and arguments types defined by arg_clazz
.
The lookup is performed by finding the most specific methods that matches the supplied arguments (see also isMoreSpecific(java.lang.reflect.Method, java.lang.reflect.Method)
).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 nullnull
if no matching method could be found or the best matching method.java.lang.SecurityException
java.lang.NoSuchMethodException
public static java.lang.Class[] getClasses(java.lang.Object o)
o
- an Objectpublic static java.lang.String[] getClassNames(java.lang.Object o)
o
- an Objectpublic static java.lang.String[] getSimpleClassNames(java.lang.Object o, boolean addConditionClasses)
o
- an Objectpublic static java.lang.String getFieldTypeName(java.lang.Class cl, java.lang.String field)
cl
- classfield
- name of the field