Class Accessors
java.lang.Object
com.comphenix.protocol.reflect.accessors.Accessors
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a field accessor that synchronizes access to the underlying field. -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldAccessorgetCached(FieldAccessor inner)Retrieve a field accessor that will cache the content of the field.static MethodAccessorgetConstantAccessor(Object returnValue, Method method)Retrieve a method accessor that always return a constant value, regardless if input.static 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 FieldAccessorgetFieldAcccessorOrNull(Class<?> clazz, String fieldName, Class<?> fieldType)Retrieve a field accessor for a field with the given name and equivalent type, or NULL.static FieldAccessorgetFieldAccessor(Class<?> instanceClass, Class<?> fieldClass, boolean forceAccess)Retrieve an accessor for the first field of the given type.static FieldAccessorgetFieldAccessor(Class<?> instanceClass, String fieldName, 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 FieldAccessorgetFieldAccessor(Field field, boolean forceAccess)Retrieve a field accessor from a given field that uses unchecked exceptions.static FieldAccessor[]getFieldAccessorArray(Class<?> instanceClass, Class<?> fieldClass, boolean forceAccess)Retrieve an accessor (in declared order) for every field of the givne type.static MethodAccessorgetMethodAcccessorOrNull(Class<?> clazz, String methodName)Retrieve a method accessor for a field with the given name and equivalent type, or NULL.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 MethodAccessorgetMethodAccessor(Method method, boolean forceAccess)Retrieve a method accessor for a particular method, avoding checked exceptions.static FieldAccessorgetSynchronized(FieldAccessor accessor)Retrieve a field accessor where the write operation is synchronized on the current field value.
-
Method Details
-
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 or not to look for private and protected fields.- Returns:
- The field accessor.
- Throws:
IllegalArgumentException- If the field cannot be found.
-
getFieldAccessorArray
public static FieldAccessor[] getFieldAccessorArray(Class<?> instanceClass, Class<?> fieldClass, boolean forceAccess)Retrieve an accessor (in declared order) for every field of the givne type.- Parameters:
instanceClass- - the type of the instance to retrieve.fieldClass- - type of the field(s) to retrieve.forceAccess- - whether or not to look for private and protected fields.- Returns:
- The accessors.
-
getFieldAccessor
public static FieldAccessor getFieldAccessor(Class<?> instanceClass, String fieldName, boolean forceAccess)Retrieve an accessor for the first field of the given type.- Parameters:
instanceClass- - the type of the instance to retrieve.fieldName- - name of the field to retrieve.forceAccess- - whether or not to look for private and protected fields.- Returns:
- The value of that field.
- Throws:
IllegalArgumentException- If the field cannot be found.
-
getFieldAccessor
Retrieve a field accessor from a given field that uses unchecked exceptions.- Parameters:
field- - the field.- Returns:
- The field accessor.
-
getFieldAccessor
Retrieve a field accessor from a given field that uses unchecked exceptions.- Parameters:
field- - the field.forceAccess- - whether or not to skip Java access checking.- Returns:
- The field accessor.
-
getFieldAcccessorOrNull
public static FieldAccessor getFieldAcccessorOrNull(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.
-
getMethodAcccessorOrNull
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.
-
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.
-
getCached
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.
-
getSynchronized
Retrieve a field accessor where the write operation is synchronized on the current field value.- Parameters:
accessor- - the accessor.- Returns:
- The field accessor.
-
getConstantAccessor
Retrieve a method accessor that always return a constant value, regardless if input.- Parameters:
returnValue- - the constant return value.method- - the method.- Returns:
- A constant method 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.
-
getMethodAccessor
Retrieve a method accessor for a particular method, avoding checked exceptions.- Parameters:
method- - the method to access.- Returns:
- The method accessor.
-
getMethodAccessor
Retrieve a method accessor for a particular method, avoding checked exceptions.- Parameters:
method- - the method to access.forceAccess- - whether or not to skip Java access checking.- 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.IllegalStateException- If we cannot access reflection.
-
getConstructorAccessor
Retrieve a constructor accessor for a particular constructor, avoding checked exceptions.- Parameters:
constructor- - the constructor to access.- Returns:
- The method accessor.
-