Package org.easymock.internal
Class ReflectionUtils
- java.lang.Object
-
- org.easymock.internal.ReflectionUtils
-
public final class ReflectionUtils extends java.lang.Object- Author:
- Henri Tremblay
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceReflectionUtils.Predicate<T>
-
Field Summary
Fields Modifier and Type Field Description static ReflectionUtils.Predicate<java.lang.reflect.Method>NOT_PRIVATEstatic java.lang.reflect.MethodOBJECT_EQUALSstatic java.lang.reflect.MethodOBJECT_FINALIZEstatic java.lang.reflect.MethodOBJECT_HASHCODEstatic java.lang.reflect.MethodOBJECT_TOSTRING
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.reflect.MethodfindMethod(java.lang.Class<?> clazz, java.lang.String name, ReflectionUtils.Predicate<java.lang.reflect.Method> filter)Attempt to find aMethodon the supplied class with the supplied name and no parameters.static java.lang.reflect.MethodfindMethod(java.lang.Class<?> clazz, java.lang.String name, ReflectionUtils.Predicate<java.lang.reflect.Method> filter, java.lang.Class<?>... paramTypes)Attempt to find aMethodon the supplied class with the supplied name and parameter types.static <T> java.lang.reflect.Constructor<T>getConstructor(java.lang.Class<T> clazz, java.lang.Object... objs)Returns a constructor that containsobjsas arguments.static java.lang.reflect.MethodgetDeclaredMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... paramTypes)Basically calls getDeclaredMethod on a Class but wraps the NoSuchMethodException into a Runtime.static booleanisClassAvailable(java.lang.String className)Tells if a class is available in the classpathstatic booleanisDefaultMethod(java.lang.reflect.Method method)
-
-
-
Field Detail
-
NOT_PRIVATE
public static final ReflectionUtils.Predicate<java.lang.reflect.Method> NOT_PRIVATE
-
OBJECT_EQUALS
public static final java.lang.reflect.Method OBJECT_EQUALS
-
OBJECT_HASHCODE
public static final java.lang.reflect.Method OBJECT_HASHCODE
-
OBJECT_TOSTRING
public static final java.lang.reflect.Method OBJECT_TOSTRING
-
OBJECT_FINALIZE
public static final java.lang.reflect.Method OBJECT_FINALIZE
-
-
Method Detail
-
findMethod
public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz, java.lang.String name, ReflectionUtils.Predicate<java.lang.reflect.Method> filter)Attempt to find aMethodon the supplied class with the supplied name and no parameters. Searches all superclasses up toObject. The filter is used to ignore some kind of methods the caller doesn't want to see returned. In this case they are totally ignored and can't clash with a non-ignored one to cause ambiguity.Returns
nullif noMethodcan be found.- Parameters:
clazz- the class to introspectname- the name of the methodfilter- tells what methods to ignore in the research- Returns:
- the Method object, or
nullif none found
-
findMethod
public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz, java.lang.String name, ReflectionUtils.Predicate<java.lang.reflect.Method> filter, java.lang.Class<?>... paramTypes)Attempt to find aMethodon the supplied class with the supplied name and parameter types. Searches all superclasses up toObject. The filter is used to ignore some kind of methods the caller doesn't want to see returned. In this case they are totally ignored and can't clash with a non-ignored one to cause ambiguity.Returns
nullif noMethodcan be found.- Parameters:
clazz- the class to introspectname- the name of the methodfilter- tells what methods to ignore in the researchparamTypes- the parameter types of the method (may benullto indicate any signature)- Returns:
- the Method object, or
nullif none found
-
getConstructor
public static <T> java.lang.reflect.Constructor<T> getConstructor(java.lang.Class<T> clazz, java.lang.Object... objs) throws java.lang.NoSuchMethodExceptionReturns a constructor that containsobjsas arguments.We could not do something like
clazz.getConstructor(objs.class())because that would require casting all the passed arguments to the exact parameter types of the desired constructor.- Type Parameters:
T- type of the class searched- Parameters:
clazz- class on which we are searching the constructorobjs- list of arguments of the constructor- Returns:
- a constructor with the arguments in
objs - Throws:
java.lang.NoSuchMethodException- when the constructor withargsdoes not exist or is ambiguous
-
getDeclaredMethod
public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... paramTypes)Basically calls getDeclaredMethod on a Class but wraps the NoSuchMethodException into a Runtime.- Parameters:
clazz- class on which the getDeclaredMethod is calledname- method nameparamTypes- method parameters- Returns:
- the method searched
-
isClassAvailable
public static boolean isClassAvailable(java.lang.String className)
Tells if a class is available in the classpath- Parameters:
className- full class name- Returns:
- true if the class was found
-
isDefaultMethod
public static boolean isDefaultMethod(java.lang.reflect.Method method)
-
-