Class RMethod

    • Method Detail

      • reflectOn

        public static RMethod reflectOn​(Object object,
                                        @NonNull
                                        @NonNull Method method)
        Wraps a method in the RMethod class with the given owning bean
        Parameters:
        object - The object to use when invoking the method.
        method - The method to call
        Returns:
        The RMethod
      • getElement

        public Method getElement()
        Gets the AnnotatedElement
        Returns:
        the AnnotatedElement object
      • getType

        public Type getType()
        Gets the type of the element
        Returns:
        the type of the element
      • invoke

        public <T> T invoke​(Object... args)
                     throws ReflectionException
        Invokes this method with the given arguments.
        Parameters:
        args - The arguments to the method
        Returns:
        The return value of the method call
        Throws:
        ReflectionException - Something went wrong invoking the method
      • invokeReflective

        public Reflect invokeReflective​(Object... args)
                                 throws ReflectionException
        Invokes this method with the given arguments.
        Parameters:
        args - The arguments to the method
        Returns:
        A Reflect object representing the results
        Throws:
        ReflectionException - Something went wrong invoking the method
      • toString

        public String toString()
      • allowPrivilegedAccess

        public final V allowPrivilegedAccess()
        Allow privileged access to the object
        Returns:
        this Object
      • getOwner

        public final Reflect getOwner()
        Gets the Reflect object from which this executable was created.
        Returns:
        the Reflect object from which this executable was created.
      • isPrivileged

        public final boolean isPrivileged()
        is privileged access allowed on this object?
        Returns:
        True - privileged access is allowed, False - no privileged access is allowed
      • process

        public final <O> O process​(@NonNull
                                   @NonNull CheckedFunction<T,​O> function)
                            throws ReflectionException
        Applies the given CheckedFunction to the object. This method takes care of accessibility concerns.
        Type Parameters:
        O - the return type parameter
        Parameters:
        function - the function to apply
        Returns:
        the return value of the function
        Throws:
        ReflectionException - Something went wrong during reflection
      • setIsPrivileged

        public final V setIsPrivileged​(boolean allowPrivilegedAccess)
        Sets whether or not privileged access is allowed on this object
        Parameters:
        allowPrivilegedAccess - True - privileged access is allowed, False - no privileged access is allowed
        Returns:
        this object
      • getAnnotation

        public final <A extends Annotation> A getAnnotation​(Class<A> annotationClass)
        Gets the annotation of the given class present on this object.
        Type Parameters:
        A - the annotation type parameter
        Parameters:
        annotationClass - the annotation class
        Returns:
        the annotation (null if does not exist)
      • getAnnotation

        public final <A extends Annotation> A getAnnotation​(@NonNull
                                                            @NonNull Class<A> annotationClass,
                                                            boolean onlyDirect)
        Gets the annotation of the given class on this object. When onlyDirect is true it will only return annotations directly present via getDeclaredAnnotation otherwise will return any instance present via getAnnotation.
        Type Parameters:
        A - the annotation type parameter
        Parameters:
        annotationClass - the annotation class
        onlyDirect - True - only declared annotations, False present annotations
        Returns:
        the annotation (null if does not exist)
      • getAnnotations

        public final Annotation[] getAnnotations​(boolean onlyDirect)
        Gets all annotations on this object. When onlyDirect is true it will only return annotations directly present via getDeclaredAnnotations otherwise will return any instance present via getAnnotations.
        Parameters:
        onlyDirect - True - only declared annotations, False present annotations
        Returns:
        the array of Annotation
      • getAnnotations

        public final Annotation[] getAnnotations()
        Gets all annotations present on this object.
        Returns:
        the array of Annotation
      • getAnnotations

        public final <A extends Annotation> A[] getAnnotations​(@NonNull
                                                               @NonNull Class<A> annotationClass,
                                                               boolean onlyDirect)
        Gets all annotations on this object. When onlyDirect is true it will only return annotations directly present via getDeclaredAnnotationsByType otherwise will return any instance present via getAnnotationsByType.
        Type Parameters:
        A - the annotation type parameter
        Parameters:
        annotationClass - the annotation class
        onlyDirect - True - only declared annotations, False present annotations
        Returns:
        the array of Annotation
      • getAnnotations

        public final <A extends Annotation> A[] getAnnotations​(@NonNull
                                                               @NonNull Class<A> annotationClass)
        Gets all associated annotations of given type on this object.
        Type Parameters:
        A - the annotation type parameter
        Parameters:
        annotationClass - the annotation class
        Returns:
        the array of Annotation
      • isAnnotationDeclared

        @SafeVarargs
        public final boolean isAnnotationDeclared​(@NonNull
                                                  @NonNull Class<? extends Annotation>... annotationClasses)
        Determines if any of the given annotations are declared on this object
        Parameters:
        annotationClasses - the annotation classes
        Returns:
        True - if any of the given annotations are declared on this object
      • isAnnotationPresent

        @SafeVarargs
        public final boolean isAnnotationPresent​(@NonNull
                                                 @NonNull Class<? extends Annotation>... annotationClasses)
        Determines if any of the given annotations are present on this object
        Parameters:
        annotationClasses - the annotation classes
        Returns:
        True - if any of the given annotations are present on this object
      • processAnnotation

        public final <A extends Annotation,​O> O processAnnotation​(@NonNull
                                                                        @NonNull Class<A> annotationClass,
                                                                        @NonNull
                                                                        @NonNull CheckedFunction<? super A,​? extends O> function)
                                                                 throws ReflectionException
        Applies the given CheckedBiFunction to this object with the given annotation if it is present on the object.
        Type Parameters:
        A - the annotation type parameter
        O - the return type parameter
        Parameters:
        annotationClass - the annotation class
        function - the function to apply
        Returns:
        the return value of the function or null if no annotation was present
        Throws:
        ReflectionException - Something went wrong during reflection
      • processAnnotations

        public final <A extends Annotation,​O> List<O> processAnnotations​(@NonNull
                                                                               @NonNull Class<A> annotationClass,
                                                                               @NonNull
                                                                               @NonNull CheckedFunction<? super A,​? extends O> function)
                                                                        throws ReflectionException
        Applies the given CheckedBiFunction to this object and all instances of the given annotation present on the object.
        Type Parameters:
        A - the annotation type parameter
        O - the return type parameter
        Parameters:
        annotationClass - the annotation class
        function - the function to apply
        Returns:
        A list of the return values of the function or null if no annotation was present
        Throws:
        ReflectionException - Something went wrong during reflection
      • withAnnotation

        public final <A extends Annotation> V withAnnotation​(@NonNull
                                                             @NonNull Class<A> annotationClass,
                                                             @NonNull
                                                             @NonNull CheckedConsumer<? super A> consumer)
                                                      throws ReflectionException
        Applies the given CheckedBiConsumer to this object with the given annotation if it is present on the object.
        Type Parameters:
        A - the annotation type parameter
        Parameters:
        annotationClass - the annotation class
        consumer - the consumer to apply
        Returns:
        This object
        Throws:
        ReflectionException - Something went wrong during reflection
      • withAnnotations

        public final <A extends Annotation> V withAnnotations​(@NonNull
                                                              @NonNull Class<A> annotationClass,
                                                              @NonNull
                                                              @NonNull CheckedConsumer<? super A> consumer)
                                                       throws ReflectionException
        Applies the given CheckedBiConsumer to this object and all instances of the given annotation present on this object.
        Type Parameters:
        A - the annotation type parameter
        Parameters:
        annotationClass - the annotation class
        consumer - the consumer to apply
        Returns:
        This object
        Throws:
        ReflectionException - Something went wrong during reflection