Class Accessors
java.lang.Object
com.comphenix.protocol.reflect.accessors.Accessors
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConstructorAccessorgetConstructorAccessor(Class<?> instanceClass, Class<?>... parameters) Retrieve a constructor accessor for a constructor with the given signature.static ConstructorAccessorgetConstructorAccessor(Constructor<?> constructor) Retrieve a constructor accessor for a particular constructor, avoding checked exceptions.static ConstructorAccessorgetConstructorAccessorOrNull(Class<?> clazz, Class<?>... parameters) Find a specific constructor in a class.static FieldAccessorgetFieldAccessor(Class<?> instanceClass, Class<?> fieldClass, boolean forceAccess) Retrieve an accessor for the first field of the given type.static FieldAccessorgetFieldAccessor(Field field) Retrieve a field accessor from a given field that uses unchecked exceptions.static FieldAccessor[]getFieldAccessorArray(Class<?> clazz, Class<?> fieldClass, boolean forceAccess) Retrieve an accessor (in declared order) for every field of the givne type.static FieldAccessorgetFieldAccessorOrNull(Class<?> clazz, String fieldName, Class<?> fieldType) Retrieve a field accessor for a field with the given name and equivalent type, or NULL.static FieldAccessorgetMemorizing(FieldAccessor inner) Retrieve a field accessor that will cache the content of the field.static MethodAccessorgetMethodAccessor(Class<?> instanceClass, String methodName, Class<?>... parameters) Retrieve a method accessor for a method with the given name and signature.static MethodAccessorgetMethodAccessor(Method method) Retrieve a method accessor for a particular method, avoding checked exceptions.static MethodAccessorgetMethodAccessorOrNull(Class<?> clazz, String methodName, Class<?>... parameters) Retrieve a method accessor for a field with the given name and equivalent type, or NULL.
-
Method Details
-
getFieldAccessorArray
public static FieldAccessor[] getFieldAccessorArray(Class<?> clazz, Class<?> fieldClass, boolean forceAccess) Retrieve an accessor (in declared order) for every field of the givne type.- Parameters:
clazz- - the type of the instance to retrieve.fieldClass- - type of the field(s) to retrieve.forceAccess- - whether to look for private and protected fields.- Returns:
- The accessors.
-
getFieldAccessor
public static FieldAccessor getFieldAccessor(Class<?> instanceClass, Class<?> fieldClass, boolean forceAccess) Retrieve an accessor for the first field of the given type.- Parameters:
instanceClass- - the type of the instance to retrieve.fieldClass- - type of the field to retrieve.forceAccess- - whether to look for private and protected fields.- Returns:
- The field accessor.
- Throws:
IllegalArgumentException- If the field cannot be found.
-
getFieldAccessorOrNull
public static FieldAccessor getFieldAccessorOrNull(Class<?> clazz, String fieldName, Class<?> fieldType) Retrieve a field accessor for a field with the given name and equivalent type, or NULL.- Parameters:
clazz- - the declaration class.fieldName- - the field name.fieldType- - assignable field type.- Returns:
- The field accessor, or NULL if not found.
-
getFieldAccessor
Retrieve a field accessor from a given field that uses unchecked exceptions.- Parameters:
field- - the field.- Returns:
- The field accessor.
-
getMemorizing
Retrieve a field accessor that will cache the content of the field.Note that we don't check if the underlying field has changed after the value has been cached, so it's best to use this on final fields.
- Parameters:
inner- - the accessor.- Returns:
- A cached field accessor.
-
getMethodAccessor
public static MethodAccessor getMethodAccessor(Class<?> instanceClass, String methodName, Class<?>... parameters) Retrieve a method accessor for a method with the given name and signature.- Parameters:
instanceClass- - the parent class.methodName- - the method name.parameters- - the parameters.- Returns:
- The method accessor.
-
getMethodAccessorOrNull
public static MethodAccessor getMethodAccessorOrNull(Class<?> clazz, String methodName, Class<?>... parameters) Retrieve a method accessor for a field with the given name and equivalent type, or NULL.- Parameters:
clazz- - the declaration class.methodName- - the method name.- Returns:
- The method accessor, or NULL if not found.
-
getMethodAccessor
Retrieve a method accessor for a particular method, avoding checked exceptions.- Parameters:
method- - the method to access.- Returns:
- The method accessor.
-
getConstructorAccessor
public static ConstructorAccessor getConstructorAccessor(Class<?> instanceClass, Class<?>... parameters) Retrieve a constructor accessor for a constructor with the given signature.- Parameters:
instanceClass- - the parent class.parameters- - the parameters.- Returns:
- The constructor accessor.
- Throws:
IllegalArgumentException- If we cannot find this constructor.
-
getConstructorAccessorOrNull
public static ConstructorAccessor getConstructorAccessorOrNull(Class<?> clazz, Class<?>... parameters) Find a specific constructor in a class.- Parameters:
clazz- - the class.parameters- - the signature of the constructor to find.- Returns:
- The constructor, or NULL if not found.
-
getConstructorAccessor
Retrieve a constructor accessor for a particular constructor, avoding checked exceptions.- Parameters:
constructor- - the constructor to access.- Returns:
- The method accessor.
-