Class ClassFieldAccessorCache

java.lang.Object
org.litebridge.tracking.ClassFieldAccessorCache

public class ClassFieldAccessorCache extends Object
A utility class that facilitates caching and retrieving FieldAccessor instances for DTO classes.

The cache is organized by class type and field name for efficient lookup and reuse of FieldAccessor instances.

  • Constructor Details

    • ClassFieldAccessorCache

      public ClassFieldAccessorCache()
      Constructs a new ClassFieldAccessorCache using the default MethodHandles.lookup().
    • ClassFieldAccessorCache

      public ClassFieldAccessorCache(MethodHandles.Lookup lookup)
      Constructs a new ClassFieldAccessorCache using the provided MethodHandles.Lookup.
      Parameters:
      lookup - the lookup to use for access checking
  • Method Details

    • registerElevatedLookup

      public void registerElevatedLookup(Class<?> dtoClass, MethodHandles.Lookup elevatedLookup)
      Registers an elevated MethodHandles.Lookup for a specific DTO class, allowing access to private fields.
      Parameters:
      dtoClass - the class for which to register the lookup
      elevatedLookup - the elevated lookup instance
    • fieldAccessorOrThrow

      public FieldAccessor fieldAccessorOrThrow(Class<?> dtoClass, String field)
      Retrieves a FieldAccessor for the specified field path, or throws an exception if it doesn't exist.
      Parameters:
      dtoClass - the class containing the field
      field - the field path (can be dot-separated for nested fields)
      Returns:
      the field accessor
      Throws:
      IllegalArgumentException - if the field cannot be found
    • fieldAccessors

      public List<FieldAccessor> fieldAccessors(Class<?> dtoClass)
      Retrieves all field accessors for the specified class.
      Parameters:
      dtoClass - the class to retrieve accessors for
      Returns:
      a list of all field accessors
    • isNestedDtoField

      public boolean isNestedDtoField(Class<?> dtoClass, FieldAccessor field)
      Determines if a field represents a nested DTO.
      Parameters:
      dtoClass - the class containing the field
      field - the field accessor to check
      Returns:
      true if the field is a nested DTO; false otherwise
    • fieldAccessor

      public FieldAccessor fieldAccessor(Class<?> dtoClass, String fieldName)
      Retrieves a FieldAccessor for the specified field name or path.
      Parameters:
      dtoClass - the class containing the field
      fieldName - the field name or path
      Returns:
      the field accessor
    • propertyAccessor

      public FieldAccessor propertyAccessor(Class<?> dtoClass, String propertyName)
      Retrieves a property accessor for the specified property name.
      Parameters:
      dtoClass - the class containing the property
      propertyName - the name of the property
      Returns:
      the field accessor for the property
    • getGenericTypes

      public Class<?>[] getGenericTypes(Field field)
      Retrieves the generic type arguments for a given field, with caching.
      Parameters:
      field - the field to inspect
      Returns:
      an array of classes representing the generic type arguments