public class FuzzyReflection
extends java.lang.Object
Constructor and Description |
---|
FuzzyReflection(java.lang.Class<?> source,
boolean forceAccess) |
Modifier and Type | Method and Description |
---|---|
static FuzzyReflection |
fromClass(java.lang.Class<?> source)
Retrieves a fuzzy reflection instance from a given class.
|
static FuzzyReflection |
fromClass(java.lang.Class<?> source,
boolean forceAccess)
Retrieves a fuzzy reflection instance from a given class.
|
static FuzzyReflection |
fromObject(java.lang.Object reference)
Retrieves a fuzzy reflection instance from an object.
|
static FuzzyReflection |
fromObject(java.lang.Object reference,
boolean forceAccess)
Retrieves a fuzzy reflection instance from an object.
|
java.lang.reflect.Constructor<?> |
getConstructor(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve the first constructor that matches.
|
java.util.List<java.lang.reflect.Constructor<?>> |
getConstructorList(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve a list of every constructor that matches the given matcher.
|
java.util.Set<java.lang.reflect.Constructor<?>> |
getConstructors()
Retrieves all private and public constructors in declared order (after JDK 1.5).
|
java.lang.reflect.Field |
getField(AbstractFuzzyMatcher<java.lang.reflect.Field> matcher)
Retrieve the first field that matches.
|
java.lang.reflect.Field |
getFieldByName(java.lang.String nameRegex)
Retrieves a field by name.
|
java.lang.reflect.Field |
getFieldByType(java.lang.String typeRegex)
Retrieves a field by type.
|
java.lang.reflect.Field |
getFieldByType(java.lang.String name,
java.lang.Class<?> type)
Retrieves the first field with a type equal to or more specific to the given type.
|
java.lang.reflect.Field |
getFieldByType(java.lang.String typeRegex,
java.util.Set<java.lang.Class> ignored)
Retrieves a field by type.
|
java.util.List<java.lang.reflect.Field> |
getFieldList(AbstractFuzzyMatcher<java.lang.reflect.Field> matcher)
Retrieve a list of every field that matches the given matcher.
|
java.util.List<java.lang.reflect.Field> |
getFieldListByType(java.lang.Class<?> type)
Retrieves every field with a type equal to or more specific to the given type.
|
java.util.Set<java.lang.reflect.Field> |
getFields()
Retrieves all private and public fields in declared order (after JDK 1.5).
|
java.util.Map<java.lang.String,java.lang.reflect.Method> |
getMappedMethods(java.util.List<java.lang.reflect.Method> methods)
Retrieve every method as a map over names.
|
java.lang.reflect.Method |
getMethod(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve the first method that matches.
|
java.lang.reflect.Method |
getMethodByName(java.lang.String nameRegex)
Retrieves a method by looking at its name.
|
java.lang.reflect.Method |
getMethodByParameters(java.lang.String name,
java.lang.Class<?>... args)
Retrieves a method by looking at the parameter types only.
|
java.lang.reflect.Method |
getMethodByParameters(java.lang.String name,
java.lang.Class<?> returnType,
java.lang.Class<?>[] args)
Retrieves a method by looking at the parameter types and return type only.
|
java.lang.reflect.Method |
getMethodByParameters(java.lang.String name,
java.lang.String returnTypeRegex,
java.lang.String[] argsRegex)
Retrieves a method by looking at the parameter types and return type only.
|
java.util.List<java.lang.reflect.Method> |
getMethodList(AbstractFuzzyMatcher<MethodInfo> matcher)
Retrieve a list of every method that matches the given matcher.
|
java.util.List<java.lang.reflect.Method> |
getMethodListByParameters(java.lang.Class<?> returnType,
java.lang.Class<?>[] args)
Retrieves every method that has the given parameter types and return type.
|
java.util.Set<java.lang.reflect.Method> |
getMethods()
Retrieves all private and public methods in declared order (after JDK 1.5).
|
java.lang.Class<?> |
getSource()
Retrieves the underlying class.
|
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(java.lang.Class<?> source, boolean forceAccess)
public static FuzzyReflection fromClass(java.lang.Class<?> source)
source
- - the class we'll use.public static FuzzyReflection fromClass(java.lang.Class<?> source, boolean forceAccess)
source
- - the class we'll use.forceAccess
- - whether or not to override scope restrictions.public static FuzzyReflection fromObject(java.lang.Object reference)
reference
- - the object we'll use.public static FuzzyReflection fromObject(java.lang.Object reference, boolean forceAccess)
reference
- - the object we'll use.forceAccess
- - whether or not to override scope restrictions.public java.lang.Class<?> getSource()
public java.lang.reflect.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.java.lang.IllegalArgumentException
- If the method cannot be found.public java.util.List<java.lang.reflect.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 java.lang.reflect.Method getMethodByName(java.lang.String nameRegex)
nameRegex
- - regular expression that will match method names.java.lang.IllegalArgumentException
- If the method cannot be found.public java.lang.reflect.Method getMethodByParameters(java.lang.String name, java.lang.Class<?>... args)
name
- - potential name of the method. Only used by the error mechanism.args
- - parameter types of the method to find.java.lang.IllegalArgumentException
- If the method cannot be found.public java.lang.reflect.Method getMethodByParameters(java.lang.String name, java.lang.Class<?> returnType, java.lang.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.java.lang.IllegalArgumentException
- If the method cannot be found.public java.lang.reflect.Method getMethodByParameters(java.lang.String name, java.lang.String returnTypeRegex, java.lang.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.java.lang.IllegalArgumentException
- If the method cannot be found.public java.util.List<java.lang.reflect.Method> getMethodListByParameters(java.lang.Class<?> returnType, java.lang.Class<?>[] args)
returnType
- - return type of the method to find.args
- - parameter types of the method to find.public java.lang.reflect.Field getFieldByName(java.lang.String nameRegex)
nameRegex
- - regular expression that will match a field name.java.lang.IllegalArgumentException
- If the field cannot be found.public java.lang.reflect.Field getFieldByType(java.lang.String name, java.lang.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 java.util.List<java.lang.reflect.Field> getFieldListByType(java.lang.Class<?> type)
type
- - type of the fields to find.public java.lang.reflect.Field getField(AbstractFuzzyMatcher<java.lang.reflect.Field> matcher)
ForceAccess must be TRUE in order for this method to access private, protected and package level fields.
matcher
- - the matcher to use.java.lang.IllegalArgumentException
- If the method cannot be found.public java.util.List<java.lang.reflect.Field> getFieldList(AbstractFuzzyMatcher<java.lang.reflect.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 java.lang.reflect.Field getFieldByType(java.lang.String typeRegex)
Note that the type is matched using the full canonical representation, i.e.:
typeRegex
- - regular expression that will match the field type.java.lang.IllegalArgumentException
- If the field cannot be found.public java.lang.reflect.Field getFieldByType(java.lang.String typeRegex, java.util.Set<java.lang.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.java.lang.IllegalArgumentException
- If the field cannot be found.public java.lang.reflect.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.java.lang.IllegalArgumentException
- If the constructor cannot be found.public java.util.Map<java.lang.String,java.lang.reflect.Method> getMappedMethods(java.util.List<java.lang.reflect.Method> methods)
Note that overloaded methods will only occur once in the resulting map.
methods
- - every method.public java.util.List<java.lang.reflect.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 java.util.Set<java.lang.reflect.Field> getFields()
Private, protected and package fields are ignored if forceAccess is FALSE.
public java.util.Set<java.lang.reflect.Method> getMethods()
Private, protected and package methods are ignored if forceAccess is FALSE.
public java.util.Set<java.lang.reflect.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.