public class FuzzyReflection extends Object
| Constructor and Description |
|---|
FuzzyReflection(Class<?> source,
boolean forceAccess) |
| Modifier and Type | Method and Description |
|---|---|
static FuzzyReflection |
fromClass(Class<?> source)
Retrieves a fuzzy reflection instance from a given class.
|
static FuzzyReflection |
fromClass(Class<?> source,
boolean forceAccess)
Retrieves a fuzzy reflection instance from a given class.
|
static FuzzyReflection |
fromObject(Object reference)
Retrieves a fuzzy reflection instance from an object.
|
static FuzzyReflection |
fromObject(Object reference,
boolean forceAccess)
Retrieves a fuzzy reflection instance from an object.
|
Constructor<?> |
getConstructor(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve the first constructor that matches.
|
List<Constructor<?>> |
getConstructorList(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve a list of every constructor that matches the given matcher.
|
Set<Constructor<?>> |
getConstructors()
Retrieves all private and public constructors in declared order (after JDK 1.5).
|
Set<Field> |
getDeclaredFields(Class<?> excludeClass)
Retrieves all private and public fields, up until a certain superclass.
|
Field |
getField(AbstractFuzzyMatcher<Field> matcher)
Retrieve the first field that matches.
|
Field |
getFieldByName(String nameRegex)
Retrieves a field by name.
|
Field |
getFieldByType(String typeRegex)
Retrieves a field by type.
|
Field |
getFieldByType(String name,
Class<?> type)
Retrieves the first field with a type equal to or more specific to the given type.
|
Field |
getFieldByType(String typeRegex,
Set<Class> ignored)
Retrieves a field by type.
|
List<Field> |
getFieldList(AbstractFuzzyMatcher<Field> matcher)
Retrieve a list of every field that matches the given matcher.
|
List<Field> |
getFieldListByType(Class<?> type)
Retrieves every field with a type equal to or more specific to the given type.
|
Set<Field> |
getFields()
Retrieves all private and public fields in declared order (after JDK 1.5).
|
static <T> T |
getFieldValue(Object instance,
Class<T> fieldClass,
boolean forceAccess)
Retrieve the value of the first field of the given type.
|
Map<String,Method> |
getMappedMethods(List<Method> methods)
Retrieve every method as a map over names.
|
Method |
getMethod(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve the first method that matches.
|
Method |
getMethod(AbstractFuzzyMatcher<MethodInfo> matcher,
String preferred)
Retrieve a method that matches.
|
Method |
getMethodByName(String nameRegex)
Retrieves a method by looking at its name.
|
Method |
getMethodByParameters(String name,
Class<?>... args)
Retrieves a method by looking at the parameter types only.
|
Method |
getMethodByParameters(String name,
Class<?> returnType,
Class<?>[] args)
Retrieves a method by looking at the parameter types and return type only.
|
Method |
getMethodByParameters(String name,
String returnTypeRegex,
String[] argsRegex)
Retrieves a method by looking at the parameter types and return type only.
|
List<Method> |
getMethodList(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve a list of every method that matches the given matcher.
|
List<Method> |
getMethodListByParameters(Class<?> returnType,
Class<?>[] args)
Retrieves every method that has the given parameter types and return type.
|
Set<Method> |
getMethods()
Retrieves all private and public methods in declared order (after JDK 1.5).
|
Object |
getSingleton()
Retrieve the singleton instance of a class, from a method or field.
|
Class<?> |
getSource()
Retrieves the underlying class.
|
Object |
invokeMethod(Object target,
String name,
Class<?> returnType,
Object... parameters)
Invoke a method by return type and parameters alone.
|
boolean |
isForceAccess()
Retrieves whether or not not to override any scope restrictions.
|
void |
setForceAccess(boolean forceAccess)
Sets whether or not not to override any scope restrictions.
|
public FuzzyReflection(Class<?> source, boolean forceAccess)
public static FuzzyReflection fromClass(Class<?> source)
source - - the class we'll use.public static FuzzyReflection fromClass(Class<?> source, boolean forceAccess)
source - - the class we'll use.forceAccess - - whether or not to override scope restrictions.public static FuzzyReflection fromObject(Object reference)
reference - - the object we'll use.public static FuzzyReflection fromObject(Object reference, boolean forceAccess)
reference - - the object we'll use.forceAccess - - whether or not to override scope restrictions.public static <T> T getFieldValue(Object instance, Class<T> fieldClass, boolean forceAccess)
T - Typeinstance - - the instance to retrieve from.fieldClass - - type of the field to retrieve.forceAccess - - whether or not to look for private and protected fields.IllegalArgumentException - If the field cannot be found.public Class<?> getSource()
public Object getSingleton()
IllegalStateException - If the class has no singleton.public Method getMethod(AbstractFuzzyMatcher<MethodInfo> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level method.
matcher - - the matcher to use.IllegalArgumentException - If the method cannot be found.public Method getMethod(AbstractFuzzyMatcher<MethodInfo> matcher, String preferred)
ForceAccess must be TRUE in order for this method to access private, protected and package level method.
matcher - - the matcher to use.preferred - - the preferred name.IllegalArgumentException - If the method cannot be found.public List<Method> getMethodList(AbstractFuzzyMatcher<MethodInfo> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level methods.
matcher - - the matcher to apply.public Method getMethodByName(String nameRegex)
nameRegex - - regular expression that will match method names.IllegalArgumentException - If the method cannot be found.public Method getMethodByParameters(String name, Class<?>... args)
name - - potential name of the method. Only used by the error mechanism.args - - parameter types of the method to find.IllegalArgumentException - If the method cannot be found.public Method getMethodByParameters(String name, Class<?> returnType, Class<?>[] args)
name - - potential name of the method. Only used by the error mechanism.returnType - - return type of the method to find.args - - parameter types of the method to find.IllegalArgumentException - If the method cannot be found.public Method getMethodByParameters(String name, String returnTypeRegex, String[] argsRegex)
name - - potential name of the method. Only used by the error mechanism.returnTypeRegex - - regular expression matching the return type of the method to find.argsRegex - - regular expressions of the matching parameter types.IllegalArgumentException - If the method cannot be found.public Object invokeMethod(Object target, String name, Class<?> returnType, Object... parameters)
The parameters must be non-null for this to work.
target - - the instance.name - - the name of the method - for debugging.returnType - - the expected return type.parameters - - the parameters.public List<Method> getMethodListByParameters(Class<?> returnType, Class<?>[] args)
returnType - - return type of the method to find.args - - parameter types of the method to find.public Field getFieldByName(String nameRegex)
nameRegex - - regular expression that will match a field name.IllegalArgumentException - If the field cannot be found.public Field getFieldByType(String name, Class<?> type)
name - - name the field probably is given. This will only be used in the error message.type - - type of the field to find.public List<Field> getFieldListByType(Class<?> type)
type - - type of the fields to find.public Field getField(AbstractFuzzyMatcher<Field> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level fields.
matcher - - the matcher to use.IllegalArgumentException - If the method cannot be found.public List<Field> getFieldList(AbstractFuzzyMatcher<Field> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level fields.
matcher - - the matcher to apply.public Field getFieldByType(String typeRegex)
Note that the type is matched using the full canonical representation, i.e.:
typeRegex - - regular expression that will match the field type.IllegalArgumentException - If the field cannot be found.public Field getFieldByType(String typeRegex, Set<Class> ignored)
Note that the type is matched using the full canonical representation, i.e.:
typeRegex - - regular expression that will match the field type.ignored - - types to ignore.IllegalArgumentException - If the field cannot be found.public Constructor<?> getConstructor(AbstractFuzzyMatcher<MethodInfo> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level constructors.
matcher - - the matcher to use.IllegalArgumentException - If the constructor cannot be found.public Map<String,Method> getMappedMethods(List<Method> methods)
Note that overloaded methods will only occur once in the resulting map.
methods - - every method.public List<Constructor<?>> getConstructorList(AbstractFuzzyMatcher<MethodInfo> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level constructors.
matcher - - the matcher to apply.public Set<Field> getFields()
Private, protected and package fields are ignored if forceAccess is FALSE.
public Set<Field> getDeclaredFields(Class<?> excludeClass)
excludeClass - - the class (and its superclasses) to exclude from the search.public Set<Method> getMethods()
Private, protected and package methods are ignored if forceAccess is FALSE.
public Set<Constructor<?>> getConstructors()
Private, protected and package constructors are ignored if forceAccess is FALSE.
public boolean isForceAccess()
public void setForceAccess(boolean forceAccess)
forceAccess - - TRUE if we override scope, FALSE otherwise.Copyright © 2012–2017 Comphenix and dmulloy2. Licensed under the GNU GPL v2.