Package io.micronaut.core.beans
Class AbstractBeanProperty<B,P>
- java.lang.Object
-
- io.micronaut.core.beans.AbstractBeanProperty<B,P>
-
- Type Parameters:
B- The bean typeP- The property type
- All Implemented Interfaces:
AnnotatedElement,AnnotationMetadata,AnnotationMetadataDelegate,AnnotationMetadataProvider,AnnotationSource,BeanProperty<B,P>,UnsafeBeanProperty<B,P>,Named,ArgumentCoercible<P>
@Internal public abstract class AbstractBeanProperty<B,P> extends java.lang.Object implements UnsafeBeanProperty<B,P>
Abstract implementation ofBeanProperty. Generated byte code should be used to create a subclass and implement theBeanProperty.get(Object)andBeanProperty.set(Object, Object)methods. This class is subclasses at compilation time by generated byte code and should not be used directly.- Since:
- 1.1
-
-
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
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBeanProperty(BeanIntrospection<B> introspection, java.lang.Class<P> type, java.lang.String name, AnnotationMetadata annotationMetadata, Argument[] typeArguments)Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Argument<P>asArgument()Represent the type as an argument, including any generic type information.booleanequals(java.lang.Object o)Pget(B bean)Read the bean value.AnnotationMetadatagetAnnotationMetadata()Supplies the metadata.BeanIntrospection<B>getDeclaringBean()java.lang.StringgetName()java.lang.Class<P>getType()PgetUnsafe(B bean)Unsafe version ofBeanProperty.get(Object).inthashCode()protected abstract PreadInternal(B bean)Reads the bean property.voidset(B bean, P value)Write the bean value.voidsetUnsafe(B bean, P value)Unsafe version ofBeanProperty.set(Object, Object).java.lang.StringtoString()BwithValue(B bean, P value)This method will attempt to modify the property or if this is a immutable type using a copy constructor to return a new instance with the new value.protected BwithValueInternal(B bean, P value)Mutates a property value.BwithValueUnsafe(B bean, P value)Unsafe version ofBeanProperty.withValue(Object, Object).protected abstract voidwriteInternal(B bean, P value)Writes a property value.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
-
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.beans.BeanProperty
convertAndSet, get, get, get, get, getDeclaringType, hasSetterOrConstructorArgument, isReadOnly, isReadWrite, isWriteOnly
-
-
-
-
Constructor Detail
-
AbstractBeanProperty
@Internal protected AbstractBeanProperty(@NonNull BeanIntrospection<B> introspection, @NonNull java.lang.Class<P> type, @NonNull java.lang.String name, @Nullable AnnotationMetadata annotationMetadata, @Nullable Argument[] typeArguments)
Default constructor.- Parameters:
introspection- The parent introspectiontype- The property typename- The property nameannotationMetadata- The annotation metadatatypeArguments- optional type arguments
-
-
Method Detail
-
getName
@NonNull public java.lang.String getName()
-
getType
@NonNull public java.lang.Class<P> getType()
- Specified by:
getTypein interfaceBeanProperty<B,P>- Returns:
- The property type.
-
asArgument
@NonNull public Argument<P> asArgument()
Description copied from interface:BeanPropertyRepresent the type as an argument, including any generic type information.- Specified by:
asArgumentin interfaceArgumentCoercible<B>- Specified by:
asArgumentin interfaceBeanProperty<B,P>- Returns:
- The argument
-
getDeclaringBean
@NonNull public final BeanIntrospection<B> getDeclaringBean()
- Specified by:
getDeclaringBeanin interfaceBeanProperty<B,P>- Returns:
- The declaring bean introspection.
-
getAnnotationMetadata
public AnnotationMetadata getAnnotationMetadata()
Description copied from interface:AnnotationMetadataProviderSupplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA.- Specified by:
getAnnotationMetadatain interfaceAnnotationMetadataProvider- Returns:
- The
AnnotationMetadata
-
get
@Nullable public final P get(@NonNull B bean)
Description copied from interface:BeanPropertyRead the bean value.- Specified by:
getin interfaceBeanProperty<B,P>- Parameters:
bean- The bean to read from- Returns:
- The value
-
getUnsafe
public final P getUnsafe(B bean)
Description copied from interface:UnsafeBeanPropertyUnsafe version ofBeanProperty.get(Object).- Specified by:
getUnsafein interfaceUnsafeBeanProperty<B,P>- Parameters:
bean- The bean to read from- Returns:
- The value
-
withValue
public B withValue(@NonNull B bean, @Nullable P value)
Description copied from interface:BeanPropertyThis method will attempt to modify the property or if this is a immutable type using a copy constructor to return a new instance with the new value.This differs from
BeanProperty.set(Object, Object)which will throw an exception if the property does not have a setter.- If the property is read-only but can be provided via constructor argument a new instance representing a copy of the bean is returned.
- If the property is mutable then the passed instance is returned and
BeanProperty.set(Object, Object)invoked to mutate the property - If there is no way for the property to be mutated then an
UnsupportedOperationExceptionis thrown
- Specified by:
withValuein interfaceBeanProperty<B,P>- Parameters:
bean- The beanvalue- The new value- Returns:
- Either the existing instance or the property is mutable or a newly created instance via the copy constructor pattern.
-
withValueUnsafe
public final B withValueUnsafe(B bean, P value)
Description copied from interface:UnsafeBeanPropertyUnsafe version ofBeanProperty.withValue(Object, Object).- Specified by:
withValueUnsafein interfaceUnsafeBeanProperty<B,P>- Parameters:
bean- The beanvalue- The new value- Returns:
- Either the existing instance or the property is mutable or a newly created instance via the copy constructor pattern.
-
set
public final void set(@NonNull B bean, @Nullable P value)
Description copied from interface:BeanPropertyWrite the bean value.- Specified by:
setin interfaceBeanProperty<B,P>- Parameters:
bean- The beanvalue- The value to write
-
setUnsafe
public final void setUnsafe(B bean, P value)
Description copied from interface:UnsafeBeanPropertyUnsafe version ofBeanProperty.set(Object, Object).- Specified by:
setUnsafein interfaceUnsafeBeanProperty<B,P>- Parameters:
bean- The beanvalue- The value to write
-
withValueInternal
@Internal protected B withValueInternal(B bean, P value)
Mutates a property value.- Parameters:
bean- The beanvalue- The value- Returns:
- Either a copy of the bean with the copy constructor invoked or the mutated instance if it mutable
- See Also:
BeanProperty.withValue(Object, Object)
-
writeInternal
@Internal protected abstract void writeInternal(@NonNull B bean, @Nullable P value)
Writes a property value.- Parameters:
bean- The beanvalue- The value
-
readInternal
@Internal protected abstract P readInternal(@NonNull B bean)
Reads the bean property.- Parameters:
bean- The bean- Returns:
- THe value
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-