Interface BeanIntrospection<T>
- Type Parameters:
T- The bean type
- All Superinterfaces:
AnnotationMetadata,AnnotationMetadataDelegate,AnnotationMetadataProvider,AnnotationSource,ArgumentCoercible<T>,BeanInfo<T>,Ordered
- All Known Subinterfaces:
EnumBeanIntrospection<E>,UnsafeBeanInstantiationIntrospection<T>
- All Known Implementing Classes:
AbstractEnumBeanIntrospectionAndReference,AbstractInitializableBeanIntrospection,AbstractInitializableBeanIntrospectionAndReference
BeanIntrospection is the result of compile time computation of a beans properties and annotation metadata.
This interface allows you to instantiate and read and write to bean properties without using reflection or caching reflective metadata, which is expensive from a memory consumption perspective.
BeanIntrospection instances can be obtained either via getIntrospection(Class) or via the BeanIntrospector.
A BeanIntrospection is only computed at compilation time if the class is annotated with Introspected.
- Since:
- 1.1
- Author:
- graemerocher
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder style API for creating instances that abstracts whether the instance is a record, bean or created by another builder. -
Field Summary
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTYFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptionbuilder()default Collection<BeanMethod<T, Object>> Returns theBeanMethodinstances for this introspection.default List<BeanReadProperty<T, Object>> The bean type.default List<BeanWriteProperty<T, Object>> default BeanConstructor<T> default Argument<?>[]The constructor arguments needed to instantiate the bean.getIndexedProperties(Class<? extends Annotation> annotationType) Get all the bean properties annotated for the given annotation type.default Optional<BeanProperty<T, Object>> getIndexedProperty(Class<? extends Annotation> annotationType) Get first bean properties annotated for the given type.getIndexedProperty(Class<? extends Annotation> annotationType, String annotationValue) Get all the bean properties annotated for the given type.static <T2> BeanIntrospection<T2> getIntrospection(Class<T2> type) Obtains an introspection from the defaultBeanIntrospector.default Optional<BeanProperty<T, Object>> getProperty(String name) Obtain a property by name.default <P> Optional<BeanProperty<T, P>> getProperty(String name, Class<P> type) Obtain a property by name and type.default String[]The property names as an array.default Optional<BeanReadProperty<T, Object>> getReadProperty(String name) Obtain a read property by name.default <P> Optional<BeanReadProperty<T, P>> getReadProperty(String name, Class<P> type) Obtain a read property by name and type.default String[]The read property names as an array.default <P> BeanProperty<T, P> getRequiredProperty(String name, Class<P> type) Gets a property of the given name and type or throwsIntrospectionExceptionif the property is not present.default <P> BeanReadProperty<T, P> getRequiredReadProperty(String name, Class<P> type) Gets a read property of the given name and type or throwsIntrospectionExceptionif the property is not present.default <P> BeanWriteProperty<T, P> getRequiredWriteProperty(String name, Class<P> type) Gets a write property of the given name and type or throwsIntrospectionExceptionif the property is not present.default Optional<BeanWriteProperty<T, Object>> getWriteProperty(String name) Obtain a write property by name.default <P> Optional<BeanWriteProperty<T, P>> getWriteProperty(String name, Class<P> type) Obtain a write property by name and type.default booleanDoes the introspection have a backing builder.Instantiates an instance of the bean, throwing an exception is instantiation is not possible.instantiate(boolean strictNullable, @Nullable Object @Nullable ... arguments) Instantiates an instance of the bean, throwing an exception is instantiation is not possible.default Tinstantiate(@Nullable Object @Nullable ... arguments) Instantiates an instance of the bean, throwing an exception is instantiation is not possible.default booleanCan the introspection be constructed withbuilder().default intpropertyIndexOf(String name) Obtain the property index position.Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider
getAnnotationMetadataMethods inherited from interface io.micronaut.core.beans.BeanInfo
asArgument, getGenericBeanType, getOrder
-
Method Details
-
getBeanProperties
Collection<BeanProperty<T,Object>> getBeanProperties()- Returns:
- An immutable collection of properties.
-
getBeanReadProperties
- Returns:
- An immutable collection of read properties.
- Since:
- 4.4.0
-
getBeanWriteProperties
- Returns:
- An immutable collection of write properties.
- Since:
- 4.4.0
-
getIndexedProperties
Get all the bean properties annotated for the given annotation type. If the annotation isIntrospected.indexed()by the given annotation, then it will be included in the resulting list.- Parameters:
annotationType- The annotation type- Returns:
- An immutable collection of properties.
- See Also:
-
builder
BeanIntrospection.Builder<T> builder()- Returns:
- Obtain a builder for this introspection.
- Since:
- 4.1.0
-
isBuildable
default boolean isBuildable()Can the introspection be constructed withbuilder().- Returns:
- True if it can
- Since:
- 4.1.0
-
hasBuilder
default boolean hasBuilder()Does the introspection have a backing builder.This method exists so that consumers can choose to optimize towards direct instantiation using
instantiate()if no builder is present.- Returns:
- True if a backing builder is present.
- Since:
- 4.1.0
-
instantiate
Instantiates an instance of the bean, throwing an exception is instantiation is not possible.- Returns:
- An instance
- Throws:
InstantiationException- If the bean cannot be instantiated or the arguments are not satisfied.
-
instantiate
Instantiates an instance of the bean, throwing an exception is instantiation is not possible.- Parameters:
arguments- The arguments required to instantiate bean. Should match the types returned bygetConstructorArguments()- Returns:
- An instance
- Throws:
InstantiationException- If the bean cannot be instantiated.
-
instantiate
T instantiate(boolean strictNullable, @Nullable Object @Nullable ... arguments) throws InstantiationException Instantiates an instance of the bean, throwing an exception is instantiation is not possible.- Parameters:
strictNullable- If true, require null parameters to be annotated with a nullable annotationarguments- The arguments required to instantiate bean. Should match the types returned bygetConstructorArguments()- Returns:
- An instance
- Throws:
InstantiationException- If the bean cannot be instantiated.
-
getBeanType
The bean type.- Specified by:
getBeanTypein interfaceBeanInfo<T>- Returns:
- The bean type
-
getIndexedProperty
Optional<BeanProperty<T,Object>> getIndexedProperty(Class<? extends Annotation> annotationType, String annotationValue) Get all the bean properties annotated for the given type.- Parameters:
annotationType- The annotation typeannotationValue- The annotation value- Returns:
- An immutable collection of properties.
- See Also:
-
getBeanMethods
Returns theBeanMethodinstances for this introspection.The
BeanMethodinstances are only those methods annotated withio.micronaut.context.annotation.Executableand hence represent a subset of the actual methods of the class and do not include any methods that are exposed asBeanPropertyinstances.- Returns:
- An immutable collection of methods.
- Since:
- 2.3.0
-
getIndexedProperty
default Optional<BeanProperty<T,Object>> getIndexedProperty(Class<? extends Annotation> annotationType) Get first bean properties annotated for the given type.- Parameters:
annotationType- The annotation type- Returns:
- An immutable collection of properties.
- See Also:
-
getConstructorArguments
The constructor arguments needed to instantiate the bean.- Returns:
- An argument array
-
getProperty
Obtain a property by name.- Parameters:
name- The name of the property- Returns:
- A bean property if found
-
getReadProperty
Obtain a read property by name.- Parameters:
name- The name of the property- Returns:
- A bean read property if found
- Since:
- 4.4.0
-
getWriteProperty
Obtain a write property by name.- Parameters:
name- The name of the property- Returns:
- A bean write property if found
- Since:
- 4.4.0
-
propertyIndexOf
Obtain the property index position.- Parameters:
name- The name of the property- Returns:
- A property index or -1 of not found.
- Since:
- 3.1
-
getRequiredProperty
Gets a property of the given name and type or throwsIntrospectionExceptionif the property is not present.- Type Parameters:
P- The property generic type- Parameters:
name- The nametype- The type- Returns:
- The property
-
getRequiredReadProperty
Gets a read property of the given name and type or throwsIntrospectionExceptionif the property is not present.- Type Parameters:
P- The property generic type- Parameters:
name- The nametype- The type- Returns:
- The property
- Since:
- 4.4.0
-
getRequiredWriteProperty
Gets a write property of the given name and type or throwsIntrospectionExceptionif the property is not present.- Type Parameters:
P- The property generic type- Parameters:
name- The nametype- The type- Returns:
- The property
- Since:
- 4.4.0
-
getProperty
Obtain a property by name and type.- Type Parameters:
P- The property type- Parameters:
name- The name of the propertytype- The property type to search for- Returns:
- A bean property if found
-
getReadProperty
Obtain a read property by name and type.- Type Parameters:
P- The property type- Parameters:
name- The name of the propertytype- The property type to search for- Returns:
- A bean read property if found
-
getWriteProperty
Obtain a write property by name and type.- Type Parameters:
P- The property type- Parameters:
name- The name of the propertytype- The property type to search for- Returns:
- A bean write property if found
- Since:
- 4.4.0
-
getPropertyNames
The property names as an array.- Returns:
- The property names
-
getReadPropertyNames
The read property names as an array.- Returns:
- The property names
- Since:
- 4.4.0
-
getConstructor
- Returns:
- The bean constructor.
- Since:
- 3.0.0
-
getIntrospection
Obtains an introspection from the defaultBeanIntrospector.- Type Parameters:
T2- The generic type- Parameters:
type- The type- Returns:
- The introspection
- Throws:
IntrospectionException- If the introspection cannot be found or errors when loading
-