Interface BeanElementBuilder

  • All Superinterfaces:
    io.micronaut.core.annotation.AnnotatedElement, io.micronaut.core.annotation.AnnotationMetadata, io.micronaut.core.annotation.AnnotationMetadataDelegate, io.micronaut.core.annotation.AnnotationMetadataProvider, io.micronaut.core.annotation.AnnotationSource, ConfigurableElement, io.micronaut.core.naming.Described, Element, io.micronaut.core.naming.Named
    All Known Implementing Classes:
    AbstractBeanDefinitionBuilder

    public interface BeanElementBuilder
    extends ConfigurableElement
    Interface for defining beans at compilation time from an originating element.
    Since:
    3.0.0
    • 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
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default <T extends java.lang.annotation.Annotation>
      BeanElementBuilder
      annotate​(java.lang.Class<T> annotationType)
      Annotate this element with the given annotation type.
      default <T extends java.lang.annotation.Annotation>
      BeanElementBuilder
      annotate​(java.lang.Class<T> annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
      Annotate this element with the given annotation type.
      default BeanElementBuilder annotate​(java.lang.String annotationType)
      Annotate this element with the given annotation type.
      default <T extends java.lang.annotation.Annotation>
      BeanElementBuilder
      annotate​(java.lang.String annotationType, java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
      Annotate this element with the given annotation type.
      BeanElementBuilder createWith​(MethodElement element)
      Specifies the bean will created with the given method element.
      ClassElement getBeanType()  
      default ClassElement getDeclaringElement()
      Returns the class that declares the bean.
      Element getOriginatingElement()  
      default Element getProducingElement()  
      BeanElementBuilder inject()
      Dependency inject this bean.
      default BeanElementBuilder intercept​(io.micronaut.core.annotation.AnnotationValue<?>... annotationValue)
      Intercept the bean.
      default <E extends MemberElement>
      BeanElementBuilder
      produceBeans​(ElementQuery<E> methodsOrFields)
      Produce additional beans from the given methods.
      <E extends MemberElement>
      BeanElementBuilder
      produceBeans​(ElementQuery<E> methodsOrFields, java.util.function.Consumer<BeanElementBuilder> childBeanBuilder)
      Produce additional beans from the given methods.
      default BeanElementBuilder qualifier​(io.micronaut.core.annotation.AnnotationValue<?> qualifier)
      Adds a qualifier for the given annotation value to the element.
      default BeanElementBuilder qualifier​(java.lang.String qualifier)
      Adds a Named qualifier to the element.
      default <T extends java.lang.annotation.Annotation>
      BeanElementBuilder
      removeAnnotation​(java.lang.Class<T> annotationType)  
      default BeanElementBuilder removeAnnotation​(java.lang.String annotationType)
      Removes an annotation of the given type from the element.
      default <T extends java.lang.annotation.Annotation>
      BeanElementBuilder
      removeAnnotationIf​(java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)
      Removes all annotations that pass the given predicate.
      default <T extends java.lang.annotation.Annotation>
      BeanElementBuilder
      removeStereotype​(java.lang.Class<T> annotationType)
      Removes a stereotype annotation of the given type from the element.
      default BeanElementBuilder removeStereotype​(java.lang.String annotationType)
      Removes a stereotype of the given name from the element.
      default BeanElementBuilder scope​(io.micronaut.core.annotation.AnnotationValue<?> scope)
      Adds a scope for the given annotation value to the bean.
      default BeanElementBuilder scope​(java.lang.String scope)
      Adds a scope for the given annotation value to the bean.
      BeanElementBuilder typeArguments​(ClassElement... types)
      Fills the type arguments for the bean with the given types.
      BeanElementBuilder typeArgumentsForType​(ClassElement type, ClassElement... types)
      Fills the type arguments for the given interface or super class with the given types.
      BeanElementBuilder typed​(ClassElement... types)
      Alters the exposed types for the bean limiting the exposed type to the given types.
      BeanElementBuilder withConstructor​(java.util.function.Consumer<BeanConstructorElement> constructorElement)
      Allows configuring the bean constructor.
      BeanElementBuilder withFields​(ElementQuery<FieldElement> fields, java.util.function.Consumer<BeanFieldElement> beanFields)
      Allows configuring fields of the bean.
      BeanElementBuilder withMethods​(ElementQuery<MethodElement> methods, java.util.function.Consumer<BeanMethodElement> beanMethods)
      Allows configuring methods of the bean.
      BeanElementBuilder withParameters​(java.util.function.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

        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.annotation.AnnotationMetadataProvider

        getAnnotationMetadata
    • Method Detail

      • intercept

        @NonNull
        default BeanElementBuilder intercept​(io.micronaut.core.annotation.AnnotationValue<?>... annotationValue)
        Intercept the bean.
        Parameters:
        annotationValue - The annotation to intercept
        Returns:
        This bean method
        Since:
        3.5.2
      • getOriginatingElement

        @NonNull
        Element getOriginatingElement()
        Returns:
        The originating element
      • getBeanType

        @NonNull
        ClassElement getBeanType()
        Returns:
        The bean type
      • getProducingElement

        @NonNull
        default Element getProducingElement()
        Returns:
        The element that produces the bean.
      • getDeclaringElement

        @NonNull
        default ClassElement 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

        @NonNull
        BeanElementBuilder createWith​(@NonNull
                                      MethodElement element)
        Specifies the bean will created with the given method element. If not specified the bean will be created with ClassElement.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

        @NonNull
        BeanElementBuilder typed​(ClassElement... types)
        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
      • typeArgumentsForType

        @NonNull
        BeanElementBuilder typeArgumentsForType​(@Nullable
                                                ClassElement type,
                                                @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-op
        types - The types
        Returns:
        This bean builder
      • scope

        @NonNull
        default BeanElementBuilder scope​(@NonNull
                                         io.micronaut.core.annotation.AnnotationValue<?> scope)
        Adds a scope for the given annotation value to the bean.
        Parameters:
        scope - The scope
        Returns:
        This bean element builder
      • scope

        @NonNull
        default BeanElementBuilder scope​(@NonNull
                                         java.lang.String 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
        BeanElementBuilder withConstructor​(@NonNull
                                           java.util.function.Consumer<BeanConstructorElement> constructorElement)
        Allows configuring the bean constructor.
        Parameters:
        constructorElement - The constructor element
        Returns:
        This bean builder
      • withParameters

        @NonNull
        BeanElementBuilder withParameters​(java.util.function.Consumer<BeanParameterElement[]> parameters)
        Allows configuring the parameters for the current constructor.
        Parameters:
        parameters - The parameters
        Returns:
        This builder
      • qualifier

        @NonNull
        default BeanElementBuilder qualifier​(@Nullable
                                             java.lang.String qualifier)
        Description copied from interface: ConfigurableElement
        Adds a Named qualifier to the element.
        Specified by:
        qualifier in interface ConfigurableElement
        Parameters:
        qualifier - The qualifier. If null an named annotation with no value is added assuming the default name.
        Returns:
        This element
      • qualifier

        @NonNull
        default BeanElementBuilder qualifier​(@NonNull
                                             io.micronaut.core.annotation.AnnotationValue<?> qualifier)
        Description copied from interface: ConfigurableElement
        Adds a qualifier for the given annotation value to the element.
        Specified by:
        qualifier in interface ConfigurableElement
        Parameters:
        qualifier - The qualifier
        Returns:
        This element
      • annotate

        @NonNull
        default <T extends java.lang.annotation.Annotation> BeanElementBuilder annotate​(@NonNull
                                                                                        java.lang.String annotationType,
                                                                                        @NonNull
                                                                                        java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
        Description copied from interface: Element
        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 interface Element
        Type Parameters:
        T - The annotation generic type
        Parameters:
        annotationType - The annotation type
        consumer - A function that receives the AnnotationValueBuilder
        Returns:
        This element
      • removeAnnotation

        default BeanElementBuilder removeAnnotation​(@NonNull
                                                    java.lang.String annotationType)
        Description copied from interface: Element
        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 interface Element
        Parameters:
        annotationType - The annotation type
        Returns:
        This element
      • removeAnnotation

        default <T extends java.lang.annotation.Annotation> BeanElementBuilder removeAnnotation​(@NonNull
                                                                                                java.lang.Class<T> annotationType)
        Specified by:
        removeAnnotation in interface Element
        Type Parameters:
        T - The annotation generic type
        Parameters:
        annotationType - The annotation type
        Returns:
        This element
        See Also:
        Element.removeAnnotation(String)
      • removeAnnotationIf

        default <T extends java.lang.annotation.Annotation> BeanElementBuilder removeAnnotationIf​(@NonNull
                                                                                                  java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)
        Description copied from interface: Element
        Removes all annotations that pass the given predicate.
        Specified by:
        removeAnnotationIf in interface Element
        Type Parameters:
        T - The annotation generic type
        Parameters:
        predicate - The predicate
        Returns:
        This element
      • removeStereotype

        default BeanElementBuilder removeStereotype​(@NonNull
                                                    java.lang.String annotationType)
        Description copied from interface: Element
        Removes a stereotype of the given name from the element.
        Specified by:
        removeStereotype in interface Element
        Parameters:
        annotationType - The annotation type
        Returns:
        This element
      • removeStereotype

        default <T extends java.lang.annotation.Annotation> BeanElementBuilder removeStereotype​(@NonNull
                                                                                                java.lang.Class<T> annotationType)
        Description copied from interface: Element
        Removes a stereotype annotation of the given type from the element.
        Specified by:
        removeStereotype in interface Element
        Type Parameters:
        T - The annotation generic type
        Parameters:
        annotationType - The annotation type
        Returns:
        This element
      • annotate

        @NonNull
        default BeanElementBuilder annotate​(@NonNull
                                            java.lang.String annotationType)
        Description copied from interface: Element
        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 interface Element
        Parameters:
        annotationType - The annotation type
        Returns:
        This element
      • annotate

        @NonNull
        default <T extends java.lang.annotation.Annotation> BeanElementBuilder annotate​(@NonNull
                                                                                        java.lang.Class<T> annotationType,
                                                                                        @NonNull
                                                                                        java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
        Description copied from interface: Element
        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 interface Element
        Type Parameters:
        T - The annotation generic type
        Parameters:
        annotationType - The annotation type
        consumer - A function that receives the AnnotationValueBuilder
        Returns:
        This element
      • annotate

        @NonNull
        default <T extends java.lang.annotation.Annotation> BeanElementBuilder annotate​(@NonNull
                                                                                        java.lang.Class<T> annotationType)
        Description copied from interface: Element
        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 interface 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 MemberElementBeanElementBuilder produceBeans​(ElementQuery<E> methodsOrFields,
                                                                  @Nullable
                                                                  java.util.function.Consumer<BeanElementBuilder> childBeanBuilder)
        Produce additional beans from the given methods.
        Type Parameters:
        E - A type variable to
        Parameters:
        methodsOrFields - The ElementQuery representing the methods or fields
        childBeanBuilder - Configure the child bean builder
        Returns:
        This bean builder
      • produceBeans

        default <E extends MemberElementBeanElementBuilder produceBeans​(ElementQuery<E> methodsOrFields)
        Produce additional beans from the given methods.
        Type Parameters:
        E - A type variable to
        Parameters:
        methodsOrFields - The ElementQuery representing the methods or fields
        Returns:
        This bean builder