Class JqwikReflectionSupport


  • public class JqwikReflectionSupport
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.lang.reflect.Constructor<T> findConstructor​(java.lang.Class<T> type, java.lang.Class<?>... parameterTypes)  
      static java.util.Optional<java.lang.reflect.Method> findGeneratorMethod​(java.lang.String generatorToFind, java.lang.Class<?> containerClass, java.lang.Class<? extends java.lang.annotation.Annotation> requiredGeneratorAnnotation, java.util.function.Function<java.lang.reflect.Method,​java.lang.String> generatorNameSupplier, net.jqwik.api.providers.TypeUsage targetType)  
      static java.util.List<java.lang.reflect.Method> findMethodsPotentiallyOuter​(java.lang.Class<?> clazz, java.util.function.Predicate<java.lang.reflect.Method> predicate, org.junit.platform.commons.support.HierarchyTraversalMode traversalMode)
      Find all methods as in ReflectionSupport.findMethods(..) but also use outer classes to look for methods.
      static java.util.Set<java.nio.file.Path> getAllClasspathRootDirectories()  
      static java.util.Optional<java.lang.reflect.Method> getFunctionMethod​(java.lang.Class<?> candidateType)  
      static MethodParameter getMethodParameter​(java.lang.reflect.Parameter parameter, int index, java.lang.Class<?> containerClass)  
      static java.util.List<MethodParameter> getMethodParameters​(java.lang.reflect.Method method, java.lang.Class<?> containerClass)  
      static boolean hasDefaultConstructor​(java.lang.Class<?> aClass)  
      static java.lang.Object invokeMethodPotentiallyOuter​(java.lang.reflect.Method method, java.lang.Object target, java.lang.Object... args)
      Invoke the supplied method as in ReflectionSupport.invokeMethod(..) but potentially use the outer instance if the method belongs to the outer instance of an object.
      static boolean isEqualsMethod​(java.lang.reflect.Method method)  
      static boolean isFunctionalType​(java.lang.Class<?> candidateType)  
      static java.util.function.Predicate<java.lang.reflect.Method> isGeneratorMethod​(net.jqwik.api.providers.TypeUsage targetType, java.lang.Class<? extends java.lang.annotation.Annotation> requiredAnnotation)  
      static boolean isHashCodeMethod​(java.lang.reflect.Method method)  
      static boolean isInnerClass​(java.lang.Class<?> clazz)  
      static boolean isJava9orAbove()  
      static boolean isNotStatic​(java.lang.Class<?> clazz)  
      static boolean isNotStatic​(java.lang.reflect.Member member)  
      static boolean isStatic​(java.lang.Class<?> clazz)  
      static boolean isStatic​(java.lang.reflect.Member member)  
      static boolean isToStringMethod​(java.lang.reflect.Method method)  
      static <T> T newInstance​(java.lang.reflect.Constructor<T> constructor, java.lang.Object... args)  
      static <T> T newInstanceInTestContext​(java.lang.Class<T> clazz, java.lang.Object context)
      Create instance of a class that can potentially be a non static inner class and its outer instance might be context
      static <T> T newInstanceWithDefaultConstructor​(java.lang.Class<T> clazz)
      Create instance of a class that can potentially be a non static inner class
      static boolean returnsVoid​(java.lang.reflect.Method method)  
      static java.util.stream.Stream<java.lang.Object> streamInstancesFromInside​(java.lang.Object inner)  
      • Methods inherited from class java.lang.Object

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

      • JqwikReflectionSupport

        public JqwikReflectionSupport()
    • Method Detail

      • streamInstancesFromInside

        public static java.util.stream.Stream<java.lang.Object> streamInstancesFromInside​(java.lang.Object inner)
      • newInstanceWithDefaultConstructor

        public static <T> T newInstanceWithDefaultConstructor​(java.lang.Class<T> clazz)
        Create instance of a class that can potentially be a non static inner class
        Type Parameters:
        T - The type of the instance to create
        Parameters:
        clazz - The class to instantiate
        Returns:
        the newly created instance
      • newInstanceInTestContext

        public static <T> T newInstanceInTestContext​(java.lang.Class<T> clazz,
                                                     java.lang.Object context)
        Create instance of a class that can potentially be a non static inner class and its outer instance might be context
        Type Parameters:
        T - The type of the instance to create
        Parameters:
        clazz - The class to instantiate
        context - The potential context instance
        Returns:
        the newly created instance
      • newInstance

        public static <T> T newInstance​(java.lang.reflect.Constructor<T> constructor,
                                        java.lang.Object... args)
      • findMethodsPotentiallyOuter

        public static java.util.List<java.lang.reflect.Method> findMethodsPotentiallyOuter​(java.lang.Class<?> clazz,
                                                                                           java.util.function.Predicate<java.lang.reflect.Method> predicate,
                                                                                           org.junit.platform.commons.support.HierarchyTraversalMode traversalMode)
        Find all methods as in ReflectionSupport.findMethods(..) but also use outer classes to look for methods.
        Parameters:
        clazz - The class in which you start the search
        predicate - The condition to check for all candidate methods
        traversalMode - Traverse hierarchy up or down. Determines the order in resulting list.
        Returns:
        List of found methods
      • invokeMethodPotentiallyOuter

        public static java.lang.Object invokeMethodPotentiallyOuter​(java.lang.reflect.Method method,
                                                                    java.lang.Object target,
                                                                    java.lang.Object... args)
        Invoke the supplied method as in ReflectionSupport.invokeMethod(..) but potentially use the outer instance if the method belongs to the outer instance of an object.
        Parameters:
        method - The method to invoke
        target - The object to invoke the method on
        args - The arguments of the method invocation
        Returns:
        Result of method invocation if there is one, otherwise null
      • getAllClasspathRootDirectories

        public static java.util.Set<java.nio.file.Path> getAllClasspathRootDirectories()
      • getMethodParameters

        public static java.util.List<MethodParameter> getMethodParameters​(java.lang.reflect.Method method,
                                                                          java.lang.Class<?> containerClass)
      • getMethodParameter

        public static MethodParameter getMethodParameter​(java.lang.reflect.Parameter parameter,
                                                         int index,
                                                         java.lang.Class<?> containerClass)
      • findGeneratorMethod

        public static java.util.Optional<java.lang.reflect.Method> findGeneratorMethod​(java.lang.String generatorToFind,
                                                                                       java.lang.Class<?> containerClass,
                                                                                       java.lang.Class<? extends java.lang.annotation.Annotation> requiredGeneratorAnnotation,
                                                                                       java.util.function.Function<java.lang.reflect.Method,​java.lang.String> generatorNameSupplier,
                                                                                       net.jqwik.api.providers.TypeUsage targetType)
      • findConstructor

        public static <T> java.lang.reflect.Constructor<T> findConstructor​(java.lang.Class<T> type,
                                                                           java.lang.Class<?>... parameterTypes)
      • isGeneratorMethod

        public static java.util.function.Predicate<java.lang.reflect.Method> isGeneratorMethod​(net.jqwik.api.providers.TypeUsage targetType,
                                                                                               java.lang.Class<? extends java.lang.annotation.Annotation> requiredAnnotation)
      • isInnerClass

        public static boolean isInnerClass​(java.lang.Class<?> clazz)
      • isFunctionalType

        public static boolean isFunctionalType​(java.lang.Class<?> candidateType)
      • getFunctionMethod

        public static java.util.Optional<java.lang.reflect.Method> getFunctionMethod​(java.lang.Class<?> candidateType)
      • isEqualsMethod

        public static boolean isEqualsMethod​(java.lang.reflect.Method method)
      • isToStringMethod

        public static boolean isToStringMethod​(java.lang.reflect.Method method)
      • isHashCodeMethod

        public static boolean isHashCodeMethod​(java.lang.reflect.Method method)
      • hasDefaultConstructor

        public static boolean hasDefaultConstructor​(java.lang.Class<?> aClass)
      • isJava9orAbove

        public static boolean isJava9orAbove()
      • isStatic

        public static boolean isStatic​(java.lang.Class<?> clazz)
      • isNotStatic

        public static boolean isNotStatic​(java.lang.Class<?> clazz)
      • isStatic

        public static boolean isStatic​(java.lang.reflect.Member member)
      • isNotStatic

        public static boolean isNotStatic​(java.lang.reflect.Member member)
      • returnsVoid

        public static boolean returnsVoid​(java.lang.reflect.Method method)