Class ReflectionBeanIntrospection<T>
- Type Parameters:
T- The bean type
- All Implemented Interfaces:
AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, BeanInfo<T>, BeanIntrospection<T>, Ordered, ArgumentCoercible<T>, ReflectiveIntrospection<T>
BeanIntrospection over a Class, with the properties, the constructor and the methods a
generated introspection would have.
A property is a getter or a setter of the type or of its super classes - named by the prefixes
AccessorsStyle declares, get, is and set by
default - merged by name, with the field of that name as a member of it: it is read through the getter when
there is one and through the field otherwise, written through the setter when there is one and through a
non-final field otherwise, and its metadata holds the annotations of all three together with the type-use
annotations of the property type. Only an accessor the visibility of the type admits makes a property - by
default one the type reaches without reflection: a public one, or a non-private one declared in its own
package - and a field alone makes one only when field access is asked for - Introspected.accessKind()
on the type, or the access kinds given to of(Class, Set) - which is what the processors admit. The
value goes through the members the access kinds admit: an accessor under method access, the field under
field access, and a getter beside a private setter or a field no access kind admits makes a read-only
property. The accessor of a record component always makes a property, and so does a member
annotated Introspected.Property, under the name of the method when the method carries no prefix,
read and written as its access kinds allow. A bean method is a public instance method of the type, of its
super classes or of its interfaces, Object excluded. The constructor is the static factory
annotated Creator when the type declares one, else the constructor annotated Creator, else
the only public one, else the public one with no parameter, else the declared one with the most
parameters; a type naming a builder in Introspected.builder() is built through that builder.
The type of a property, of a method argument and of a return type is the type the bean type sees:
T declared by a Box<T> and read through a StringBox extends Box<String> is
String, not the bound of the variable.
- Since:
- 5.2.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested classes/interfaces inherited from interface BeanIntrospection
BeanIntrospection.Builder<T>Nested classes/interfaces inherited from interface ReflectiveIntrospection
ReflectiveIntrospection.ReflectivePropertyMember<B> -
Field Summary
Fields inherited from interface AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface AnnotationSource
EMPTYFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptionbuilder()findDeclaredMethod(String name, Class<?>... parameterTypes) Finds the method the introspected type itself declares, with the annotations of that declaration only: the generated metadata of a method merges the annotations of the methods it overrides.Supplies the metadata.Returns theBeanMethodinstances for this introspection.The properties a value can be read from: every property but a write only one.The bean type.The properties a value can be written to: every property but a read only one.Argument<?>[]The constructor arguments needed to instantiate the bean.Every constructor of the type, the selected one first, the others by arity and then by parameter types.getIndexedProperties(Class<? extends Annotation> annotationType) The properties carrying an annotation, out of the indexIntrospected.indexed()asks for.getIndexedProperty(Class<? extends Annotation> annotationType, String annotationValue) The property whose annotation carries a value, out of the indexIntrospected.indexed()asks for.getProperty(String name) The property of a name, from the properties indexed by name rather than by walking them: a caller reading a bean asks for a property per value it reads.booleanWhetherIntrospected.builder()configures a builder type, whichbuilder()then builds through, as a generated introspection does.Instantiates an instance of the bean, throwing an exception is instantiation is not possible.instantiate(boolean strictNullable, @Nullable Object... arguments) Instantiates an instance of the bean, throwing an exception is instantiation is not possible.booleanCan the introspection be constructed withBeanIntrospection.builder().static booleanisIntrospectable(Class<?> type) Whether a type can be described reflectively.static <T> ReflectionBeanIntrospection<T> Introspects a type through its accessors, which is what a generated introspection describes by default: a field of the type is a member of the property of its name, it does not make one of its own unless the type carriesIntrospected.accessKind()asking for field access.static <T> ReflectionBeanIntrospection<T> of(Class<T> beanType, AnnotationMetadata additionalAnnotationMetadata) The reflective introspection of a type, carrying annotations the caller means it to have beyond the ones the class declares.static <T> ReflectionBeanIntrospection<T> of(Class<T> beanType, AnnotationMetadata additionalAnnotationMetadata, Set<Introspected.AccessKind> accessKinds) The reflective introspection of a type described through the access kinds the caller asks for, carrying annotations the caller means it to have beyond the ones the class declares.static <T> ReflectionBeanIntrospection<T> of(Class<T> beanType, Set<Introspected.AccessKind> accessKinds) The reflective introspection of a type described through the access kinds the caller asks for, rather than through the onesIntrospected.accessKind()declares.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods inherited from interface AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, 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, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasEvaluatedExpressions, 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, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface BeanInfo
asArgument, getGenericBeanType, getOrderMethods inherited from interface BeanIntrospection
getIndexedProperty, getProperty, getPropertyNames, getReadProperty, getReadProperty, getReadPropertyNames, getRequiredProperty, getRequiredReadProperty, getRequiredWriteProperty, getTypeArguments, getTypeArguments, getTypeArguments, getWriteProperty, getWriteProperty, instantiate, propertyIndexOfMethods inherited from interface ReflectiveIntrospection
separatesDeclarations
-
Method Details
-
of
Introspects a type through its accessors, which is what a generated introspection describes by default: a field of the type is a member of the property of its name, it does not make one of its own unless the type carriesIntrospected.accessKind()asking for field access.- Type Parameters:
T- The type- Parameters:
beanType- The type- Returns:
- The introspection
- Throws:
IllegalArgumentException- When the type cannot be introspected, seeisIntrospectable(Class)
-
of
public static <T> ReflectionBeanIntrospection<T> of(Class<T> beanType, AnnotationMetadata additionalAnnotationMetadata) The reflective introspection of a type, carrying annotations the caller means it to have beyond the ones the class declares.A specification that reads a type it was told to handle - serialization asked to read a class that was never annotated - decides that itself, and the code downstream asks the introspection for the annotation rather than being told separately.
- Type Parameters:
T- The bean type- Parameters:
beanType- The bean typeadditionalAnnotationMetadata- The annotations to carry beyond the ones of the class- Returns:
- The introspection, describing the type through its accessors unless the annotations ask for field access
- Throws:
IllegalArgumentException- When the type cannot be described reflectively
-
of
public static <T> ReflectionBeanIntrospection<T> of(Class<T> beanType, Set<Introspected.AccessKind> accessKinds) The reflective introspection of a type described through the access kinds the caller asks for, rather than through the onesIntrospected.accessKind()declares.A reflective introspection exists for the types the processors never saw, which carry no annotation to read the kinds from: a caller that means the fields of such a type to be properties - a mapping layer over a class of plain fields - says so here. The members of the kinds asked for are taken whatever their visibility, a private field included: reflection reaches them, and asking for field access is asking for exactly that.
- Type Parameters:
T- The bean type- Parameters:
beanType- The bean typeaccessKinds- The kinds of member that make a property, empty forIntrospected.AccessKind.METHODalone- Returns:
- The introspection
- Throws:
IllegalArgumentException- When the type cannot be described reflectively
-
of
public static <T> ReflectionBeanIntrospection<T> of(Class<T> beanType, AnnotationMetadata additionalAnnotationMetadata, Set<Introspected.AccessKind> accessKinds) The reflective introspection of a type described through the access kinds the caller asks for, carrying annotations the caller means it to have beyond the ones the class declares.- Type Parameters:
T- The bean type- Parameters:
beanType- The bean typeadditionalAnnotationMetadata- The annotations to carry beyond the ones of the classaccessKinds- The kinds of member that make a property, empty forIntrospected.AccessKind.METHODalone- Returns:
- The introspection
- Throws:
IllegalArgumentException- When the type cannot be described reflectively- See Also:
-
isIntrospectable
Whether a type can be described reflectively.- Parameters:
type- The type- Returns:
- Whether the type is a class, an interface or a
Proxyof an introspectable interface a reflective introspection can describe: not a primitive, an array, an annotation, an enum or a type of the JDK
-
getBeanType
Description copied from interface:BeanIntrospectionThe bean type.- Specified by:
getBeanTypein interfaceBeanInfo<T>- Specified by:
getBeanTypein interfaceBeanIntrospection<T>- Returns:
- The bean type
-
getAnnotationMetadata
Description copied from interface:AnnotationMetadataProviderSupplies the metadata. Defaults toAnnotationMetadata.EMPTY_METADATA.- Specified by:
getAnnotationMetadatain interfaceAnnotationMetadataProvider- Returns:
- The
AnnotationMetadata
-
getBeanProperties
- Specified by:
getBeanPropertiesin interfaceBeanIntrospection<T>- Returns:
- An immutable collection of properties.
-
getProperty
The property of a name, from the properties indexed by name rather than by walking them: a caller reading a bean asks for a property per value it reads.- Specified by:
getPropertyin interfaceBeanIntrospection<T>- Parameters:
name- The property name- Returns:
- The property, empty when the type has none of that name
-
getBeanReadProperties
The properties a value can be read from: every property but a write only one. A generated introspection keeps this view apart fromgetBeanProperties(), and the code reading a bean - serialization among it - asks for this one.- Specified by:
getBeanReadPropertiesin interfaceBeanIntrospection<T>- Returns:
- The read properties
-
getBeanWriteProperties
The properties a value can be written to: every property but a read only one.- Specified by:
getBeanWritePropertiesin interfaceBeanIntrospection<T>- Returns:
- The write properties
-
getBeanMethods
Description copied from interface:BeanIntrospectionReturns theBeanMethodinstances for this introspection.The
BeanMethodinstances are only those methods annotated withio.micronaut.context.annotation.Executableand hence represent a subset of the actual methods of the class and do not include any methods that are exposed asBeanPropertyinstances.- Specified by:
getBeanMethodsin interfaceBeanIntrospection<T>- Returns:
- An immutable collection of methods.
-
findDeclaredMethod
Description copied from interface:ReflectiveIntrospectionFinds the method the introspected type itself declares, with the annotations of that declaration only: the generated metadata of a method merges the annotations of the methods it overrides.- Specified by:
findDeclaredMethodin interfaceReflectiveIntrospection<T>- Parameters:
name- The method nameparameterTypes- The parameter types- Returns:
- The method declared by the type, empty when the type inherits it
-
getConstructorArguments
Description copied from interface:BeanIntrospectionThe constructor arguments needed to instantiate the bean.- Specified by:
getConstructorArgumentsin interfaceBeanIntrospection<T>- Returns:
- An argument array
-
getConstructor
- Specified by:
getConstructorin interfaceBeanIntrospection<T>- Returns:
- The bean constructor.
-
getConstructors
Every constructor of the type, the selected one first, the others by arity and then by parameter types. An introspection describes one constructor; a specification that names constructors by their parameter types needs the others too.- Specified by:
getConstructorsin interfaceBeanIntrospection<T>- Specified by:
getConstructorsin interfaceReflectiveIntrospection<T>- Returns:
- The constructors
-
getIndexedProperties
public Collection<BeanProperty<T,Object>> getIndexedProperties(Class<? extends Annotation> annotationType) The properties carrying an annotation, out of the indexIntrospected.indexed()asks for. The processor builds an index for the annotations named there and for no other, so an annotation the type does not index finds nothing here either, as it finds nothing in a generated introspection.- Specified by:
getIndexedPropertiesin interfaceBeanIntrospection<T>- Parameters:
annotationType- The annotation type- Returns:
- An immutable collection of properties.
- See Also:
-
getIndexedProperty
public Optional<BeanProperty<T,Object>> getIndexedProperty(Class<? extends Annotation> annotationType, String annotationValue) The property whose annotation carries a value, out of the indexIntrospected.indexed()asks for. The member read is the oneIntrospected.IndexedAnnotation.member()names: an entry naming none is an index by annotation alone, which no value matches.- Specified by:
getIndexedPropertyin interfaceBeanIntrospection<T>- Parameters:
annotationType- The annotation typeannotationValue- The annotation value- Returns:
- An immutable collection of properties.
- See Also:
-
instantiate
Description copied from interface:BeanIntrospectionInstantiates an instance of the bean, throwing an exception is instantiation is not possible.- Specified by:
instantiatein interfaceBeanIntrospection<T>- Returns:
- An instance
- Throws:
InstantiationException- If the bean cannot be instantiated or the arguments are not satisfied.
-
instantiate
public T instantiate(boolean strictNullable, @Nullable Object... arguments) throws InstantiationException Description copied from interface:BeanIntrospectionInstantiates an instance of the bean, throwing an exception is instantiation is not possible.- Specified by:
instantiatein interfaceBeanIntrospection<T>- 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 byBeanIntrospection.getConstructorArguments()- Returns:
- An instance
- Throws:
InstantiationException- If the bean cannot be instantiated.
-
isBuildable
public boolean isBuildable()Description copied from interface:BeanIntrospectionCan the introspection be constructed withBeanIntrospection.builder().- Specified by:
isBuildablein interfaceBeanIntrospection<T>- Returns:
- True if it can
-
hasBuilder
public boolean hasBuilder()WhetherIntrospected.builder()configures a builder type, whichbuilder()then builds through, as a generated introspection does.- Specified by:
hasBuilderin interfaceBeanIntrospection<T>- Returns:
- True if a backing builder is present.
-
builder
- Specified by:
builderin interfaceBeanIntrospection<T>- Returns:
- Obtain a builder for this introspection.
-
toString
-