public class Reflections
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Reflections.ReflectionAccessException |
static class |
Reflections.ReflectionNotFoundException |
Constructor and Description |
---|
Reflections(java.lang.ClassLoader classLoader) |
Modifier and Type | Method and Description |
---|---|
Reflections |
applyClassRenames(java.util.Map<java.lang.String,java.lang.String> newClassRenames)
supply a map of known renames, of the form "old-class -> new-class"
|
static java.util.List<?> |
arrayToList(java.lang.Object input) |
static <T> T |
cast(java.lang.Object candidate,
java.lang.Class<? extends T> type)
convenience for casting the given candidate to the given type (without any coercion, and allowing candidate to be null)
|
static <T> void |
copyFields(T source,
T target)
copies all fields from the source to target; very little compile-time safety checking, so use with care
|
static Maybe<java.lang.reflect.Method> |
findAccessibleMethod(java.lang.reflect.Method method)
Attempts to find an equivalent accessible method to be invoked (or if the given method is
already accessible, then return it).
|
static java.lang.reflect.Field |
findField(java.lang.Class<?> clazz,
java.lang.String name)
Finds the field with the given name declared on the given class or any superclass,
using
Class.getDeclaredField(String) . |
static Maybe<java.lang.reflect.Field> |
findFieldMaybe(java.lang.Class<?> clazz,
java.lang.String originalName) |
static java.util.List<java.lang.reflect.Field> |
findFields(java.lang.Class<?> clazz,
<any> filter,
java.util.Comparator<java.lang.reflect.Field> fieldOrdering)
Lists all fields declared on the class, with those lowest in the hierarchy first,
filtered and ordered as requested.
|
static java.lang.String |
findMappedNameAndLog(java.util.Map<java.lang.String,java.lang.String> renames,
java.lang.String name) |
static Maybe<java.lang.String> |
findMappedNameMaybe(java.util.Map<java.lang.String,java.lang.String> renames,
java.lang.String name)
Takes a map of old-class-names to renames classes, and returns the mapped name if matched, or absent
|
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... parameterTypes)
Deprecated.
|
static Maybe<java.lang.reflect.Method> |
findMethodMaybe(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... parameterTypes)
Returns any method exactly matching the given signature, including privates and on parent classes.
|
static java.lang.Iterable<java.lang.reflect.Method> |
findMethodsCompatible(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... parameterTypes)
Returns all methods compatible with the given argument types, including privates and on parent classes and where the method takes a supertype.
|
static java.util.List<java.lang.reflect.Field> |
findPublicFieldsOrderedBySuper(java.lang.Class<?> clazz)
Lists all public fields declared on the class or any ancestor, with those HIGHEST in the hierarchy first
|
static java.util.List<java.lang.reflect.Method> |
findPublicMethodsOrderedBySuper(java.lang.Class<?> clazz) |
static <T> java.lang.Class<? super T> |
findSuperType(T impl,
java.lang.String typeName) |
static java.util.List<java.lang.Class<?>> |
getAllInterfaces(java.lang.Class<?> type)
Gets all the interfaces implemented by the given type, including its parent classes.
|
java.lang.ClassLoader |
getClassLoader() |
static Maybe<java.lang.Object> |
getFieldValueMaybe(java.lang.Object instance,
java.lang.reflect.Field field) |
static Maybe<java.lang.Object> |
getFieldValueMaybe(java.lang.Object instance,
java.lang.String fieldName) |
static <any>[] |
getGenericParameterTypeTokens(<any> t) |
static java.util.Set<java.lang.Class<?>> |
getInterfacesIncludingClassAncestors(java.lang.Class<?> clazz)
whereas Class.getInterfaces() only returns interfaces directly implemented by a class,
this walks the inheritance hierarchy to include interfaces implemented by superclass/ancestors;
(note it does not include superinterfaces)
|
static Maybe<java.lang.reflect.Method> |
getMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args)
searches for the given method on the given clazz or instance, doing reasonably good matching on args etc
|
static Maybe<java.lang.reflect.Method> |
getMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args,
<any> coercer)
searches for the given method on the given clazz or instance, doing reasonably good matching on args etc
|
java.net.URL |
getResource(java.lang.String r)
finds the resource in the classloader, if it exists; inserts or replaces leading slash as necessary
(i believe it should _not_ have one, but there is some inconsistency)
Will return null if no resource is found.
|
static boolean |
hasNoArgConstructor(java.lang.Class<?> clazz) |
static boolean |
hasNoNonObjectFields(java.lang.Class<? extends java.lang.Object> clazz) |
static boolean |
hasSpecialSerializationMethods(java.lang.Class<? extends java.lang.Object> type) |
static java.lang.Class<?> |
inferSubbest(java.lang.Class<?> c1,
java.lang.Class<?> c2)
If one class is a subclass of the other, return that (the lower in the type hierarchy);
otherwise return null (if they are the same or neither is a subclass of the other).
|
static java.lang.reflect.Field |
inferSubbestField(java.lang.reflect.Field f1,
java.lang.reflect.Field f2)
If the classes of the fields satisfy
inferSubbest(Class, Class)
return the field in the lower (sub-best) class, otherwise null. |
static java.lang.reflect.Method |
inferSubbestMethod(java.lang.reflect.Method m1,
java.lang.reflect.Method m2)
If the classes of the methods satisfy
inferSubbest(Class, Class)
return the field in the lower (sub-best) class, otherwise null. |
static <T> Maybe<T> |
invokeConstructorFromArgs(java.lang.Class<? extends T> clazz,
java.lang.Object... argsArray)
Finds and invokes a suitable constructor, supporting varargs and primitives, boxing and looking at compatible supertypes in the constructor's signature
|
static <T> Maybe<T> |
invokeConstructorFromArgs(java.lang.Class<? extends T> clazz,
java.lang.Object[] argsArray,
boolean setAccessible)
As
invokeConstructorFromArgs(Class, Object...) but allowing more configurable input;
in particular setAccessible allows private constructors to be used (not the default) |
static <T> Maybe<T> |
invokeConstructorFromArgs(java.lang.ClassLoader classLoader,
java.lang.Class<T> clazz,
java.lang.Object[] argsArray,
boolean setAccessible)
As
invokeConstructorFromArgs(Class, Object...) but allowing more configurable input;
in particular setAccessible allows private constructors to be used (not the default) |
static <T> Maybe<T> |
invokeConstructorFromArgs(java.lang.ClassLoader classLoader,
java.lang.Class<T> optionalSupertype,
java.lang.String className,
java.lang.Object... argsArray)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
static Maybe<java.lang.Object> |
invokeConstructorFromArgs(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.Object... argsArray)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
static <T> Maybe<T> |
invokeConstructorFromArgs(Reflections reflections,
java.lang.Class<? extends T> clazz,
java.lang.Object[] argsArray,
boolean setAccessible)
As
invokeConstructorFromArgs(Class, Object...) but allowing more configurable input;
in particular setAccessible allows private constructors to be used (not the default) |
static <T> Maybe<T> |
invokeConstructorFromArgsIncludingPrivate(java.lang.Class<? extends T> clazz,
java.lang.Object... argsArray)
As
invokeConstructorFromArgs(Class, Object...) but will use private constructors (with setAccessible = true) |
static <T> Maybe<T> |
invokeConstructorFromArgsUntyped(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.Object... argsArray)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
static <T> <any> |
invokeConstructorWithArgs(java.lang.Class<? extends T> clazz,
java.lang.Object... argsArray)
Deprecated.
since 0.10.0 use
invokeConstructorFromArgs(Class, Object...) or one of the variants |
static <T> <any> |
invokeConstructorWithArgs(java.lang.Class<? extends T> clazz,
java.lang.Object[] argsArray,
boolean setAccessible)
Deprecated.
since 0.10.0 use
invokeConstructorFromArgs(Class, Object...) or one of the variants |
static <T> <any> |
invokeConstructorWithArgs(java.lang.ClassLoader classLoader,
java.lang.Class<T> clazz,
java.lang.Object[] argsArray,
boolean setAccessible)
Deprecated.
since 0.10.0 use
invokeConstructorFromArgs(Class, Object...) or one of the variants |
static <T> <any> |
invokeConstructorWithArgs(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.Object... argsArray)
Deprecated.
since 0.10.0 use
invokeConstructorFromArgs(Class, Object...) or one of the variants;
this allows null field values |
static <T> <any> |
invokeConstructorWithArgs(Reflections reflections,
java.lang.Class<? extends T> clazz,
java.lang.Object[] argsArray,
boolean setAccessible)
Deprecated.
since 0.10.0 use
invokeConstructorFromArgs(Class, Object...) or one of the variants |
java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object... argValues) |
static java.lang.Object |
invokeMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.reflect.Method m,
java.util.List<?> args)
invokes the given method on the given clazz or instance, assuming that the method matches passed arguments
|
static java.lang.Object |
invokeMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.reflect.Method m,
java.util.List<?> args,
boolean setAccessible)
as
invokeMethodFromArgs(Object, Method, List) but giving control over whether to set it accessible |
static java.lang.Object |
invokeMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.reflect.Method m,
java.util.List<?> args,
boolean setAccessible,
<any> coercer)
as
invokeMethodFromArgs(Object, Method, List) but giving control over whether to set it accessible |
static Maybe<java.lang.Object> |
invokeMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args)
invokes the given method on the given clazz or instance, doing reasonably good matching on args etc
|
static Maybe<java.lang.Object> |
invokeMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args,
boolean setAccessible)
as
invokeMethodFromArgs(Object, String, List) but giving control over whether to set it accessible |
static Maybe<java.lang.Object> |
invokeMethodFromArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args,
boolean setAccessible,
<any> coercer)
as
invokeMethodFromArgs(Object, String, List) but giving control over whether to set it accessible |
static <any> |
invokeMethodWithArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args)
Deprecated.
since 0.10.0 use
invokeMethodFromArgs(Object, String, List) ;
this allows null return values |
static <any> |
invokeMethodWithArgs(java.lang.Object clazzOrInstance,
java.lang.String method,
java.util.List<?> args,
boolean setAccessible)
Deprecated.
since 0.10.0 use
invokeMethodFromArgs(Object, String, List) |
java.lang.Object |
invokeStaticMethod(java.lang.reflect.Method method,
java.lang.Object... argValues) |
java.lang.Class<?> |
loadClass(java.lang.String classname)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
<T> java.lang.Class<? extends T> |
loadClass(java.lang.String classname,
java.lang.Class<T> superType)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
java.lang.Class<?> |
loadClassFromCanonicalName(java.lang.String canonicalName)
Loads class given its canonical name format (e.g.
|
java.lang.reflect.Constructor<?> |
loadConstructor(java.lang.Class<?> clazz,
java.lang.Class<?>[] argTypes) |
java.lang.Class<?> |
loadInnerClassNotInheritted(java.lang.Class<?> outerClazz,
java.lang.String innerClassname)
does not look through ancestors of outer class
|
java.lang.Class<?> |
loadInnerClassNotInheritted(java.lang.String outerClassname,
java.lang.String innerClassname)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
static java.lang.Class<?> |
loadInnerClassPossiblyInheritted(java.lang.Class<?> clazz,
java.lang.String nestedPart)
given a nested part, e.g.
|
<T> T |
loadInstance(java.lang.reflect.Constructor<T> constructor,
java.lang.Object... argValues) |
java.lang.Object |
loadInstance(java.lang.String classname)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
java.lang.Object |
loadInstance(java.lang.String classname,
java.lang.Class<?>[] argTypes,
java.lang.Object[] argValues)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
java.lang.Object |
loadInstance(java.lang.String classname,
java.lang.Object... argValues)
Deprecated.
since 0.11.0, use
ClassLoaderUtils in a combination with invokeConstructorFromArgs(Class, Object...) instead |
java.lang.reflect.Method |
loadMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
returns the first method matching the given name
|
java.lang.reflect.Method |
loadMethod(java.lang.Class<?> clazz,
java.lang.String methodName,
java.lang.Class<?>[] argTypes) |
java.lang.reflect.Constructor<?> |
loadSingleConstructor(java.lang.Class<?> clazz)
returns a single constructor in a given class, or throws an exception
|
java.lang.Object |
loadStaticField(java.lang.Class<?> clazz,
java.lang.String fieldname) |
java.lang.Object[] |
loadStaticFields(java.lang.Class<?> clazz,
java.lang.String[] fieldnamesArray,
java.lang.Object[] defaults) |
static <any> |
tryFindMappedName(java.util.Map<java.lang.String,java.lang.String> renames,
java.lang.String name)
Deprecated.
since 0.10.0 use
findMappedNameMaybe(Map, String) |
static boolean |
trySetAccessible(java.lang.reflect.Method method)
Calls
AccessibleObject.setAccessible(boolean) "safely", wrapping in a try-catch block so that
the exception is never propagated. |
static boolean |
typeMatches(java.lang.Object arg,
java.lang.Class<?> parameterType,
<any> coercer)
true iff the initial N args match the corresponding types
|
static boolean |
typesMatch(java.lang.Object[] argsArray,
java.lang.Class<?>[] parameterTypes)
true iff all args match the corresponding types
|
static boolean |
typesMatch(java.lang.Object[] argsArray,
java.lang.Class<?>[] parameterTypes,
<any> coercer)
true iff all args match the corresponding types
|
static boolean |
typesMatchUpTo(java.lang.Object[] argsArray,
java.lang.Class<?>[] parameterTypes,
int lengthRequired)
true iff the initial N args match the corresponding types
|
static boolean |
typesMatchUpTo(java.lang.Object[] argsArray,
java.lang.Class<?>[] parameterTypes,
int lengthRequired,
<any> coercer)
true iff the initial N args match the corresponding types
|
java.lang.Object |
updateFromNewClassLoader(java.lang.Object data)
Serialize the given object, then reload using the current class loader;
this removes linkages to instances with classes loaded by an older class loader.
|
public Reflections applyClassRenames(java.util.Map<java.lang.String,java.lang.String> newClassRenames)
public java.lang.Object loadInstance(java.lang.String classname, java.lang.Object... argValues) throws Reflections.ReflectionNotFoundException, Reflections.ReflectionAccessException
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic java.lang.Object loadInstance(java.lang.String classname, java.lang.Class<?>[] argTypes, java.lang.Object[] argValues) throws Reflections.ReflectionNotFoundException, Reflections.ReflectionAccessException
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic java.lang.Object loadInstance(java.lang.String classname) throws Reflections.ReflectionNotFoundException, Reflections.ReflectionAccessException
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic java.lang.Class<?> loadClass(java.lang.String classname) throws Reflections.ReflectionNotFoundException
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic <T> java.lang.Class<? extends T> loadClass(java.lang.String classname, java.lang.Class<T> superType) throws Reflections.ReflectionNotFoundException
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic static java.lang.Class<?> loadInnerClassPossiblyInheritted(java.lang.Class<?> clazz, java.lang.String nestedPart) throws Reflections.ReflectionNotFoundException
so it will find Clazz.Inner.VeryInner wherever in the hierarchy it is defined
(as opposed to ClassLoader which requires Inner.VeryInner to be _declared_ in clazz, not in any supertype
returns null if not found
public java.lang.Class<?> loadInnerClassNotInheritted(java.lang.String outerClassname, java.lang.String innerClassname) throws Reflections.ReflectionNotFoundException
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic java.lang.Class<?> loadInnerClassNotInheritted(java.lang.Class<?> outerClazz, java.lang.String innerClassname) throws Reflections.ReflectionNotFoundException
uses the classloader set in this class, not in the clazz supplied
public java.lang.reflect.Constructor<?> loadConstructor(java.lang.Class<?> clazz, java.lang.Class<?>[] argTypes) throws Reflections.ReflectionAccessException
@Deprecated public static <T> <any> invokeConstructorWithArgs(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.Object... argsArray)
invokeConstructorFromArgs(Class, Object...)
or one of the variants;
this allows null field values@Deprecated public static <T> <any> invokeConstructorWithArgs(java.lang.ClassLoader classLoader, java.lang.Class<T> clazz, java.lang.Object[] argsArray, boolean setAccessible)
invokeConstructorFromArgs(Class, Object...)
or one of the variants@Deprecated public static <T> <any> invokeConstructorWithArgs(java.lang.Class<? extends T> clazz, java.lang.Object... argsArray)
invokeConstructorFromArgs(Class, Object...)
or one of the variants@Deprecated public static <T> <any> invokeConstructorWithArgs(java.lang.Class<? extends T> clazz, java.lang.Object[] argsArray, boolean setAccessible)
invokeConstructorFromArgs(Class, Object...)
or one of the variants@Deprecated public static <T> <any> invokeConstructorWithArgs(Reflections reflections, java.lang.Class<? extends T> clazz, java.lang.Object[] argsArray, boolean setAccessible)
invokeConstructorFromArgs(Class, Object...)
or one of the variantspublic static <T> Maybe<T> invokeConstructorFromArgs(java.lang.Class<? extends T> clazz, java.lang.Object... argsArray)
public static Maybe<java.lang.Object> invokeConstructorFromArgs(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.Object... argsArray)
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic static <T> Maybe<T> invokeConstructorFromArgs(java.lang.ClassLoader classLoader, java.lang.Class<T> optionalSupertype, java.lang.String className, java.lang.Object... argsArray)
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic static <T> Maybe<T> invokeConstructorFromArgsUntyped(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.Object... argsArray)
ClassLoaderUtils
in a combination with invokeConstructorFromArgs(Class, Object...)
insteadpublic static <T> Maybe<T> invokeConstructorFromArgs(java.lang.ClassLoader classLoader, java.lang.Class<T> clazz, java.lang.Object[] argsArray, boolean setAccessible)
invokeConstructorFromArgs(Class, Object...)
but allowing more configurable input;
in particular setAccessible allows private constructors to be used (not the default)public static <T> Maybe<T> invokeConstructorFromArgs(java.lang.Class<? extends T> clazz, java.lang.Object[] argsArray, boolean setAccessible)
invokeConstructorFromArgs(Class, Object...)
but allowing more configurable input;
in particular setAccessible allows private constructors to be used (not the default)public static <T> Maybe<T> invokeConstructorFromArgsIncludingPrivate(java.lang.Class<? extends T> clazz, java.lang.Object... argsArray)
invokeConstructorFromArgs(Class, Object...)
but will use private constructors (with setAccessible = true)public static <T> Maybe<T> invokeConstructorFromArgs(Reflections reflections, java.lang.Class<? extends T> clazz, java.lang.Object[] argsArray, boolean setAccessible)
invokeConstructorFromArgs(Class, Object...)
but allowing more configurable input;
in particular setAccessible allows private constructors to be used (not the default)public java.lang.reflect.Constructor<?> loadSingleConstructor(java.lang.Class<?> clazz)
public <T> T loadInstance(java.lang.reflect.Constructor<T> constructor, java.lang.Object... argValues) throws java.lang.IllegalArgumentException, Reflections.ReflectionAccessException
java.lang.IllegalArgumentException
Reflections.ReflectionAccessException
public java.lang.reflect.Method loadMethod(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>[] argTypes) throws Reflections.ReflectionNotFoundException, Reflections.ReflectionAccessException
public java.lang.reflect.Method loadMethod(java.lang.Class<?> clazz, java.lang.String methodName) throws Reflections.ReflectionNotFoundException, Reflections.ReflectionAccessException
public java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object... argValues) throws Reflections.ReflectionAccessException
Reflections.ReflectionAccessException
- If invocation failed due to illegal access or the invoked method failedjava.lang.IllegalArgumentException
- If the arguments were invalidpublic java.lang.Object invokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... argValues) throws java.lang.IllegalArgumentException, Reflections.ReflectionAccessException
java.lang.IllegalArgumentException
Reflections.ReflectionAccessException
public java.lang.Object loadStaticField(java.lang.Class<?> clazz, java.lang.String fieldname) throws Reflections.ReflectionAccessException
public java.lang.Object[] loadStaticFields(java.lang.Class<?> clazz, java.lang.String[] fieldnamesArray, java.lang.Object[] defaults) throws Reflections.ReflectionAccessException
public static <T> void copyFields(T source, T target) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
public java.lang.Class<?> loadClassFromCanonicalName(java.lang.String canonicalName) throws java.lang.ClassNotFoundException, Reflections.ReflectionNotFoundException
Reflections.ReflectionNotFoundException
java.lang.ClassNotFoundException
@Nullable public java.net.URL getResource(java.lang.String r)
public final java.lang.Object updateFromNewClassLoader(java.lang.Object data) throws java.io.IOException, java.lang.ClassNotFoundException
(like a poor man's clone)
aka "reconstitute(Object)"
java.io.IOException
java.lang.ClassNotFoundException
public java.lang.ClassLoader getClassLoader()
public static <T> java.lang.Class<? super T> findSuperType(T impl, java.lang.String typeName)
public static java.util.Set<java.lang.Class<?>> getInterfacesIncludingClassAncestors(java.lang.Class<?> clazz)
public static Maybe<java.lang.reflect.Method> findMethodMaybe(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)
public static java.lang.Iterable<java.lang.reflect.Method> findMethodsCompatible(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes)
@Deprecated public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>... parameterTypes) throws java.lang.NoSuchMethodException
findMethodMaybe(Class, String, Class...)
or findMethodsCompatible(Class, String, Class...)
java.lang.NoSuchMethodException
public static java.lang.reflect.Field findField(java.lang.Class<?> clazz, java.lang.String name) throws java.lang.NoSuchFieldException
Class.getDeclaredField(String)
.
If the field name contains a '.' the field is interpreted as having
DeclaringClassCanonicalName.FieldName
format,
allowing a way to set a field unambiguously if some are masked.
java.lang.NoSuchFieldException
- if not foundpublic static Maybe<java.lang.reflect.Field> findFieldMaybe(java.lang.Class<?> clazz, java.lang.String originalName)
public static Maybe<java.lang.Object> getFieldValueMaybe(java.lang.Object instance, java.lang.String fieldName)
public static Maybe<java.lang.Object> getFieldValueMaybe(java.lang.Object instance, java.lang.reflect.Field field)
public static java.util.List<java.lang.reflect.Field> findPublicFieldsOrderedBySuper(java.lang.Class<?> clazz)
public static java.util.List<java.lang.reflect.Field> findFields(java.lang.Class<?> clazz, <any> filter, java.util.Comparator<java.lang.reflect.Field> fieldOrdering)
See ReflectionPredicates
and FieldOrderings
for conveniences.
Default is no filter and FieldOrderings.SUB_BEST_FIELD_LAST_THEN_ALPHABETICAL
public static java.util.List<java.lang.reflect.Method> findPublicMethodsOrderedBySuper(java.lang.Class<?> clazz)
public static java.lang.reflect.Field inferSubbestField(java.lang.reflect.Field f1, java.lang.reflect.Field f2)
inferSubbest(Class, Class)
return the field in the lower (sub-best) class, otherwise null.public static java.lang.reflect.Method inferSubbestMethod(java.lang.reflect.Method m1, java.lang.reflect.Method m2)
inferSubbest(Class, Class)
return the field in the lower (sub-best) class, otherwise null.public static java.lang.Class<?> inferSubbest(java.lang.Class<?> c1, java.lang.Class<?> c2)
public static <T> T cast(java.lang.Object candidate, java.lang.Class<? extends T> type)
@Deprecated public static <any> invokeMethodWithArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
invokeMethodFromArgs(Object, String, List)
;
this allows null return valuesjava.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
@Deprecated public static <any> invokeMethodWithArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args, boolean setAccessible) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
invokeMethodFromArgs(Object, String, List)
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static Maybe<java.lang.Object> invokeMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
public static Maybe<java.lang.Object> invokeMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args, boolean setAccessible) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
invokeMethodFromArgs(Object, String, List)
but giving control over whether to set it accessiblejava.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static Maybe<java.lang.Object> invokeMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args, boolean setAccessible, <any> coercer) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
invokeMethodFromArgs(Object, String, List)
but giving control over whether to set it accessiblejava.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static Maybe<java.lang.reflect.Method> getMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args)
public static Maybe<java.lang.reflect.Method> getMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.String method, java.util.List<?> args, <any> coercer)
public static java.lang.Object invokeMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.reflect.Method m, java.util.List<?> args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
public static java.lang.Object invokeMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.reflect.Method m, java.util.List<?> args, boolean setAccessible) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
invokeMethodFromArgs(Object, Method, List)
but giving control over whether to set it accessiblejava.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Object invokeMethodFromArgs(java.lang.Object clazzOrInstance, java.lang.reflect.Method m, java.util.List<?> args, boolean setAccessible, <any> coercer) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
invokeMethodFromArgs(Object, Method, List)
but giving control over whether to set it accessiblejava.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static boolean typesMatch(java.lang.Object[] argsArray, java.lang.Class<?>[] parameterTypes)
public static boolean typesMatch(java.lang.Object[] argsArray, java.lang.Class<?>[] parameterTypes, <any> coercer)
public static boolean typesMatchUpTo(java.lang.Object[] argsArray, java.lang.Class<?>[] parameterTypes, int lengthRequired)
public static boolean typesMatchUpTo(java.lang.Object[] argsArray, java.lang.Class<?>[] parameterTypes, int lengthRequired, <any> coercer)
public static boolean typeMatches(java.lang.Object arg, java.lang.Class<?> parameterType, <any> coercer)
public static java.util.List<java.lang.Class<?>> getAllInterfaces(@Nullable java.lang.Class<?> type)
type
- the class to look uppublic static boolean hasNoArgConstructor(java.lang.Class<?> clazz)
public static boolean hasNoNonObjectFields(java.lang.Class<? extends java.lang.Object> clazz)
@Deprecated public static <any> tryFindMappedName(java.util.Map<java.lang.String,java.lang.String> renames, java.lang.String name)
findMappedNameMaybe(Map, String)
public static Maybe<java.lang.String> findMappedNameMaybe(java.util.Map<java.lang.String,java.lang.String> renames, java.lang.String name)
public static java.lang.String findMappedNameAndLog(java.util.Map<java.lang.String,java.lang.String> renames, java.lang.String name)
public static boolean hasSpecialSerializationMethods(java.lang.Class<? extends java.lang.Object> type)
public static java.util.List<?> arrayToList(java.lang.Object input)
public static Maybe<java.lang.reflect.Method> findAccessibleMethod(java.lang.reflect.Method method)
method
is declared on a private sub-class, but that overides a
method declared on a public super-class, then this method will return the Method
instance for the public super-class (assuming the method is not static).
If no better method could be found, it does a log.warn (once per method signature, per
jvm-invocation), and then returns absent.public static boolean trySetAccessible(java.lang.reflect.Method method)
AccessibleObject.setAccessible(boolean)
"safely", wrapping in a try-catch block so that
the exception is never propagated.
It will log.warn once per method signature for which we fail to set it accessible. It will also log.warn if it succeeds (once per method signature) as this is discouraged!
public static <any>[] getGenericParameterTypeTokens(<any> t)