Class AbstractInitializableBeanIntrospection<B>

java.lang.Object
io.micronaut.inject.beans.AbstractInitializableBeanIntrospection<B>
Type Parameters:
B - The bean type
All Implemented Interfaces:
AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, BeanInfo<B>, BeanIntrospection<B>, UnsafeBeanInstantiationIntrospection<B>, Ordered, ArgumentCoercible<B>
Direct Known Subclasses:
AbstractInitializableBeanIntrospectionAndReference

public abstract class AbstractInitializableBeanIntrospection<B> extends Object implements UnsafeBeanInstantiationIntrospection<B>
Abstract implementation of the BeanIntrospection interface. This class is subclassed at compilation time by generated bytecode and should not be used directly.

The generated subclass uses method dispatch to access the bean instance. Boxed dispatch methods provide the general reflection-free access path, while the primitive dispatch methods exist for generated UnsafeBeanReadProperty and UnsafeBeanWriteProperty implementations that need to avoid primitive boxing in hot paths.

Since:
3.1
Author:
Denis Stepanov
  • Constructor Details

  • Method Details

    • builder

      public BeanIntrospection.Builder<B> builder()
      Specified by:
      builder in interface BeanIntrospection<B>
      Returns:
      Obtain a builder for this introspection.
    • hasConstructor

      protected boolean hasConstructor()
      Whether an accessible constructor exists.
      Returns:
      True if a default constructor exists
      Since:
      4.7.11
    • instantiateInternal

      @Internal protected B instantiateInternal(@Nullable Object @Nullable [] arguments)
      Reflection free bean instantiation implementation for the given arguments.
      Parameters:
      arguments - The arguments
      Returns:
      The bean
    • getPropertyByIndex

      @Internal protected BeanProperty<B,Object> getPropertyByIndex(int index)
      Obtain a property by its index.
      Parameters:
      index - The index of the property
      Returns:
      A bean property
    • propertyIndexOf

      public int propertyIndexOf(String name)
      Description copied from interface: BeanIntrospection
      Obtain the property index position.
      Specified by:
      propertyIndexOf in interface BeanIntrospection<B>
      Parameters:
      name - The name of the property
      Returns:
      A property index or -1 of not found.
    • getTargetMethodByIndex

      @Internal protected abstract Method getTargetMethodByIndex(int index)
      Find Method representation at the method by index. Used by MethodReference.getTargetMethod().
      Parameters:
      index - The index
      Returns:
      The method
    • getAccessibleTargetMethodByIndex

      protected final Method getAccessibleTargetMethodByIndex(int index)
      Find Method representation at the method by index. Used by MethodReference.getTargetMethod().
      Parameters:
      index - The index
      Returns:
      The method
      Since:
      3.8.5
    • dispatch

      protected <V> @Nullable V dispatch(int index, B target, @Nullable Object[] args)
      Triggers the invocation of the method at index.
      Type Parameters:
      V - The result type
      Parameters:
      index - The method index
      target - The target
      args - The arguments
      Returns:
      The result
    • dispatchOne

      protected <V> @Nullable V dispatchOne(int index, Object target, @Nullable Object arg)
      Triggers the invocation of the method at index for a single-argument call, avoiding wrapping the value in an Object[] array.

      For no-argument calls (for example, property getters), generated code passes null as arg. This is the boxed single-argument dispatch path used by unsafe bean property implementations. Primitive property access uses the type-specific dispatch methods below when generated introspections provide them, so serializers and other hot paths can avoid boxing primitive values.

      Type Parameters:
      V - The result type
      Parameters:
      index - The method index
      target - The target
      arg - The argument
      Returns:
      The result
    • dispatchOneVoid

      protected void dispatchOneVoid(int index, Object target, @Nullable Object arg)
      Triggers the invocation of the void method at index for a single argument call. Allowing to not wrap a single argument in an object array or return a placeholder value.

      This method is used by setter paths where the caller does not need a return value. The primitive dispatchSet*Void methods below build on this contract and let generated introspections avoid both a synthetic return value and primitive boxing.

      Parameters:
      index - The method index
      target - The target
      arg - The argument
      Since:
      5.1.0
    • dispatchGetBoolean

      protected boolean dispatchGetBoolean(int index, Object target)
      Triggers the primitive boolean getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getBooleanUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetByte

      protected byte dispatchGetByte(int index, Object target)
      Triggers the primitive byte getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getByteUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetShort

      protected short dispatchGetShort(int index, Object target)
      Triggers the primitive short getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getShortUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetChar

      protected char dispatchGetChar(int index, Object target)
      Triggers the primitive char getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getCharUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetInt

      protected int dispatchGetInt(int index, Object target)
      Triggers the primitive int getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getIntUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetLong

      protected long dispatchGetLong(int index, Object target)
      Triggers the primitive long getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getLongUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetFloat

      protected float dispatchGetFloat(int index, Object target)
      Triggers the primitive float getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getFloatUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchGetDouble

      protected double dispatchGetDouble(int index, Object target)
      Triggers the primitive double getter invocation at index.

      The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object). Generated introspections override this method with a primitive switch dispatch to avoid boxing in hot paths. It backs UnsafeBeanReadProperty.getDoubleUnsafe(Object) for generated bean properties.

      Parameters:
      index - The method index
      target - The target
      Returns:
      The primitive value
      Since:
      5.1.0
    • dispatchSetBoolean

      protected @Nullable Object dispatchSetBoolean(int index, Object target, boolean value)
      Triggers the primitive boolean setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetBooleanVoid

      protected void dispatchSetBooleanVoid(int index, Object target, boolean value)
      Triggers the primitive boolean setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetByte

      protected @Nullable Object dispatchSetByte(int index, Object target, byte value)
      Triggers the primitive byte setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetByteVoid

      protected void dispatchSetByteVoid(int index, Object target, byte value)
      Triggers the primitive byte setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetShort

      protected @Nullable Object dispatchSetShort(int index, Object target, short value)
      Triggers the primitive short setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetShortVoid

      protected void dispatchSetShortVoid(int index, Object target, short value)
      Triggers the primitive short setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetChar

      protected @Nullable Object dispatchSetChar(int index, Object target, char value)
      Triggers the primitive char setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetCharVoid

      protected void dispatchSetCharVoid(int index, Object target, char value)
      Triggers the primitive char setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetInt

      protected @Nullable Object dispatchSetInt(int index, Object target, int value)
      Triggers the primitive int setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetIntVoid

      protected void dispatchSetIntVoid(int index, Object target, int value)
      Triggers the primitive int setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetLong

      protected @Nullable Object dispatchSetLong(int index, Object target, long value)
      Triggers the primitive long setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetLongVoid

      protected void dispatchSetLongVoid(int index, Object target, long value)
      Triggers the primitive long setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetFloat

      protected @Nullable Object dispatchSetFloat(int index, Object target, float value)
      Triggers the primitive float setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetFloatVoid

      protected void dispatchSetFloatVoid(int index, Object target, float value)
      Triggers the primitive float setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • dispatchSetDouble

      protected @Nullable Object dispatchSetDouble(int index, Object target, double value)
      Triggers the primitive double setter invocation at index.

      Generated introspections may override this method to dispatch primitive write/copy-constructor paths without boxing before the switch. The base implementation preserves compatibility by boxing through dispatchOne(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Returns:
      The dispatch result
      Since:
      5.1.0
    • dispatchSetDoubleVoid

      protected void dispatchSetDoubleVoid(int index, Object target, double value)
      Triggers the primitive double setter invocation at index.

      Generated introspections may override this method to dispatch mutable setter paths without boxing before the switch and without producing a return value. The base implementation preserves compatibility by boxing through dispatchOneVoid(int, Object, Object).

      Parameters:
      index - The method index
      target - The target
      value - The primitive value
      Since:
      5.1.0
    • unknownDispatchAtIndexException

      protected final RuntimeException unknownDispatchAtIndexException(int index)
      Creates a new exception when the dispatch at index is not found.
      Parameters:
      index - The method index
      Returns:
      The exception
    • findIndexedProperty

      public @Nullable BeanProperty<B,Object> findIndexedProperty(Class<? extends Annotation> annotationType, String annotationValue)
      Get all the bean properties annotated for the given type. Nullable result method version of getIndexedProperty(Class, String).
      Parameters:
      annotationType - The annotation type
      annotationValue - The annotation value
      Returns:
      An immutable collection of properties.
      See Also:
    • getIndexedProperties

      public Collection<BeanProperty<B,Object>> getIndexedProperties(Class<? extends Annotation> annotationType)
      Description copied from interface: BeanIntrospection
      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.
      Specified by:
      getIndexedProperties in interface BeanIntrospection<B>
      Parameters:
      annotationType - The annotation type
      Returns:
      An immutable collection of properties.
      See Also:
    • getBeanPropertiesIndexedSubset

      protected Collection<BeanProperty<B,Object>> getBeanPropertiesIndexedSubset(int[] indexes)
      Returns subset of bean properties defined by an array of indexes.
      Parameters:
      indexes - The indexes
      Returns:
      a collection of bean properties
    • instantiate

      public B instantiate() throws InstantiationException
      Description copied from interface: BeanIntrospection
      Instantiates an instance of the bean, throwing an exception is instantiation is not possible.
      Specified by:
      instantiate in interface BeanIntrospection<B>
      Returns:
      An instance
      Throws:
      InstantiationException - If the bean cannot be instantiated or the arguments are not satisfied.
    • instantiate

      public B instantiate(boolean strictNullable, @Nullable Object... arguments) throws InstantiationException
      Description copied from interface: BeanIntrospection
      Instantiates an instance of the bean, throwing an exception is instantiation is not possible.
      Specified by:
      instantiate in interface BeanIntrospection<B>
      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 BeanIntrospection.getConstructorArguments()
      Returns:
      An instance
      Throws:
      InstantiationException - If the bean cannot be instantiated.
    • instantiateUnsafe

      public B instantiateUnsafe(@Nullable Object @Nullable ... arguments)
      Description copied from interface: UnsafeBeanInstantiationIntrospection
      Instantiates an instance of the bean.
      Specified by:
      instantiateUnsafe in interface UnsafeBeanInstantiationIntrospection<B>
      Parameters:
      arguments - The arguments required to instantiate bean.
      Returns:
      An instance
    • getConstructor

      public BeanConstructor<B> getConstructor()
      Specified by:
      getConstructor in interface BeanIntrospection<B>
      Returns:
      The bean constructor.
    • getConstructorArguments

      public Argument<?>[] getConstructorArguments()
      Description copied from interface: BeanIntrospection
      The constructor arguments needed to instantiate the bean.
      Specified by:
      getConstructorArguments in interface BeanIntrospection<B>
      Returns:
      An argument array
    • getIndexedProperty

      public Optional<BeanProperty<B,Object>> getIndexedProperty(Class<? extends Annotation> annotationType, String annotationValue)
      Description copied from interface: BeanIntrospection
      Get all the bean properties annotated for the given type.
      Specified by:
      getIndexedProperty in interface BeanIntrospection<B>
      Parameters:
      annotationType - The annotation type
      annotationValue - The annotation value
      Returns:
      An immutable collection of properties.
      See Also:
    • getProperty

      public Optional<BeanProperty<B,Object>> getProperty(String name)
      Description copied from interface: BeanIntrospection
      Obtain a property by name.
      Specified by:
      getProperty in interface BeanIntrospection<B>
      Parameters:
      name - The name of the property
      Returns:
      A bean property if found
    • getAnnotationMetadata

      public AnnotationMetadata getAnnotationMetadata()
      Description copied from interface: AnnotationMetadataProvider
      Supplies the metadata. Defaults to AnnotationMetadata.EMPTY_METADATA.
      Specified by:
      getAnnotationMetadata in interface AnnotationMetadataProvider
      Returns:
      The AnnotationMetadata
    • getBeanProperties

      public Collection<BeanProperty<B,Object>> getBeanProperties()
      Specified by:
      getBeanProperties in interface BeanIntrospection<B>
      Returns:
      An immutable collection of properties.
    • getBeanReadProperties

      public List<BeanReadProperty<B,Object>> getBeanReadProperties()
      Specified by:
      getBeanReadProperties in interface BeanIntrospection<B>
      Returns:
      An immutable collection of read properties.
    • getBeanWriteProperties

      public List<BeanWriteProperty<B,Object>> getBeanWriteProperties()
      Specified by:
      getBeanWriteProperties in interface BeanIntrospection<B>
      Returns:
      An immutable collection of write properties.
    • getBeanType

      public Class<B> getBeanType()
      Description copied from interface: BeanIntrospection
      The bean type.
      Specified by:
      getBeanType in interface BeanInfo<B>
      Specified by:
      getBeanType in interface BeanIntrospection<B>
      Returns:
      The bean type
    • getBeanMethods

      public Collection<BeanMethod<B,Object>> getBeanMethods()
      Description copied from interface: BeanIntrospection
      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.

      Specified by:
      getBeanMethods in interface BeanIntrospection<B>
      Returns:
      An immutable collection of methods.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object