Package de.cuioss.test.valueobjects.util
Class ReflectionHelper
java.lang.Object
de.cuioss.test.valueobjects.util.ReflectionHelper
- Author:
- Oliver Wolff
-
Field Summary
FieldsModifier and TypeFieldDescriptionIdentifies the properties to be ignored. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PropertyMetadata
createPropertyMetadata
(Class<?> beanType, de.cuioss.tools.property.PropertyHolder propertyHolder) Creates aPropertyMetadata
for a given field.static <T> Class<T>
determineSupertypeFromIterable
(Iterable<T> iterable) Helper method that determines the actual type of a givenIterable
by peeking into it.static SortedSet<PropertyMetadata>
handlePostProcess
(Class<?> annotated, SortedSet<PropertyMetadata> metatdata) Filters the given properties according to the annotated element given.static SortedSet<PropertyMetadata>
handlePostProcessConfig
(PropertyReflectionConfig config, SortedSet<PropertyMetadata> metatdata) Filters the given properties according to the annotated element given.static <T> List<PropertyMetadata>
handlePropertyMetadata
(PropertyReflectionConfig propertyReflectionConfig, List<PropertyConfig> propertyConfig, Class<T> targetClass) One stop method for the deriving of configured metadatastatic <T> List<PropertyMetadata>
handlePropertyMetadata
(Class<?> annotated, Class<T> targetClass) One stop method for the deriving of configured metadatastatic SortedSet<PropertyMetadata>
scanBeanTypeForProperties
(Class<?> beanType, PropertyReflectionConfig config) UsesMoreReflection
to scan the concrete bean and describe the properties with fittingPropertyMetadata
.static boolean
Checks the given type for the annotationPropertyReflectionConfig
if it is there it checks on the valuePropertyReflectionConfig.skip()
static boolean
shouldScanClass
(Class<?> annotated) Checks the given type for the annotationPropertyReflectionConfig
if it is there it checks on the valuePropertyReflectionConfig.skip()
-
Field Details
-
PROPERTY_IGNORE_SET
Identifies the properties to be ignored. Currently only consisting of 'class'
-
-
Constructor Details
-
ReflectionHelper
public ReflectionHelper()
-
-
Method Details
-
handlePropertyMetadata
public static <T> List<PropertyMetadata> handlePropertyMetadata(Class<?> annotated, Class<T> targetClass) One stop method for the deriving of configured metadata- Parameters:
annotated
- must not be nulltargetClass
- must not be null- Returns:
- an immutable
List
ofPropertyMetadata
containing the result of the actual scanning withscanBeanTypeForProperties(Class, PropertyReflectionConfig)
andhandlePostProcess(Class, SortedSet)
andPropertyHelper.handlePropertyConfigAnnotations(Class)
andPropertyHelper.handlePrimitiveAsDefaults(Collection)
-
handlePropertyMetadata
public static <T> List<PropertyMetadata> handlePropertyMetadata(PropertyReflectionConfig propertyReflectionConfig, List<PropertyConfig> propertyConfig, Class<T> targetClass) One stop method for the deriving of configured metadata- Parameters:
propertyReflectionConfig
- extracted from the target class, may be null.propertyConfig
- extracted from the target class, may be emptytargetClass
- must not be null- Returns:
- an immutable
List
ofPropertyMetadata
containing the result of the actual scanning withscanBeanTypeForProperties(Class, PropertyReflectionConfig)
andhandlePostProcess(Class, SortedSet)
andPropertyHelper.handlePropertyConfigAnnotations(Class)
andPropertyHelper.handlePrimitiveAsDefaults(Collection)
-
scanBeanTypeForProperties
public static SortedSet<PropertyMetadata> scanBeanTypeForProperties(Class<?> beanType, PropertyReflectionConfig config) UsesMoreReflection
to scan the concrete bean and describe the properties with fittingPropertyMetadata
. Each property will contain the derived data for the attributes:PropertyMetadata.getName()
PropertyMetadata.getGenerator()
with the generator being dynamically resolved usingGeneratorResolver.resolveGenerator(Class)
PropertyMetadata.getPropertyReadWrite()
PropertyMetadata.getCollectionType()
PropertyMetadata.getPropertyMemberInfo()
PropertyMetadata.isRequired()
defaults to falsePropertyMetadata.isDefaultValue()
defaults to false
- Parameters:
beanType
- to be checked by reflectionconfig
- optional instance ofPropertyReflectionConfig
used for filtering the scanning- Returns:
- a
SortedSet
containing the result of the inspection
-
createPropertyMetadata
public static PropertyMetadata createPropertyMetadata(Class<?> beanType, de.cuioss.tools.property.PropertyHolder propertyHolder) Creates aPropertyMetadata
for a given field.- Parameters:
beanType
- providing the property, must not be nullpropertyHolder
- identifying the property-metadata, must not be null- Returns:
- an instance of
PropertyMetadata
describing the field. - Throws:
IllegalArgumentException
- wrapping underlying reflection exceptions.
-
handlePostProcess
public static SortedSet<PropertyMetadata> handlePostProcess(Class<?> annotated, SortedSet<PropertyMetadata> metatdata) Filters the given properties according to the annotated element given. It checks for the annotationPropertyReflectionConfig
and filters the givenSortedSet
- Parameters:
annotated
- must not be nullmetatdata
- must not be null- Returns:
- the filtered
SortedSet
-
handlePostProcessConfig
public static SortedSet<PropertyMetadata> handlePostProcessConfig(PropertyReflectionConfig config, SortedSet<PropertyMetadata> metatdata) Filters the given properties according to the annotated element given. It checks for the annotationPropertyReflectionConfig
and filters the givenSortedSet
- Parameters:
config
- must not be nullmetatdata
- must not be null- Returns:
- the filtered
SortedSet
-
shouldScanClass
Checks the given type for the annotationPropertyReflectionConfig
if it is there it checks on the valuePropertyReflectionConfig.skip()
- Parameters:
annotated
- the class that may or may not provide the annotations, must not be null- Returns:
- boolean indicating whether to skip property scanning.
-
shouldScanClass
Checks the given type for the annotationPropertyReflectionConfig
if it is there it checks on the valuePropertyReflectionConfig.skip()
- Parameters:
config
- the optional annotation, may be null- Returns:
- boolean indicating whether to skip property scanning.
-
determineSupertypeFromIterable
Helper method that determines the actual type of a givenIterable
by peeking into it. For testing only, should never be used in productive code- Parameters:
iterable
- must not be null nor empty, the iterator must be reentrant.- Returns:
- The Class of the given
Iterable
.
-