java.lang.Object
nl.jqno.equalsverifier.internal.reflection.SubtypeManager

public final class SubtypeManager extends Object
Can find subtypes that can be instantiated. Useful for abstract classes, interfaces, and sealed types.
  • Field Details

    • FORBIDDEN_PACKAGES

      private static final List<String> FORBIDDEN_PACKAGES
    • FALLBACK_PACKAGE_NAME

      private static final String FALLBACK_PACKAGE_NAME
  • Constructor Details

    • SubtypeManager

      private SubtypeManager()
  • Method Details

    • findInstantiableSubclass

      public static <T> Class<T> findInstantiableSubclass(ClassProbe<T> probe, ValueProvider vp, Attributes attributes)
      Finds a subtype that can be instantiated.
      Type Parameters:
      T - Represent the class to find an instantiable subtype for.
      Parameters:
      probe - Represents the class to find an instantiable subtype for.
      vp - Used to test if the subtype of a sealed type can indeed be instantiated.
      attributes - Used by the vp.
      Returns:
      An instantiable subtype, or null if none can be found.
      Throws:
      NoValueException - if no subtype can be found. This only happens for sealed types, when all permitted subclasses are recursive.
    • giveDynamicSubclass

      public static <S> Class<S> giveDynamicSubclass(Class<S> superclass)
      Generates an anonymous subclass of S. The subclass is generated dynamically.
      Type Parameters:
      S - The class to create a dynamic subclass of.
      Parameters:
      superclass - The class to create a dynamic subclass of.
      Returns:
      An instance of an anonymous subclass of S.
    • giveDynamicSubclass

      public static <S> Class<S> giveDynamicSubclass(Class<S> superclass, String nameSuffix, UnaryOperator<net.bytebuddy.dynamic.DynamicType.Builder<S>> modify)
      Generates an anonymous subclass of S. The subclass is generated dynamically.
      Type Parameters:
      S - The class to create a dynamic subclass of.
      Parameters:
      superclass - The class to create a dynamic subclass of.
      nameSuffix - A constant that will be appended to the name of the newly generated class.
      modify - Allows custom modifications to the generated class.
      Returns:
      An instance of an anonymous subclass of S.
    • findInstantiablePermittedSubclass

      private static <T> Class<T> findInstantiablePermittedSubclass(ClassProbe<T> probe, ValueProvider vp, Attributes attributes)
    • isUsable

      private static <T> boolean isUsable(Class<T> type, ValueProvider vp, Attributes attributes)
    • isRecursive

      private static <T> boolean isRecursive(Class<T> type, ValueProvider vp, Attributes attributes)
    • findAllInstantiablePermittedSubclasses

      static <T> Stream<Class<? extends T>> findAllInstantiablePermittedSubclasses(ClassProbe<T> probe)
    • getClassLoadingStrategy

      private static <S> net.bytebuddy.dynamic.loading.ClassLoadingStrategy<ClassLoader> getClassLoadingStrategy(Class<S> context)
    • isSystemClass

      private static boolean isSystemClass(String className)
    • getPackageName

      private static String getPackageName(Class<?> type)