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 protected
AbstractBeanProperty(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.boolean
equals(java.lang.Object o)
P
get(B bean)
Read the bean value.AnnotationMetadata
getAnnotationMetadata()
Supplies the metadata.BeanIntrospection<B>
getDeclaringBean()
java.lang.String
getName()
java.lang.Class<P>
getType()
P
getUnsafe(B bean)
Unsafe version ofBeanProperty.get(Object)
.int
hashCode()
protected abstract P
readInternal(B bean)
Reads the bean property.void
set(B bean, P value)
Write the bean value.void
setUnsafe(B bean, P value)
Unsafe version ofBeanProperty.set(Object, Object)
.java.lang.String
toString()
B
withValue(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 B
withValueInternal(B bean, P value)
Mutates a property value.B
withValueUnsafe(B bean, P value)
Unsafe version ofBeanProperty.withValue(Object, Object)
.protected abstract void
writeInternal(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:
getType
in interfaceBeanProperty<B,P>
- Returns:
- The property type.
-
asArgument
@NonNull public Argument<P> asArgument()
Description copied from interface:BeanProperty
Represent the type as an argument, including any generic type information.- Specified by:
asArgument
in interfaceArgumentCoercible<B>
- Specified by:
asArgument
in interfaceBeanProperty<B,P>
- Returns:
- The argument
-
getDeclaringBean
@NonNull public final BeanIntrospection<B> getDeclaringBean()
- Specified by:
getDeclaringBean
in interfaceBeanProperty<B,P>
- Returns:
- The declaring bean introspection.
-
getAnnotationMetadata
public AnnotationMetadata getAnnotationMetadata()
Description copied from interface:AnnotationMetadataProvider
Supplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA
.- Specified by:
getAnnotationMetadata
in interfaceAnnotationMetadataProvider
- Returns:
- The
AnnotationMetadata
-
get
@Nullable public final P get(@NonNull B bean)
Description copied from interface:BeanProperty
Read the bean value.- Specified by:
get
in interfaceBeanProperty<B,P>
- Parameters:
bean
- The bean to read from- Returns:
- The value
-
getUnsafe
public final P getUnsafe(B bean)
Description copied from interface:UnsafeBeanProperty
Unsafe version ofBeanProperty.get(Object)
.- Specified by:
getUnsafe
in 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:BeanProperty
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.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
UnsupportedOperationException
is thrown
- Specified by:
withValue
in 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:UnsafeBeanProperty
Unsafe version ofBeanProperty.withValue(Object, Object)
.- Specified by:
withValueUnsafe
in 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:BeanProperty
Write the bean value.- Specified by:
set
in interfaceBeanProperty<B,P>
- Parameters:
bean
- The beanvalue
- The value to write
-
setUnsafe
public final void setUnsafe(B bean, P value)
Description copied from interface:UnsafeBeanProperty
Unsafe version ofBeanProperty.set(Object, Object)
.- Specified by:
setUnsafe
in 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:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-