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_MEMBERFields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTYFields inherited from interface io.micronaut.inject.ast.Element
EMPTY_ELEMENT_ARRAYFields 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 BeanElementBuilderAnnotate 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 be created with the given method element.default @NonNull ClassElementReturns the class that declares the bean.inject()Dependency inject this bean.default @NonNull BeanElementBuilderintercept(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 BeanElementBuilderqualifier(@NonNull AnnotationValue<?> qualifier) Adds a qualifier for the given annotation value to the element.default @NonNull BeanElementBuilderAdds aNamedqualifier to the element.default <T extends Annotation>
BeanElementBuilderremoveAnnotation(@NonNull Class<T> annotationType) default BeanElementBuilderremoveAnnotation(@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 BeanElementBuilderremoveStereotype(@NonNull String annotationType) Removes a stereotype of the given name from the element.default @NonNull BeanElementBuilderscope(@NonNull AnnotationValue<?> scope) Adds a scope for the given annotation value to the bean.default @NonNull BeanElementBuilderAdds 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, isNullableMethods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods 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, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider
getAnnotationMetadataMethods 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 be 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:
typeArgumentsin 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- TheElementQueryto 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- TheElementQueryto 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:ConfigurableElementAdds aNamedqualifier to the element.- Specified by:
qualifierin interfaceConfigurableElement- Parameters:
qualifier- The qualifier. Ifnulla 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:ConfigurableElementAdds a qualifier for the given annotation value to the element.- Specified by:
qualifierin 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:MutableAnnotationMetadataDelegateAnnotate 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:
annotatein interfaceElement- Specified by:
annotatein 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:MutableAnnotationMetadataDelegateRemoves 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:
removeAnnotationin interfaceElement- Specified by:
removeAnnotationin interfaceMutableAnnotationMetadataDelegate<Element>- Parameters:
annotationType- The annotation type- Returns:
- This element
-
removeAnnotation
default <T extends Annotation> BeanElementBuilder removeAnnotation(@NonNull @NonNull Class<T> annotationType) - Specified by:
removeAnnotationin interfaceElement- Specified by:
removeAnnotationin 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:MutableAnnotationMetadataDelegateRemoves all annotations that pass the given predicate.- Specified by:
removeAnnotationIfin interfaceElement- Specified by:
removeAnnotationIfin interfaceMutableAnnotationMetadataDelegate<Element>- Type Parameters:
T- The annotation generic type- Parameters:
predicate- The predicate- Returns:
- This element
-
removeStereotype
Description copied from interface:MutableAnnotationMetadataDelegateRemoves a stereotype of the given name from the element.- Specified by:
removeStereotypein interfaceElement- Specified by:
removeStereotypein 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:MutableAnnotationMetadataDelegateRemoves a stereotype annotation of the given type from the element.- Specified by:
removeStereotypein interfaceElement- Specified by:
removeStereotypein interfaceMutableAnnotationMetadataDelegate<Element>- Type Parameters:
T- The annotation generic type- Parameters:
annotationType- The annotation type- Returns:
- This element
-
annotate
Description copied from interface:MutableAnnotationMetadataDelegateAnnotate 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:
annotatein interfaceElement- Specified by:
annotatein 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:MutableAnnotationMetadataDelegateAnnotate 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:
annotatein interfaceElement- Specified by:
annotatein 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:MutableAnnotationMetadataDelegateAnnotate 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:
annotatein interfaceElement- Specified by:
annotatein 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- TheElementQueryrepresenting 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- TheElementQueryrepresenting the methods or fields- Returns:
- This bean builder
-