Class Accessors

java.lang.Object
com.comphenix.protocol.reflect.accessors.Accessors

public final class Accessors extends Object
  • 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

      public static FieldAccessor getFieldAccessor(Field field)
      Retrieve a field accessor from a given field that uses unchecked exceptions.
      Parameters:
      field - - the field.
      Returns:
      The field accessor.
    • getFieldAccessor

      public static FieldAccessor getFieldAccessor(Field field, boolean forceAccess)
      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

      public static MethodAccessor getMethodAcccessorOrNull(Class<?> clazz, String methodName)
      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

      public static FieldAccessor getCached(FieldAccessor inner)
      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

      public static FieldAccessor getSynchronized(FieldAccessor accessor)
      Retrieve a field accessor where the write operation is synchronized on the current field value.
      Parameters:
      accessor - - the accessor.
      Returns:
      The field accessor.
    • getConstantAccessor

      public static MethodAccessor getConstantAccessor(Object returnValue, Method method)
      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

      public static MethodAccessor getMethodAccessor(Method method)
      Retrieve a method accessor for a particular method, avoding checked exceptions.
      Parameters:
      method - - the method to access.
      Returns:
      The method accessor.
    • getMethodAccessor

      public static MethodAccessor getMethodAccessor(Method method, boolean forceAccess)
      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

      public static ConstructorAccessor getConstructorAccessor(Constructor<?> constructor)
      Retrieve a constructor accessor for a particular constructor, avoding checked exceptions.
      Parameters:
      constructor - - the constructor to access.
      Returns:
      The method accessor.