|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfun.yan.util.ReflectionUtil
public final class ReflectionUtil
The utility class to help reflection.
throughout this class, public members are defined as members defined with "public" keyword and declared in a public type. public members declared by a non-public class is considered non-public because access to it from outside is prohibited by the java access control anyway.
public members defined in public classes are always prefered even when we allow private/protected members and types to be visible. So if a non-public subtype and a public super type both have a field with the same name, the field in the public super type is always used.
Codehaus.org.
| Constructor Summary | |
|---|---|
ReflectionUtil()
|
|
| Method Summary | ||
|---|---|---|
static
|
getConstructor(java.lang.Class<T> c)
To find the only public constructor in a class. |
|
static
|
getConstructor(java.lang.Class<T> c,
boolean suppress_security)
To find the only constructor in a class. |
|
static
|
getConstructor(java.lang.Class<T> c,
java.lang.Class[] param_types)
To find a public constructor in a class. |
|
static
|
getConstructor(java.lang.Class<T> c,
java.lang.Class[] param_types,
boolean suppress_security)
To find a constructor in a class. |
|
static
|
getConstructor(java.lang.Class<T> c,
int param_count)
To find the only public constructor with the expected number of formal parameters in the class. |
|
static
|
getConstructor(java.lang.Class<T> c,
int param_count,
boolean suppress_security)
To find the only public constructor with the expected number of formal parameters in the class. |
|
static java.lang.reflect.Field |
getField(java.lang.Class c,
java.lang.String name)
To find a public field in a class. |
|
static java.lang.reflect.Field |
getField(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
To find a field in a class. |
|
static java.lang.reflect.Field |
getInstanceField(java.lang.Class c,
java.lang.String name)
To find a public instance field in a class. |
|
static java.lang.reflect.Field |
getInstanceField(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
To find an instance field in a class. |
|
static java.lang.reflect.Method |
getInstanceMethod(java.lang.Class c,
int param_count,
java.lang.String name)
To find a public instance method in a class. |
|
static java.lang.reflect.Method |
getInstanceMethod(java.lang.Class c,
java.lang.String name)
To find a public instance method in a class. |
|
static java.lang.reflect.Method |
getInstanceMethod(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
To find an instance method in a class. |
|
static java.lang.reflect.Method |
getInstanceMethod(java.lang.Class c,
java.lang.String name,
int param_count,
boolean suppress_security)
To find an instance method in a class. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class c,
java.lang.String name)
To find a public method in a class. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
To find a method in a class. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types)
To find a public method in a class with a certain signature. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types,
boolean suppress_security)
To find a method in a class with a certain signature. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class c,
java.lang.String name,
int param_count)
To find a public method in a class. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class c,
java.lang.String name,
int param_count,
boolean suppress_security)
To find a method in a class. |
|
static java.lang.reflect.Field |
getStaticField(java.lang.Class c,
java.lang.String name)
To find a public static field in a class. |
|
static java.lang.reflect.Field |
getStaticField(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
To find a static field in a class. |
|
static java.lang.reflect.Method |
getStaticMethod(java.lang.Class c,
java.lang.String name)
To find a public static method in a class. |
|
static java.lang.reflect.Method |
getStaticMethod(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
To find a static method in a class. |
|
static java.lang.reflect.Method |
getStaticMethod(java.lang.Class c,
java.lang.String name,
int param_count)
To find a public static method in a class. |
|
static java.lang.reflect.Method |
getStaticMethod(java.lang.Class c,
java.lang.String name,
int param_count,
boolean suppress_security)
To find a static method in a class. |
|
static boolean |
isAssignableFrom(java.lang.Class t1,
java.lang.Class t2)
To tell if an object of class t2 can be set to a parameter of type t1 using reflection. |
|
static boolean |
isCompatible(java.lang.Class a,
java.lang.Class b)
To determine if two types are sub-type relationship. |
|
static boolean |
isInstance(java.lang.Class t,
java.lang.Object obj)
To tell if an object can be assigned to a parameter type using reflection. |
|
static java.lang.String |
toMethodString(java.lang.String name,
int param_count)
Create a string representation of a method with the given number of formal parameters. |
|
static java.lang.Class |
toObjectType(java.lang.Class c)
Convert a primitive type to the corresponding wrapper type if any. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ReflectionUtil()
| Method Detail |
|---|
public static java.lang.Class toObjectType(java.lang.Class c)
c - the type that could be primitive.
public static boolean isAssignableFrom(java.lang.Class t1,
java.lang.Class t2)
for example, Integer can be set to int.
t1 - the parameter type.t2 - the object type.
public static boolean isCompatible(java.lang.Class a,
java.lang.Class b)
a - the first type.b - the second type.
public static boolean isInstance(java.lang.Class t,
java.lang.Object obj)
for example, an object of Integer is an instance of int.
t - the parameter type.obj - the object.
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> c,
int param_count)
throws AmbiguityException
c - the type to find constructor.param_count - the number of formal parameters.
AmbiguityException - if more than one are found.
java.lang.IllegalArgumentException - if no public constructor is found
or if the class is not public.
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> c,
int param_count,
boolean suppress_security)
c - the type to find constructor.param_count - the number of formal parameters.suppress_security - whether access to the private/protected/package private members is allowed.
AmbiguityException - if more than one are found.
java.lang.IllegalArgumentException - if no constructor is found.
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> c)
throws AmbiguityException
c - the type to find constructor.
AmbiguityException - if more than one are found.
java.lang.IllegalArgumentException - if no public constructor is found
or if the class is not public.
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> c,
boolean suppress_security)
c - the type to find constructor.suppress_security - whether access to the private/protected/package private members is allowed.
AmbiguityException - if more than one are found.
java.lang.IllegalArgumentException - if no constructor is found.
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> c,
java.lang.Class[] param_types)
c - the type to find constructor.param_types - the parameter types.
java.lang.IllegalArgumentException - if constructor is not found
or if the class is not public.
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> c,
java.lang.Class[] param_types,
boolean suppress_security)
c - the type to find constructor.param_types - the parameter types.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if constructor is not found.
public static java.lang.reflect.Method getStaticMethod(java.lang.Class c,
java.lang.String name)
throws AmbiguityException
c - the type to search the method.name - the method name.
AmbiguityException - when more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found or
if the class is not public.
public static java.lang.reflect.Method getStaticMethod(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
throws AmbiguityException
c - the type to search the method.name - the method name.suppress_security - whether access to the private/protected/package private members is allowed.
AmbiguityException - if more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getStaticMethod(java.lang.Class c,
java.lang.String name,
int param_count)
throws AmbiguityException
c - the type to search the method.name - the method name.param_count - the number of formal parameters.
AmbiguityException - when more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found or
if the class is not public.
public static java.lang.reflect.Method getStaticMethod(java.lang.Class c,
java.lang.String name,
int param_count,
boolean suppress_security)
throws AmbiguityException
c - the type to search the method.name - the method name.param_count - the number of formal parameters.suppress_security - whether access to the private/protected/package private members is allowed.
AmbiguityException - if more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Field getField(java.lang.Class c,
java.lang.String name)
c - the type to search the field.name - the field name.
java.lang.IllegalArgumentException - if the field is not found.
public static java.lang.reflect.Field getField(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
c - the type to search the field.name - the field name.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if the field is not found.
public static java.lang.reflect.Field getStaticField(java.lang.Class c,
java.lang.String name)
c - the type to search the field.name - the field name.
java.lang.IllegalArgumentException - if the field is not found.
public static java.lang.reflect.Field getStaticField(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
c - the type to search the field.name - the field name.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if the field is not found.
public static java.lang.reflect.Field getInstanceField(java.lang.Class c,
java.lang.String name)
c - the type to search the field.name - the field name.
java.lang.IllegalArgumentException - if the field is not found.
public static java.lang.reflect.Field getInstanceField(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
c - the type to search the field.name - the field name.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if the field is not found.
public static java.lang.reflect.Method getInstanceMethod(java.lang.Class c,
java.lang.String name)
throws AmbiguityException
c - the type to search the method.name - the method name.
AmbiguityException - if more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getInstanceMethod(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
c - the type to search the method.name - the method name.suppress_security - whether access to the private/protected/package private members is allowed.
AmbiguityException - when more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getInstanceMethod(java.lang.Class c,
int param_count,
java.lang.String name)
throws AmbiguityException
c - the type to search the method.name - the method name.param_count - the number of formal parameters.
AmbiguityException - if more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getInstanceMethod(java.lang.Class c,
java.lang.String name,
int param_count,
boolean suppress_security)
c - the type to search the method.name - the method name.param_count - the number of formal parameters.suppress_security - whether access to the private/protected/package private members is allowed.
AmbiguityException - when more than one methods are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getMethod(java.lang.Class c,
java.lang.String name)
c - the type to search the method.name - the method name.
AmbiguityException - if more than one are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getMethod(java.lang.Class c,
java.lang.String name,
boolean suppress_security)
c - the type to search the method.name - the method name.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if the method is not found or more than one are found.
public static java.lang.reflect.Method getMethod(java.lang.Class c,
java.lang.String name,
int param_count)
c - the type to search the method.name - the method name.param_count - the number of formal parameters.
AmbiguityException - if more than one are found.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getMethod(java.lang.Class c,
java.lang.String name,
int param_count,
boolean suppress_security)
c - the type to search the method.name - the method name.param_count - the number of formal parameters.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if the method is not found or more than one are found.
public static java.lang.reflect.Method getMethod(java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types)
c - the type to search the method.name - the method name.param_types - the parameter types.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.reflect.Method getMethod(java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types,
boolean suppress_security)
c - the type to search the method.name - the method name.param_types - the parameter types.suppress_security - whether access to the private/protected/package private members is allowed.
java.lang.IllegalArgumentException - if the method is not found.
public static java.lang.String toMethodString(java.lang.String name,
int param_count)
name - the method name.param_count - the number of formal parameters.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||