Interface IReflection

    • Method Detail

      • setAccessible

        boolean setAccessible​(Class<?> clazz,
                              Field field)
        Set the field as accessible.
        Parameters:
        clazz - the clazz the field is on
        field - the field to access
        Returns:
        could we complete the operation
        See Also:
        Field.setAccessible(boolean)
      • setAccessible

        boolean setAccessible​(Class<?> clazz,
                              Method method)
        Set the method as accessible.
        Parameters:
        clazz - the clazz the field is on
        method - the method to access
        Returns:
        could we complete the operation
        See Also:
        Method.setAccessible(boolean)
      • setAccessible

        boolean setAccessible​(Class<?> clazz,
                              Constructor<?> constructor)
        Set the constructor as accessible.
        Parameters:
        clazz - the clazz the field is on
        constructor - the constructor to set
        Returns:
        could we complete the operation
        See Also:
        Constructor.setAccessible(boolean)
      • callMethod

        <T> T callMethod​(Object target,
                         String methodName,
                         Object... args)
        Call a method on the target object.

        This will look for the method using findMethod(Class, String, Class[]) using the input arguments as the argument types of the method. The method will then be invoked on the target argument.

        Type Parameters:
        T - the type of the response
        Parameters:
        target - the target instance to call the method on
        methodName - the name of the method to call
        args - the arguments to the method
        Returns:
        the response of the method
      • findMethod

        Method findMethod​(Class<?> clazz,
                          String methodName,
                          Class<?>... argTypes)
        Scan the hierarchy of the input class for a method with the given name. This will scan declared methods and methods, as well as stepping up the super class.
        Parameters:
        clazz - the class to start the scan on
        methodName - the name of the method to look for
        argTypes - the argument types in the method signature
        Returns:
        the discovered method or null
      • getField

        Field getField​(Object target,
                       String fieldName)
        Get a filed from the target.
        Parameters:
        target - the target instance to look on.
        fieldName - the name of the field to get
        Returns:
        the field, or null
      • getFieldValue

        <T> T getFieldValue​(Object target,
                            String fieldName)
        Get a field from an object.
        Type Parameters:
        T - the type to return as
        Parameters:
        target - the object to look at
        fieldName - the field name to look for
        Returns:
        the field as T, else null
      • getFieldIterator

        Iterator<Field> getFieldIterator​(Class<?> clazz)
        Get an iterator that will iterator over all the available fields on the given class.
        Parameters:
        clazz - the class to scan
        Returns:
        the iterator for the fields
      • callField

        <T> T callField​(Object target,
                        Field field)
        Call a field on a target.
        Type Parameters:
        T - the type of the return
        Parameters:
        target - the object to get the field from
        field - the field to call
        Returns:
        the value of the field
      • getModifiers

        Set<String> getModifiers​(Field field)
        Get the modifier names of a field.
        Parameters:
        field - the field to look at
        Returns:
        a set of strings that represent the modifiers.
      • findConstructor

        Constructor<?> findConstructor​(Class<?> clazz,
                                       Class<?>... args)
        Find a constructor on the given class.
        Parameters:
        clazz - the class to look on
        args - the arguments for the constructor
        Returns:
        the constructor or null
      • callConstructor

        <T> T callConstructor​(Constructor<?> constructor,
                              Object... args)
                       throws DeepRuntimeException
        Call a constructor with the arguments.
        Type Parameters:
        T - the type of the return
        Parameters:
        constructor - the constructor to call
        args - the arguments for the constructor
        Returns:
        the new object, or null
        Throws:
        DeepRuntimeException - if we could not create a new object