Package io.micronaut.inject.ast.beans
Interface BeanElementBuilder
- All Superinterfaces:
AnnotatedElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,AnnotationSource
,ConfigurableElement
,Described
,Element
,MutableAnnotationMetadataDelegate<Element>
,Named
- All Known Implementing Classes:
AbstractBeanDefinitionBuilder
Interface for defining beans at compilation time from an originating element.
- Since:
- 3.0.0
- Author:
- graemerocher
-
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
Fields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAY
Fields inherited from interface io.micronaut.inject.ast.annotation.MutableAnnotationMetadataDelegate
EMPTY
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T extends Annotation>
@NonNull BeanElementBuilderAnnotate this element with the given annotation type.default <T extends Annotation>
@NonNull BeanElementBuilderAnnotate this element with the given annotation type.default @NonNull BeanElementBuilder
Annotate this element with the given annotation type.default <T extends Annotation>
@NonNull BeanElementBuilderAnnotate this element with the given annotation type.createWith
(@NonNull MethodElement element) Specifies the bean will created with the given method element.default @NonNull ClassElement
Returns the class that declares the bean.inject()
Dependency inject this bean.default @NonNull BeanElementBuilder
intercept
(AnnotationValue<?>... annotationValue) Intercept the bean.default <E extends MemberElement>
BeanElementBuilderproduceBeans
(ElementQuery<E> methodsOrFields) Produce additional beans from the given methods.<E extends MemberElement>
BeanElementBuilderproduceBeans
(ElementQuery<E> methodsOrFields, @Nullable Consumer<BeanElementBuilder> childBeanBuilder) Produce additional beans from the given methods.default @NonNull BeanElementBuilder
qualifier
(@NonNull AnnotationValue<?> qualifier) Adds a qualifier for the given annotation value to the element.default @NonNull BeanElementBuilder
Adds aNamed
qualifier to the element.default <T extends Annotation>
BeanElementBuilderremoveAnnotation
(@NonNull Class<T> annotationType) default BeanElementBuilder
removeAnnotation
(@NonNull String annotationType) Removes an annotation of the given type from the element.default <T extends Annotation>
BeanElementBuilderremoveAnnotationIf
(@NonNull Predicate<AnnotationValue<T>> predicate) Removes all annotations that pass the given predicate.default <T extends Annotation>
BeanElementBuilderremoveStereotype
(@NonNull Class<T> annotationType) Removes a stereotype annotation of the given type from the element.default BeanElementBuilder
removeStereotype
(@NonNull String annotationType) Removes a stereotype of the given name from the element.default @NonNull BeanElementBuilder
scope
(@NonNull AnnotationValue<?> scope) Adds a scope for the given annotation value to the bean.default @NonNull BeanElementBuilder
Adds a scope for the given annotation value to the bean.typeArguments
(@NonNull ClassElement... types) Fills the type arguments for the bean with the given types.typeArgumentsForType
(@Nullable ClassElement type, @NonNull ClassElement... types) Fills the type arguments for the given interface or super class with the given types.typed
(ClassElement... types) Alters the exposed types for the bean limiting the exposed type to the given types.withConstructor
(@NonNull Consumer<BeanConstructorElement> constructorElement) Allows configuring the bean constructor.withFields
(@NonNull ElementQuery<FieldElement> fields, @NonNull Consumer<BeanFieldElement> beanFields) Allows configuring fields of the bean.withMethods
(@NonNull ElementQuery<MethodElement> methods, @NonNull Consumer<BeanMethodElement> beanMethods) Allows configuring methods of the bean.withParameters
(Consumer<BeanParameterElement[]> parameters) Allows configuring the parameters for the current constructor.Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresent
Methods inherited from interface io.micronaut.core.annotation.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, 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.annotation.AnnotationMetadataProvider
getAnnotationMetadata
Methods inherited from interface io.micronaut.inject.ast.Element
annotate, getDescription, getDescription, getDocumentation, getModifiers, getName, getNativeType, getSimpleName, isAbstract, isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, isSynthetic, withAnnotationMetadata
-
Method Details
-
intercept
Intercept the bean.- Parameters:
annotationValue
- The annotation to intercept- Returns:
- This bean method
- Since:
- 3.5.2
-
getOriginatingElement
- Returns:
- The originating element
-
getBeanType
- Returns:
- The bean type
-
getProducingElement
- Returns:
- The element that produces the bean.
-
getDeclaringElement
Returns the class that declares the bean. In case of a bean defined by a class, that is the bean class directly. In case of a producer method or field, that is the class that declares the producer method or field.- Returns:
- The element declares the bean.
-
createWith
Specifies the bean will created with the given method element. If not specified the bean will be created withClassElement.getPrimaryConstructor()
.Note that the method can be a one of the following:
- An accessible constructor on the bean type being generated
- An accessible static method on the bean type being generated
- Parameters:
element
- The element- Returns:
- This bean builder
-
typed
Alters the exposed types for the bean limiting the exposed type to the given types.- Parameters:
types
- 1 or more types to expose- Returns:
- This builder
-
typeArguments
Fills the type arguments for the bean with the given types.- Specified by:
typeArguments
in interfaceConfigurableElement
- Parameters:
types
- The types- Returns:
- This bean builder
-
typeArgumentsForType
@NonNull @NonNull BeanElementBuilder typeArgumentsForType(@Nullable @Nullable ClassElement type, @NonNull @NonNull ClassElement... types) Fills the type arguments for the given interface or super class with the given types.- Parameters:
type
- The type or interface. If null, results in a no-optypes
- The types- Returns:
- This bean builder
-
scope
Adds a scope for the given annotation value to the bean.- Parameters:
scope
- The scope- Returns:
- This bean element builder
-
scope
Adds a scope for the given annotation value to the bean.- Parameters:
scope
- The full qualified scope annotation name- Returns:
- This bean element builder
-
withConstructor
@NonNull @NonNull BeanElementBuilder withConstructor(@NonNull @NonNull Consumer<BeanConstructorElement> constructorElement) Allows configuring the bean constructor.- Parameters:
constructorElement
- The constructor element- Returns:
- This bean builder
-
withMethods
@NonNull @NonNull BeanElementBuilder withMethods(@NonNull @NonNull ElementQuery<MethodElement> methods, @NonNull @NonNull Consumer<BeanMethodElement> beanMethods) Allows configuring methods of the bean.- Parameters:
methods
- TheElementQuery
to locate selected methods.beanMethods
- A consumer that receives eachBeanMethodElement
- Returns:
- This builder
-
withFields
@NonNull @NonNull BeanElementBuilder withFields(@NonNull @NonNull ElementQuery<FieldElement> fields, @NonNull @NonNull Consumer<BeanFieldElement> beanFields) Allows configuring fields of the bean.- Parameters:
fields
- TheElementQuery
to locate fields.beanFields
- The bean fields- Returns:
- This builder
-
withParameters
Allows configuring the parameters for the current constructor.- Parameters:
parameters
- The parameters- Returns:
- This builder
-
qualifier
Description copied from interface:ConfigurableElement
Adds aNamed
qualifier to the element.- Specified by:
qualifier
in interfaceConfigurableElement
- Parameters:
qualifier
- The qualifier. Ifnull
an named annotation with no value is added assuming the default name.- Returns:
- This element
-
qualifier
@NonNull default @NonNull BeanElementBuilder qualifier(@NonNull @NonNull AnnotationValue<?> qualifier) Description copied from interface:ConfigurableElement
Adds a qualifier for the given annotation value to the element.- Specified by:
qualifier
in interfaceConfigurableElement
- Parameters:
qualifier
- The qualifier- Returns:
- This element
-
annotate
@NonNull default <T extends Annotation> @NonNull BeanElementBuilder annotate(@NonNull @NonNull String annotationType, @NonNull @NonNull Consumer<AnnotationValueBuilder<T>> consumer) Description copied from interface:MutableAnnotationMetadataDelegate
Annotate this element with the given annotation type. If the annotation is already present then any values populated by the builder will be merged/overridden with the existing values.- Specified by:
annotate
in interfaceElement
- Specified by:
annotate
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationType
- The annotation typeconsumer
- A function that receives theAnnotationValueBuilder
- Returns:
- This element
-
removeAnnotation
Description copied from interface:MutableAnnotationMetadataDelegate
Removes an annotation of the given type from the element.If the annotation features any stereotypes these will also be removed unless there are other annotations that reference the stereotype to be removed.
In the case of repeatable annotations this method will remove all repeated annotations, effectively clearing out all declared repeated annotations of the given type.
- Specified by:
removeAnnotation
in interfaceElement
- Specified by:
removeAnnotation
in interfaceMutableAnnotationMetadataDelegate<Element>
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
removeAnnotation
default <T extends Annotation> BeanElementBuilder removeAnnotation(@NonNull @NonNull Class<T> annotationType) - Specified by:
removeAnnotation
in interfaceElement
- Specified by:
removeAnnotation
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationType
- The annotation type- Returns:
- This element
- See Also:
-
removeAnnotationIf
default <T extends Annotation> BeanElementBuilder removeAnnotationIf(@NonNull @NonNull Predicate<AnnotationValue<T>> predicate) Description copied from interface:MutableAnnotationMetadataDelegate
Removes all annotations that pass the given predicate.- Specified by:
removeAnnotationIf
in interfaceElement
- Specified by:
removeAnnotationIf
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
predicate
- The predicate- Returns:
- This element
-
removeStereotype
Description copied from interface:MutableAnnotationMetadataDelegate
Removes a stereotype of the given name from the element.- Specified by:
removeStereotype
in interfaceElement
- Specified by:
removeStereotype
in interfaceMutableAnnotationMetadataDelegate<Element>
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
removeStereotype
default <T extends Annotation> BeanElementBuilder removeStereotype(@NonNull @NonNull Class<T> annotationType) Description copied from interface:MutableAnnotationMetadataDelegate
Removes a stereotype annotation of the given type from the element.- Specified by:
removeStereotype
in interfaceElement
- Specified by:
removeStereotype
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
annotate
Description copied from interface:MutableAnnotationMetadataDelegate
Annotate this element with the given annotation type. If the annotation is already present then any values populated by the builder will be merged/overridden with the existing values.- Specified by:
annotate
in interfaceElement
- Specified by:
annotate
in interfaceMutableAnnotationMetadataDelegate<Element>
- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
annotate
@NonNull default <T extends Annotation> @NonNull BeanElementBuilder annotate(@NonNull @NonNull Class<T> annotationType, @NonNull @NonNull Consumer<AnnotationValueBuilder<T>> consumer) Description copied from interface:MutableAnnotationMetadataDelegate
Annotate this element with the given annotation type. If the annotation is already present then any values populated by the builder will be merged/overridden with the existing values.- Specified by:
annotate
in interfaceElement
- Specified by:
annotate
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationType
- The annotation typeconsumer
- A function that receives theAnnotationValueBuilder
- Returns:
- This element
-
annotate
@NonNull default <T extends Annotation> @NonNull BeanElementBuilder annotate(@NonNull @NonNull Class<T> annotationType) Description copied from interface:MutableAnnotationMetadataDelegate
Annotate this element with the given annotation type. If the annotation is already present then any values populated by the builder will be merged/overridden with the existing values.- Specified by:
annotate
in interfaceElement
- Specified by:
annotate
in interfaceMutableAnnotationMetadataDelegate<Element>
- Type Parameters:
T
- The annotation generic type- Parameters:
annotationType
- The annotation type- Returns:
- This element
-
inject
BeanElementBuilder inject()Dependency inject this bean.- Returns:
- this bean builder
-
produceBeans
<E extends MemberElement> BeanElementBuilder produceBeans(ElementQuery<E> methodsOrFields, @Nullable @Nullable Consumer<BeanElementBuilder> childBeanBuilder) Produce additional beans from the given methods.- Type Parameters:
E
- A type variable to- Parameters:
methodsOrFields
- TheElementQuery
representing the methods or fieldschildBeanBuilder
- Configure the child bean builder- Returns:
- This bean builder
-
produceBeans
Produce additional beans from the given methods.- Type Parameters:
E
- A type variable to- Parameters:
methodsOrFields
- TheElementQuery
representing the methods or fields- Returns:
- This bean builder
-