Class AbstractBeanDefinitionBuilder

  • All Implemented Interfaces:
    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, io.micronaut.core.naming.Described, io.micronaut.core.naming.Named, BeanElementBuilder, ConfigurableElement, Element

    @Internal
    public abstract class AbstractBeanDefinitionBuilder
    extends java.lang.Object
    implements BeanElementBuilder
    Abstract implementation of the BeanElementBuilder interface that should be implemented by downstream language specific implementations.
    Since:
    3.0.0
    • Constructor Detail

      • AbstractBeanDefinitionBuilder

        protected AbstractBeanDefinitionBuilder​(Element originatingElement,
                                                ClassElement beanType,
                                                ConfigurationMetadataBuilder<?> metadataBuilder,
                                                VisitorContext visitorContext)
        Default constructor.
        Parameters:
        originatingElement - The originating element
        beanType - The bean type
        metadataBuilder - the metadata builder
        visitorContext - the visitor context
    • Method Detail

      • intercept

        public BeanElementBuilder intercept​(io.micronaut.core.annotation.AnnotationValue<?>... annotationValue)
        Description copied from interface: BeanElementBuilder
        Intercept the bean.
        Specified by:
        intercept in interface BeanElementBuilder
        Parameters:
        annotationValue - The annotation to intercept
        Returns:
        This bean method
      • writeBeanDefinitionBuilders

        @Internal
        public static void writeBeanDefinitionBuilders​(ClassWriterOutputVisitor classWriterOutputVisitor,
                                                       java.util.List<AbstractBeanDefinitionBuilder> beanDefinitionBuilders)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • isIntercepted

        protected boolean isIntercepted()
        Is the bean to be built intercepted?
        Returns:
        True if it is
      • initBeanParameters

        protected final BeanParameterElement[] initBeanParameters​(@NonNull
                                                                  ParameterElement[] constructorParameters)
        Initialize the bean parameters.
        Parameters:
        constructorParameters - The parameters to use.
        Returns:
        The initialized parameters
      • getAnnotationMetadata

        @NonNull
        public io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
        Specified by:
        getAnnotationMetadata in interface io.micronaut.core.annotation.AnnotationMetadataProvider
      • createWith

        @NonNull
        public BeanElementBuilder createWith​(@NonNull
                                             MethodElement element)
        Description copied from interface: BeanElementBuilder
        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
        Specified by:
        createWith in interface BeanElementBuilder
        Parameters:
        element - The element
        Returns:
        This bean builder
      • getParameters

        @NonNull
        protected BeanParameterElement[] getParameters()
        Returns:
        The bean creation parameters.
      • getName

        @NonNull
        public java.lang.String getName()
        Specified by:
        getName in interface Element
        Specified by:
        getName in interface io.micronaut.core.naming.Named
        Returns:
        The name of the element. For a type this represents the binary name.
      • isProtected

        public boolean isProtected()
        Specified by:
        isProtected in interface Element
        Returns:
        True if the element is protected.
      • isPublic

        public boolean isPublic()
        Specified by:
        isPublic in interface Element
        Returns:
        True if the element is public.
      • getNativeType

        @NonNull
        public java.lang.Object getNativeType()
        Description copied from interface: Element
        Returns the native underlying type. This API is extended by all of the inject language implementations. The object returned by this method will be the language native type the information is being retrieved from.
        Specified by:
        getNativeType in interface Element
        Returns:
        The native type
      • annotate

        @NonNull
        public <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 BeanElementBuilder
        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

        public <T extends java.lang.annotation.Annotation> Element annotate​(io.micronaut.core.annotation.AnnotationValue<T> annotationValue)
        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:
        annotationValue - The annotation type
        Returns:
        This element
      • removeAnnotation

        public 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 BeanElementBuilder
        Specified by:
        removeAnnotation in interface Element
        Parameters:
        annotationType - The annotation type
        Returns:
        This element
      • removeAnnotationIf

        public <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 BeanElementBuilder
        Specified by:
        removeAnnotationIf in interface Element
        Type Parameters:
        T - The annotation generic type
        Parameters:
        predicate - The predicate
        Returns:
        This element
      • createChildBean

        @NonNull
        protected abstract AbstractBeanDefinitionBuilder createChildBean​(FieldElement producerField)
        Creates a child bean for the given producer field.
        Parameters:
        producerField - The producer field
        Returns:
        The child bean builder
      • visitInterceptedMethods

        protected void visitInterceptedMethods​(java.util.function.BiConsumer<TypedElement,​MethodElement> consumer)
        Visit the intercepted methods of this type.
        Parameters:
        consumer - A consumer to handle the method
      • createChildBean

        @NonNull
        protected abstract AbstractBeanDefinitionBuilder createChildBean​(MethodElement producerMethod)
        Creates a child bean for the given producer method.
        Parameters:
        producerMethod - The producer method
        Returns:
        The child bean builder
      • build

        @Nullable
        public BeanClassWriter build()
        Build the bean definition writer.
        Returns:
        The writer, possibly null if it wasn't possible to build it
      • createAroundMethodVisitor

        @NonNull
        protected abstract java.util.function.BiConsumer<TypedElement,​MethodElement> createAroundMethodVisitor​(BeanDefinitionVisitor aopProxyWriter)
        Creates the around method visitor.
        Parameters:
        aopProxyWriter - The AOP writer
        Returns:
        The visitor
      • createAopWriter

        @NonNull
        protected abstract BeanDefinitionVisitor createAopWriter​(BeanDefinitionWriter beanDefinitionWriter,
                                                                 io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
        Creates the AOP writer.
        Parameters:
        beanDefinitionWriter - The bean definition writer
        annotationMetadata - The annotation metadata
        Returns:
        The AOP writer
      • finalizeAndWriteBean

        protected void finalizeAndWriteBean​(ClassWriterOutputVisitor classWriterOutputVisitor,
                                            BeanDefinitionVisitor beanDefinitionWriter)
                                     throws java.io.IOException
        Finish the given bean and write it to the output.
        Parameters:
        classWriterOutputVisitor - The output
        beanDefinitionWriter - The writer
        Throws:
        java.io.IOException - If an error occurred
      • configureBeanVisitor

        protected boolean configureBeanVisitor​(BeanDefinitionVisitor beanDefinitionWriter)
        Configure the bean visitor for this builder.
        Parameters:
        beanDefinitionWriter - The bean visitor
        Returns:
        True if an error occurred
      • createBeanDefinitionWriter

        protected BeanDefinitionVisitor createBeanDefinitionWriter()
        Returns:
        Creates the bean definition writer.
      • annotate

        protected abstract <T extends java.lang.annotation.Annotation> void annotate​(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
                                                                                     java.lang.String annotationType,
                                                                                     java.util.function.Consumer<io.micronaut.core.annotation.AnnotationValueBuilder<T>> consumer)
        Add an annotation to the given metadata.
        Type Parameters:
        T - The annotation generic type
        Parameters:
        annotationMetadata - The annotation metadata
        annotationType - the annotation type
        consumer - The builder
      • annotate

        protected abstract <T extends java.lang.annotation.Annotation> void annotate​(@NonNull
                                                                                     io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
                                                                                     @NonNull
                                                                                     io.micronaut.core.annotation.AnnotationValue<T> annotationValue)
        Add an annotation to the given metadata.
        Type Parameters:
        T - The annotation generic type
        Parameters:
        annotationMetadata - The annotation metadata
        annotationValue - The value
        Since:
        3.3.0
      • removeStereotype

        protected abstract void removeStereotype​(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
                                                 java.lang.String annotationType)
        Remove a stereotype from the given metadata.
        Parameters:
        annotationMetadata - The metadata
        annotationType - The stereotype
      • removeAnnotationIf

        protected abstract <T extends java.lang.annotation.Annotation> void removeAnnotationIf​(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
                                                                                               java.util.function.Predicate<io.micronaut.core.annotation.AnnotationValue<T>> predicate)
        Remove an annotation if it matches the given condition.
        Type Parameters:
        T - The annotation type
        Parameters:
        annotationMetadata - The metadata
        predicate - The predicate
      • removeAnnotation

        protected abstract void removeAnnotation​(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
                                                 java.lang.String annotationType)
        Remove an annotation for the given name.
        Parameters:
        annotationMetadata - The metadata
        annotationType - The type