java.lang.Object
org.litebridge.tracking.ClassFieldAccessorCache
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 Summary
ConstructorsConstructorDescriptionConstructs a newClassFieldAccessorCacheusing the defaultMethodHandles.lookup().Constructs a newClassFieldAccessorCacheusing the providedMethodHandles.Lookup. -
Method Summary
Modifier and TypeMethodDescriptionfieldAccessor(Class<?> dtoClass, String fieldName) Retrieves aFieldAccessorfor the specified field name or path.fieldAccessorOrThrow(Class<?> dtoClass, String field) Retrieves aFieldAccessorfor the specified field path, or throws an exception if it doesn't exist.fieldAccessors(Class<?> dtoClass) Retrieves all field accessors for the specified class.Class<?>[]getGenericTypes(Field field) Retrieves the generic type arguments for a given field, with caching.booleanisNestedDtoField(Class<?> dtoClass, FieldAccessor field) Determines if a field represents a nested DTO.propertyAccessor(Class<?> dtoClass, String propertyName) Retrieves a property accessor for the specified property name.voidregisterElevatedLookup(Class<?> dtoClass, MethodHandles.Lookup elevatedLookup) Registers an elevatedMethodHandles.Lookupfor a specific DTO class, allowing access to private fields.
-
Constructor Details
-
ClassFieldAccessorCache
public ClassFieldAccessorCache()Constructs a newClassFieldAccessorCacheusing the defaultMethodHandles.lookup(). -
ClassFieldAccessorCache
Constructs a newClassFieldAccessorCacheusing the providedMethodHandles.Lookup.- Parameters:
lookup- the lookup to use for access checking
-
-
Method Details
-
registerElevatedLookup
Registers an elevatedMethodHandles.Lookupfor a specific DTO class, allowing access to private fields.- Parameters:
dtoClass- the class for which to register the lookupelevatedLookup- the elevated lookup instance
-
fieldAccessorOrThrow
Retrieves aFieldAccessorfor the specified field path, or throws an exception if it doesn't exist.- Parameters:
dtoClass- the class containing the fieldfield- the field path (can be dot-separated for nested fields)- Returns:
- the field accessor
- Throws:
IllegalArgumentException- if the field cannot be found
-
fieldAccessors
Retrieves all field accessors for the specified class.- Parameters:
dtoClass- the class to retrieve accessors for- Returns:
- a list of all field accessors
-
isNestedDtoField
Determines if a field represents a nested DTO.- Parameters:
dtoClass- the class containing the fieldfield- the field accessor to check- Returns:
trueif the field is a nested DTO;falseotherwise
-
fieldAccessor
Retrieves aFieldAccessorfor the specified field name or path.- Parameters:
dtoClass- the class containing the fieldfieldName- the field name or path- Returns:
- the field accessor
-
propertyAccessor
Retrieves a property accessor for the specified property name.- Parameters:
dtoClass- the class containing the propertypropertyName- the name of the property- Returns:
- the field accessor for the property
-
getGenericTypes
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
-