Class ExactReflection

java.lang.Object
com.comphenix.protocol.reflect.ExactReflection

public class ExactReflection extends Object
  • Method Details

    • fromClass

      public static ExactReflection fromClass(Class<?> source, boolean forceAccess)
      Retrieves an exact reflection instance from a given class.
      Parameters:
      source - - the class we'll use.
      forceAccess - - whether to also search for members which are out of the allowed scope.
      Returns:
      A fuzzy reflection instance.
    • fromObject

      public static ExactReflection fromObject(Object reference, boolean forceAccess)
      Retrieves an exact reflection instance from an object.
      Parameters:
      reference - - the object we'll use.
      forceAccess - - whether to also search for members which are out of the allowed scope.
      Returns:
      A fuzzy reflection instance that uses the class of the given object.
    • getMethod

      public Method getMethod(String methodName, Class<?>... parameters)
      Retrieve the first method in the class hierarchy with the given name and parameters.

      If isForceAccess() is TRUE, we will also search for methods which are out of the caller scope.

      Parameters:
      methodName - - the name of the method to find, NULL to only search by using the given parameters.
      parameters - - the parameters of the method to find.
      Returns:
      the first matching method.
      Throws:
      IllegalArgumentException - if there is no method with the given name and parameter types.
    • findMethod

      public Method findMethod(String methodName, Class<?>... parameters)
      Finds the first method in the class hierarchy with the given name and parameters.

      If isForceAccess() is TRUE, we will also search for methods which are out of the caller scope.

      Parameters:
      methodName - - the name of the method to find, NULL to only search by using the given parameters.
      parameters - - the parameters of the method to find.
      Returns:
      the first matching method, NULL if no method matches.
    • getField

      public Field getField(String fieldName)
      Retrieve a field in the class hierarchy by the given name.

      If isForceAccess() is TRUE, we will also search for fields which are out of the caller scope.

      Parameters:
      fieldName - - the name of the field to find.
      Returns:
      the first matching field.
      Throws:
      IllegalArgumentException - if no field with the given name was found.
    • findField

      public Field findField(String fieldName)
      Finds a field in the class hierarchy by the given name.

      If isForceAccess() is TRUE, we will also search for fields which are out of the caller scope.

      Parameters:
      fieldName - - the name of the field to find.
      Returns:
      the first matching field, null if no field matches.
    • getConstructor

      public Constructor<?> getConstructor(Class<?>... parameters)
      Retrieves the first constructor in the class hierarchy with the given parameters.

      If isForceAccess() is TRUE, we will also search for constructors which are out of the caller scope.

      Parameters:
      parameters - - the parameters of the constructor to find.
      Returns:
      the first matching constructor.
      Throws:
      IllegalArgumentException - if no constructor with the given parameters was found.
    • findConstructor

      public Constructor<?> findConstructor(Class<?>... parameters)
      Finds the first constructor in the class hierarchy with the given parameters.

      If isForceAccess() is TRUE, we will also search for constructors which are out of the caller scope.

      Parameters:
      parameters - - the parameters of the constructor to find.
      Returns:
      the first matching constructor, NULL if no constructor matches.
    • forceAccess

      public ExactReflection forceAccess()
      Retrieve an ExactReflection object where scope restrictions are ignored.
      Returns:
      A copy of the current object.
    • isForceAccess

      public boolean isForceAccess()
      Determine if we are overriding scope restrictions and will also find private, protected or package members.
      Returns:
      TRUE if we are, FALSE otherwise.
    • getSource

      public Class<?> getSource()
      Retrieve the source class we are searching.
      Returns:
      The source.