Class FuzzyReflection
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Set<T> combineArrays(T[]... arrays) static FuzzyReflectionRetrieves a fuzzy reflection instance from a given class.static FuzzyReflectionRetrieves a fuzzy reflection instance from a given class.static FuzzyReflectionfromObject(Object reference) Retrieves a fuzzy reflection instance from an object.static FuzzyReflectionfromObject(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<?>> Retrieves all private and public constructors in declared order (after JDK 1.5).getDeclaredFields(Class<?> excludeClass) Retrieves all private and public fields, up until a certain superclass.getField(AbstractFuzzyMatcher<Field> matcher) Retrieve the first field that matches.getFieldByName(String nameRegex) Retrieves a field by name.getFieldByType(String typeRegex) Retrieves a field by type.getFieldByType(String name, Class<?> type) Retrieves the first field with a type equal to or more specific to the given type.getFieldList(AbstractFuzzyMatcher<Field> matcher) Retrieve a list of every field that matches the given matcher.getFieldListByType(Class<?> type) Retrieves every field with a type equal to or more specific to the given type.Retrieves all private and public fields in declared order.static <T> TgetFieldValue(Object instance, Class<T> fieldClass, boolean forceAccess) Retrieve the value of the first field of the given type.getMethod(AbstractFuzzyMatcher<MethodInfo> matcher) Retrieve the first method that matches.getMethod(AbstractFuzzyMatcher<MethodInfo> matcher, String preferred) Retrieve a method that matches.getMethodByName(String nameRegex) Retrieves a method by looking at its name.getMethodByParameters(String name, Class<?>... args) Retrieves a method by looking at the parameter types only.getMethodByReturnTypeAndParameters(String name, Class<?> returnType, Class<?>... args) Retrieves a method by looking at the parameter types and return type only.getMethodList(AbstractFuzzyMatcher<MethodInfo> matcher) Retrieve a list of every method that matches the given matcher.getMethodListByParameters(Class<?> returnType, Class<?>... args) Retrieves every method that has the given parameter types and return type.Retrieves all private and public methods in declared order (after JDK 1.5).getParameterizedField(Class<?> fieldType, Class<?>... params) Retrieves a field with a given type and parameters.Retrieve the singleton instance of a class, from a method or field.Class<?> Retrieves the underlying class.booleanRetrieves whether or not not to override any scope restrictions.
-
Constructor Details
-
FuzzyReflection
-
-
Method Details
-
fromClass
Retrieves a fuzzy reflection instance from a given class.- Parameters:
source- - the class we'll use.- Returns:
- A fuzzy reflection instance.
-
fromClass
Retrieves a fuzzy reflection instance from a given class.- Parameters:
source- - the class we'll use.forceAccess- - whether to override scope restrictions.- Returns:
- A fuzzy reflection instance.
-
fromObject
Retrieves a fuzzy reflection instance from an object.- Parameters:
reference- - the object we'll use.- Returns:
- A fuzzy reflection instance that uses the class of the given object.
-
fromObject
Retrieves a fuzzy reflection instance from an object.- Parameters:
reference- - the object we'll use.forceAccess- - whether to override scope restrictions.- Returns:
- A fuzzy reflection instance that uses the class of the given object.
-
getFieldValue
Retrieve the value of the first field of the given type.- Type Parameters:
T- Type- Parameters:
instance- - the instance to retrieve from.fieldClass- - type of the field to retrieve.forceAccess- - whether to look for private and protected fields.- Returns:
- The value of that field.
- Throws:
IllegalArgumentException- If the field cannot be found.
-
combineArrays
-
getSource
Retrieves the underlying class.- Returns:
- The underlying class.
-
isForceAccess
public boolean isForceAccess()Retrieves whether or not not to override any scope restrictions.- Returns:
- TRUE if we override scope, FALSE otherwise.
-
getSingleton
Retrieve the singleton instance of a class, from a method or field.- Returns:
- The singleton instance.
- Throws:
IllegalStateException- If the class has no singleton.
-
getMethod
Retrieve the first method that matches.ForceAccess must be TRUE in order for this method to access private, protected and package level method.
- Parameters:
matcher- - the matcher to use.- Returns:
- The first method that satisfies the given matcher.
- Throws:
IllegalArgumentException- If the method cannot be found.
-
getMethod
Retrieve a method that matches. If there are multiple methods that match, the first one with the preferred name is selected.ForceAccess must be TRUE in order for this method to access private, protected and package level method.
- Parameters:
matcher- - the matcher to use.preferred- - the preferred name, null for no preference.- Returns:
- The first method that satisfies the given matcher.
- Throws:
IllegalArgumentException- If the method cannot be found.
-
getMethodByName
Retrieves a method by looking at its name.- Parameters:
nameRegex- - regular expression that will match method names.- Returns:
- The first method that satisfies the regular expression.
- Throws:
IllegalArgumentException- If the method cannot be found.
-
getMethodByParameters
Retrieves a method by looking at the parameter types only.- Parameters:
name- - potential name of the method. Only used by the error mechanism.args- - parameter types of the method to find.- Returns:
- The first method that satisfies the parameter types.
- Throws:
IllegalArgumentException- If the method cannot be found.
-
getMethodByReturnTypeAndParameters
public Method getMethodByReturnTypeAndParameters(String name, Class<?> returnType, Class<?>... args) Retrieves a method by looking at the parameter types and return type only.- Parameters:
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.- Returns:
- The first method that satisfies the parameter types.
- Throws:
IllegalArgumentException- If the method cannot be found.
-
getMethodList
Retrieve a list of every method that matches the given matcher.ForceAccess must be TRUE in order for this method to access private, protected and package level methods.
- Parameters:
matcher- - the matcher to apply.- Returns:
- List of found methods.
-
getMethodListByParameters
Retrieves every method that has the given parameter types and return type.- Parameters:
returnType- - return type of the method to find.args- - parameter types of the method to find.- Returns:
- Every method that satisfies the given constraints.
-
getField
Retrieve the first field that matches.ForceAccess must be TRUE in order for this method to access private, protected and package level fields.
- Parameters:
matcher- - the matcher to use.- Returns:
- The first method that satisfies the given matcher.
- Throws:
IllegalArgumentException- If the method cannot be found.
-
getFieldByName
Retrieves a field by name.- Parameters:
nameRegex- - regular expression that will match a field name.- Returns:
- The first field to match the given expression.
- Throws:
IllegalArgumentException- If the field cannot be found.
-
getFieldByType
Retrieves the first field with a type equal to or more specific to the given type.- Parameters:
name- - name the field probably is given. This will only be used in the error message.type- - type of the field to find.- Returns:
- The first field with a type that is an instance of the given type.
-
getFieldListByType
Retrieves every field with a type equal to or more specific to the given type.- Parameters:
type- - type of the fields to find.- Returns:
- Every field with a type that is an instance of the given type.
-
getParameterizedField
Retrieves a field with a given type and parameters. This is most useful when dealing with Collections.- Parameters:
fieldType- Type of the fieldparams- Variable length array of type parameters- Returns:
- The field
- Throws:
IllegalArgumentException- If the field cannot be found
-
getFieldList
Retrieve a list of every field that matches the given matcher.ForceAccess must be TRUE in order for this method to access private, protected and package level fields.
- Parameters:
matcher- - the matcher to apply.- Returns:
- List of found fields.
-
getFieldByType
Retrieves a field by type.Note that the type is matched using the full canonical representation, i.e.:
- java.util.List
- net.comphenix.xp.ExperienceMod
- Parameters:
typeRegex- - regular expression that will match the field type.- Returns:
- The first field with a type that matches the given regular expression.
- Throws:
IllegalArgumentException- If the field cannot be found.
-
getConstructor
Retrieve the first constructor that matches.ForceAccess must be TRUE in order for this method to access private, protected and package level constructors.
- Parameters:
matcher- - the matcher to use.- Returns:
- The first constructor that satisfies the given matcher.
- Throws:
IllegalArgumentException- If the constructor cannot be found.
-
getConstructorList
Retrieve a list of every constructor that matches the given matcher.ForceAccess must be TRUE in order for this method to access private, protected and package level constructors.
- Parameters:
matcher- - the matcher to apply.- Returns:
- List of found constructors.
-
getFields
Retrieves all private and public fields in declared order.Private, protected and package fields are ignored if forceAccess is FALSE.
- Returns:
- Every field.
-
getDeclaredFields
Retrieves all private and public fields, up until a certain superclass.- Parameters:
excludeClass- - the class (and its superclasses) to exclude from the search.- Returns:
- Every such declared field.
-
getMethods
Retrieves all private and public methods in declared order (after JDK 1.5).Private, protected and package methods are ignored if forceAccess is FALSE.
- Returns:
- Every method.
-
getConstructors
Retrieves all private and public constructors in declared order (after JDK 1.5).Private, protected and package constructors are ignored if forceAccess is FALSE.
- Returns:
- Every constructor.
-