Interface BeanIntrospection<T>

Type Parameters:
T - The bean type
All Superinterfaces:
AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, ArgumentCoercible<T>, BeanInfo<T>
All Known Implementing Classes:
AbstractBeanIntrospection, AbstractInitializableBeanIntrospection

public interface BeanIntrospection<T> extends AnnotationMetadataDelegate, BeanInfo<T>
A 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:
  • Method Details

    • getBeanProperties

      @NonNull Collection<BeanProperty<T,Object>> getBeanProperties()
      Returns:
      A immutable collection of properties.
    • getIndexedProperties

      @NonNull Collection<BeanProperty<T,Object>> getIndexedProperties(@NonNull Class<? extends Annotation> annotationType)
      Get all the bean properties annotated for the given annotation type. If the annotation is Introspected.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:
    • 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(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 by getConstructorArguments()
      Returns:
      An instance
      Throws:
      InstantiationException - If the bean cannot be instantiated.
    • instantiate

      @NonNull T instantiate(boolean strictNullable, 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 annotation
      arguments - The arguments required to instantiate bean. Should match the types returned by getConstructorArguments()
      Returns:
      An instance
      Throws:
      InstantiationException - If the bean cannot be instantiated.
    • getBeanType

      @NonNull Class<T> getBeanType()
      The bean type.
      Specified by:
      getBeanType in interface BeanInfo<T>
      Returns:
      The bean type
    • getIndexedProperty

      @NonNull Optional<BeanProperty<T,Object>> getIndexedProperty(@NonNull Class<? extends Annotation> annotationType, @NonNull String annotationValue)
      Get all the bean properties annotated for the given type.
      Parameters:
      annotationType - The annotation type
      annotationValue - The annotation value
      Returns:
      A immutable collection of properties.
      See Also:
    • getBeanMethods

      @NonNull default Collection<BeanMethod<T,Object>> getBeanMethods()
      Returns the BeanMethod instances for this introspection.

      The BeanMethod instances are only those methods annotated with io.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 as BeanProperty instances.

      Returns:
      A immutable collection of methods.
      Since:
      2.3.0
    • getIndexedProperty

      @NonNull default Optional<BeanProperty<T,Object>> getIndexedProperty(@NonNull Class<? extends 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:
    • getConstructorArguments

      @NonNull default Argument<?>[] getConstructorArguments()
      The constructor arguments needed to instantiate the bean.
      Returns:
      An argument array
    • getProperty

      @NonNull default Optional<BeanProperty<T,Object>> getProperty(@NonNull 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 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 String name, @NonNull Class<P> type)
      Gets a property of the given name and type or throws IntrospectionException if the property is not present.
      Type Parameters:
      P - The property generic type
      Parameters:
      name - The name
      type - The type
      Returns:
      The property
    • getProperty

      @NonNull default <P> Optional<BeanProperty<T,P>> getProperty(@NonNull String name, @NonNull Class<P> type)
      Obtain a property by name and type.
      Type Parameters:
      P - The property type
      Parameters:
      name - The name of the property
      type - The property type to search for
      Returns:
      A bean property if found
    • getPropertyNames

      @NonNull default 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(Class<T2> type)
      Obtains an introspection from the default BeanIntrospector.
      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