Class ReflectionUtils

    • Constructor Summary

      Constructors 
      Constructor Description
      ReflectionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.reflect.AnnotatedElement>
      UtilQueryBuilder<java.lang.reflect.AnnotatedElement,​T>
      extendType()  
      static <C,​T>
      java.util.Set<T>
      get​(QueryFunction<C,​T> function)
      get type elements <T> by applying QueryFunction
      static <T> java.util.Set<T> get​(QueryFunction<Store,​T> queryFunction, java.util.function.Predicate<? super T>... predicates)
      get type elements <T> by applying QueryFunction and predicates
      static <T extends java.lang.reflect.AnnotatedElement>
      java.util.Set<java.lang.annotation.Annotation>
      getAllAnnotations​(T type, java.util.function.Predicate<java.lang.annotation.Annotation>... predicates)
      get all annotations of given type, up the super class hierarchy, optionally filtered by predicates
      static java.util.Set<java.lang.reflect.Constructor> getAllConstructors​(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.reflect.Constructor>... predicates)
      get all constructors of given type, up the super class hierarchy, optionally filtered by predicates
      static java.util.Set<java.lang.reflect.Field> getAllFields​(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.reflect.Field>... predicates)
      get all fields of given type, up the super class hierarchy, optionally filtered by predicates
      static java.util.Set<java.lang.reflect.Method> getAllMethods​(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.reflect.Method>... predicates)
      get all methods of given type, up the super class hierarchy, optionally filtered by predicates
      static java.util.Set<java.lang.Class<?>> getAllSuperTypes​(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.Class<?>>... predicates)
      get all super types of given type, including, optionally filtered by predicates
      static <T extends java.lang.reflect.AnnotatedElement>
      java.util.Set<java.lang.annotation.Annotation>
      getAnnotations​(T type, java.util.function.Predicate<java.lang.annotation.Annotation>... predicates)
      get annotations of given type, optionally honorInherited, optionally filtered by predicates
      static java.util.Set<java.lang.reflect.Constructor> getConstructors​(java.lang.Class<?> t, java.util.function.Predicate<? super java.lang.reflect.Constructor>... predicates)
      get constructors of given type, optionally filtered by predicates
      static java.util.Set<java.lang.reflect.Field> getFields​(java.lang.Class<?> type, java.util.function.Predicate<? super java.lang.reflect.Field>... predicates)
      get fields of given type, optionally filtered by predicates
      static java.util.Set<java.lang.reflect.Method> getMethods​(java.lang.Class<?> t, java.util.function.Predicate<? super java.lang.reflect.Method>... predicates)
      get methods of given type, optionally filtered by predicates
      static java.util.Set<java.lang.Class<?>> getSuperTypes​(java.lang.Class<?> type)
      get the immediate supertype and interfaces of the given type
      static java.lang.Object invoke​(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object... args)
      invoke the given method with args, return either the result or an exception if occurred
      static java.lang.annotation.Annotation toAnnotation​(java.util.Map<java.lang.String,​java.lang.Object> map)
      create new annotation proxy with member values from the given map
      static <T extends java.lang.annotation.Annotation>
      T
      toAnnotation​(java.util.Map<java.lang.String,​java.lang.Object> map, java.lang.Class<T> annotationType)
      create new annotation proxy with member values from the given map and member values from the given map
      static java.util.Map<java.lang.String,​java.lang.Object> toMap​(java.lang.annotation.Annotation annotation)
      map annotation to hash map of member values recursively
      static java.util.Map<java.lang.String,​java.lang.Object> toMap​(java.lang.annotation.Annotation annotation, java.lang.reflect.AnnotatedElement element)
      map annotation and annotatedElement to hash map of member values
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • objectMethodNames

        private static final java.util.List<java.lang.String> objectMethodNames
      • notObjectMethod

        public static final java.util.function.Predicate<java.lang.reflect.Method> notObjectMethod
        predicate to filter out Object methods
      • SuperClass

        public static final UtilQueryBuilder<java.lang.Class<?>,​java.lang.Class<?>> SuperClass
        query super class
        get(SuperClass.of(element)) -> Set<Class<?>>

        see also SuperTypes, Interfaces

      • Interfaces

        public static final UtilQueryBuilder<java.lang.Class<?>,​java.lang.Class<?>> Interfaces
        query interfaces
        get(Interfaces.of(element)) -> Set<Class<?>>
      • SuperTypes

        public static final UtilQueryBuilder<java.lang.Class<?>,​java.lang.Class<?>> SuperTypes
        query super classes and interfaces including element
        get(SuperTypes.of(element)) -> Set<Class<?>> 
      • Annotations

        public static final UtilQueryBuilder<java.lang.reflect.AnnotatedElement,​java.lang.annotation.Annotation> Annotations
        query annotations
        get(Annotation.of(element)) -> Set<Annotation> 
      • AnnotationTypes

        public static final UtilQueryBuilder<java.lang.reflect.AnnotatedElement,​java.lang.Class<? extends java.lang.annotation.Annotation>> AnnotationTypes
        query annotation types
        get(AnnotationTypes.of(element)) -> Set<Class<? extends Annotation>> 
      • Methods

        public static final UtilQueryBuilder<java.lang.Class<?>,​java.lang.reflect.Method> Methods
        query methods
        get(Methods.of(type)) -> Set<Method>
      • Constructors

        public static final UtilQueryBuilder<java.lang.Class<?>,​java.lang.reflect.Constructor> Constructors
        query constructors
        get(Constructors.of(type)) -> Set<Constructor> 
      • Fields

        public static final UtilQueryBuilder<java.lang.Class<?>,​java.lang.reflect.Field> Fields
        query fields
        get(Fields.of(type)) -> Set<Field> 
      • Resources

        public static final UtilQueryBuilder<java.lang.String,​java.net.URL> Resources
        query url resources using ClassLoader.getResources(java.lang.String)
        get(Resources.with(name)) -> Set<URL> 
    • Constructor Detail

      • ReflectionUtils

        public ReflectionUtils()
    • Method Detail

      • get

        public static <C,​T> java.util.Set<T> get​(QueryFunction<C,​T> function)
        get type elements <T> by applying QueryFunction
        get(SuperTypes.of(type))
      • get

        public static <T> java.util.Set<T> get​(QueryFunction<Store,​T> queryFunction,
                                               java.util.function.Predicate<? super T>... predicates)
        get type elements <T> by applying QueryFunction and predicates
      • extendType

        public static <T extends java.lang.reflect.AnnotatedElement> UtilQueryBuilder<java.lang.reflect.AnnotatedElement,​T> extendType()
      • getAllAnnotations

        public static <T extends java.lang.reflect.AnnotatedElement> java.util.Set<java.lang.annotation.Annotation> getAllAnnotations​(T type,
                                                                                                                                      java.util.function.Predicate<java.lang.annotation.Annotation>... predicates)
        get all annotations of given type, up the super class hierarchy, optionally filtered by predicates

        marked for removal, use instead get(Annotations.of())

      • getAllSuperTypes

        public static java.util.Set<java.lang.Class<?>> getAllSuperTypes​(java.lang.Class<?> type,
                                                                         java.util.function.Predicate<? super java.lang.Class<?>>... predicates)
        get all super types of given type, including, optionally filtered by predicates
      • getSuperTypes

        public static java.util.Set<java.lang.Class<?>> getSuperTypes​(java.lang.Class<?> type)
        get the immediate supertype and interfaces of the given type

        marked for removal, use instead get(SuperTypes.get())

      • getAllMethods

        public static java.util.Set<java.lang.reflect.Method> getAllMethods​(java.lang.Class<?> type,
                                                                            java.util.function.Predicate<? super java.lang.reflect.Method>... predicates)
        get all methods of given type, up the super class hierarchy, optionally filtered by predicates

        marked for removal, use instead get(Methods.of())

      • getMethods

        public static java.util.Set<java.lang.reflect.Method> getMethods​(java.lang.Class<?> t,
                                                                         java.util.function.Predicate<? super java.lang.reflect.Method>... predicates)
        get methods of given type, optionally filtered by predicates

        marked for removal, use instead get(Methods.get())

      • getAllConstructors

        public static java.util.Set<java.lang.reflect.Constructor> getAllConstructors​(java.lang.Class<?> type,
                                                                                      java.util.function.Predicate<? super java.lang.reflect.Constructor>... predicates)
        get all constructors of given type, up the super class hierarchy, optionally filtered by predicates

        marked for removal, use instead get(Constructors.of())

      • getConstructors

        public static java.util.Set<java.lang.reflect.Constructor> getConstructors​(java.lang.Class<?> t,
                                                                                   java.util.function.Predicate<? super java.lang.reflect.Constructor>... predicates)
        get constructors of given type, optionally filtered by predicates

        marked for removal, use instead get(Constructors.get())

      • getAllFields

        public static java.util.Set<java.lang.reflect.Field> getAllFields​(java.lang.Class<?> type,
                                                                          java.util.function.Predicate<? super java.lang.reflect.Field>... predicates)
        get all fields of given type, up the super class hierarchy, optionally filtered by predicates

        marked for removal, use instead get(Fields.of())

      • getFields

        public static java.util.Set<java.lang.reflect.Field> getFields​(java.lang.Class<?> type,
                                                                       java.util.function.Predicate<? super java.lang.reflect.Field>... predicates)
        get fields of given type, optionally filtered by predicates

        marked for removal, use instead get(Fields.get())

      • getAnnotations

        public static <T extends java.lang.reflect.AnnotatedElement> java.util.Set<java.lang.annotation.Annotation> getAnnotations​(T type,
                                                                                                                                   java.util.function.Predicate<java.lang.annotation.Annotation>... predicates)
        get annotations of given type, optionally honorInherited, optionally filtered by predicates

        marked for removal, use instead get(Annotations.get())

      • toMap

        public static java.util.Map<java.lang.String,​java.lang.Object> toMap​(java.lang.annotation.Annotation annotation)
        map annotation to hash map of member values recursively
        Annotations.of(type).map(ReflectionUtils::toMap) 
      • toMap

        public static java.util.Map<java.lang.String,​java.lang.Object> toMap​(java.lang.annotation.Annotation annotation,
                                                                                   java.lang.reflect.AnnotatedElement element)
        map annotation and annotatedElement to hash map of member values
        Annotations.of(type).map(a -> toMap(type, a)) 
      • toAnnotation

        public static java.lang.annotation.Annotation toAnnotation​(java.util.Map<java.lang.String,​java.lang.Object> map)
        create new annotation proxy with member values from the given map
        toAnnotation(Map.of("annotationType", annotationType, "value", ""))
      • toAnnotation

        public static <T extends java.lang.annotation.Annotation> T toAnnotation​(java.util.Map<java.lang.String,​java.lang.Object> map,
                                                                                 java.lang.Class<T> annotationType)
        create new annotation proxy with member values from the given map and member values from the given map
        toAnnotation(Map.of("value", ""), annotationType)
      • invoke

        public static java.lang.Object invoke​(java.lang.reflect.Method method,
                                              java.lang.Object obj,
                                              java.lang.Object... args)
        invoke the given method with args, return either the result or an exception if occurred