Package io.micronaut.core.beans
Interface BeanIntrospection<T>
-
- Type Parameters:
T
- The bean type
- All Superinterfaces:
AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,AnnotationSource
- All Known Implementing Classes:
AbstractBeanIntrospection
@Immutable public interface BeanIntrospection<T> extends AnnotationMetadataDelegate
ABeanIntrospection
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 viagetIntrospection(Class)
or via theBeanIntrospector
.A
BeanIntrospection
is only computed at compilation time if the class is annotated withIntrospected
.- Since:
- 1.1
- See Also:
BeanIntrospector
,Introspected
-
-
Field Summary
-
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
-
Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.Collection<BeanMethod<T,java.lang.Object>>
getBeanMethods()
Returns theBeanMethod
instances for this introspection.java.util.Collection<BeanProperty<T,java.lang.Object>>
getBeanProperties()
java.lang.Class<T>
getBeanType()
The bean type.default BeanConstructor<T>
getConstructor()
default Argument<?>[]
getConstructorArguments()
The constructor arguments needed to instantiate the bean.java.util.Collection<BeanProperty<T,java.lang.Object>>
getIndexedProperties(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Get all the bean properties annotated for the given annotation type.default java.util.Optional<BeanProperty<T,java.lang.Object>>
getIndexedProperty(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Get all the bean properties annotated for the given type.java.util.Optional<BeanProperty<T,java.lang.Object>>
getIndexedProperty(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.String annotationValue)
Get all the bean properties annotated for the given type.static <T2> BeanIntrospection<T2>
getIntrospection(java.lang.Class<T2> type)
Obtains an introspection from the defaultBeanIntrospector
.default java.util.Optional<BeanProperty<T,java.lang.Object>>
getProperty(java.lang.String name)
Obtain a property by name.default <P> java.util.Optional<BeanProperty<T,P>>
getProperty(java.lang.String name, java.lang.Class<P> type)
Obtain a property by name and type.default java.lang.String[]
getPropertyNames()
The property names as an array.default <P> BeanProperty<T,P>
getRequiredProperty(java.lang.String name, java.lang.Class<P> type)
Gets a property of the given name and type or throwsIntrospectionException
if the property is not present.T
instantiate()
Instantiates an instance of the bean, throwing an exception is instantiation is not possible.T
instantiate(boolean strictNullable, java.lang.Object... arguments)
Instantiates an instance of the bean, throwing an exception is instantiation is not possible.default T
instantiate(java.lang.Object... arguments)
Instantiates an instance of the bean, throwing an exception is instantiation is not possible.default int
propertyIndexOf(java.lang.String name)
Obtain the property index position.-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
getAnnotationValuesByName, getAnnotationValuesByStereotype, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresent
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, 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, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, 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, synthesizeDeclaredAnnotationsByType
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider
getAnnotationMetadata
-
-
-
-
Method Detail
-
getBeanProperties
@NonNull java.util.Collection<BeanProperty<T,java.lang.Object>> getBeanProperties()
- Returns:
- A immutable collection of properties.
-
getIndexedProperties
@NonNull java.util.Collection<BeanProperty<T,java.lang.Object>> getIndexedProperties(@NonNull java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
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:
- A immutable collection of properties.
- See Also:
Introspected.indexed()
-
instantiate
@NonNull T instantiate() throws InstantiationException
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
@NonNull default T instantiate(java.lang.Object... arguments) throws InstantiationException
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
@NonNull T instantiate(boolean strictNullable, java.lang.Object... 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.
-
getIndexedProperty
@NonNull java.util.Optional<BeanProperty<T,java.lang.Object>> getIndexedProperty(@NonNull java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, @NonNull java.lang.String annotationValue)
Get all the bean properties annotated for the given type.- Parameters:
annotationType
- The annotation typeannotationValue
- The annotation value- Returns:
- A immutable collection of properties.
- See Also:
Introspected.indexed()
-
getBeanMethods
@NonNull default java.util.Collection<BeanMethod<T,java.lang.Object>> getBeanMethods()
Returns theBeanMethod
instances for this introspection.The
BeanMethod
instances are only those methods annotated withio.micronaut.context.annotation.Executable
and hence represent a subset of the actual methods of the class and do not include any methods that are exposed asBeanProperty
instances.- Returns:
- A immutable collection of methods.
- Since:
- 2.3.0
-
getIndexedProperty
@NonNull default java.util.Optional<BeanProperty<T,java.lang.Object>> getIndexedProperty(@NonNull java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Get all the bean properties annotated for the given type.- Parameters:
annotationType
- The annotation type- Returns:
- A immutable collection of properties.
- See Also:
Introspected.indexed()
-
getConstructorArguments
@NonNull default Argument<?>[] getConstructorArguments()
The constructor arguments needed to instantiate the bean.- Returns:
- An argument array
-
getProperty
@NonNull default java.util.Optional<BeanProperty<T,java.lang.Object>> getProperty(@NonNull java.lang.String name)
Obtain a property by name.- Parameters:
name
- The name of the property- Returns:
- A bean property if found
-
propertyIndexOf
default int propertyIndexOf(@NonNull java.lang.String name)
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
@NonNull default <P> BeanProperty<T,P> getRequiredProperty(@NonNull java.lang.String name, @NonNull java.lang.Class<P> type)
Gets a property of the given name and type or throwsIntrospectionException
if the property is not present.- Type Parameters:
P
- The property generic type- Parameters:
name
- The nametype
- The type- Returns:
- The property
-
getProperty
@NonNull default <P> java.util.Optional<BeanProperty<T,P>> getProperty(@NonNull java.lang.String name, @NonNull java.lang.Class<P> type)
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
-
getPropertyNames
@NonNull default java.lang.String[] getPropertyNames()
The property names as an array.- Returns:
- The properties names
-
getConstructor
@NonNull default BeanConstructor<T> getConstructor()
- Returns:
- The bean constructor.
- Since:
- 3.0.0
-
getIntrospection
static <T2> BeanIntrospection<T2> getIntrospection(java.lang.Class<T2> type)
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
-
-