Class TypeCollector

java.lang.Object
org.springframework.data.util.TypeCollector

public class TypeCollector extends Object
Collector to inspect domain types and discover the type graph that is relevant for Spring Data operations.

Type inspection walks through all class members (fields, methods, constructors) and introspects those for additional types that are part of the domain model.

Type collection can be customized by providing filters that stop introspection when encountering a Predicate that returns false. Filters are combined so that multiple filters can be taken into account. A type/field/method must pass all filters to be considered for further inspection.

The collector uses AotServices to discover implementations of TypeCollector.TypeCollectorFilters so that components using TypeCollector can contribute their own filtering logic to exclude types, fields, and methods from being inspected.

Since:
3.0
Author:
Christoph Strobl, Sebastien Deleuze, John Blum, Mark Paluch
  • Constructor Details

  • Method Details

    • filterTypes

      @Contract("_ -> this") public TypeCollector filterTypes(Predicate<Class<?>> filter)
      Add a filter to exclude types from being introspected.
      Parameters:
      filter - filter predicate matching a Class.
      Returns:
      this TypeCollector instance.
    • filterMethods

      @Contract("_ -> this") public TypeCollector filterMethods(Predicate<Method> filter)
      Add a filter to exclude methods from being introspected.
      Parameters:
      filter - filter predicate matching a Class.
      Returns:
      this TypeCollector instance.
      Since:
      4.0
    • filterFields

      @Contract("_ -> this") public TypeCollector filterFields(Predicate<Field> filter)
      Add a filter to exclude fields from being introspected.
      Parameters:
      filter - filter predicate matching a Class.
      Returns:
      this TypeCollector instance.
      Since:
      4.0
    • inspect

      public static TypeCollector.ReachableTypes inspect(Class<?>... types)
      Inspect the given type and resolve those reachable via fields, methods, generics, ...
      Parameters:
      types - the types to inspect
      Returns:
      a type model collector for the type
    • inspect

      public static TypeCollector.ReachableTypes inspect(Collection<Class<?>> types)
      Inspect the given type and resolve those reachable via fields, methods, generics, ...
      Parameters:
      types - the types to inspect
      Returns:
      a type model collector for the type
    • inspect

      public static TypeCollector.ReachableTypes inspect(Consumer<TypeCollector> collectorCustomizer, Class<?>... types)
      Inspect the given type and resolve those reachable via fields, methods, generics, ...
      Parameters:
      collectorCustomizer - the customizer function to configure the TypeCollector.
      types - the types to inspect.
      Returns:
      a type model collector for the type.
      Since:
      4.0
    • inspect

      public static TypeCollector.ReachableTypes inspect(Consumer<TypeCollector> collectorCustomizer, Collection<Class<?>> types)
      Inspect the given type and resolve those reachable via fields, methods, generics, ...
      Parameters:
      collectorCustomizer - the customizer function to configure the TypeCollector.
      types - the types to inspect.
      Returns:
      a type model collector for the type.
      Since:
      4.0