@Internal public abstract class AbstractBeanDefinitionBuilder extends Object implements BeanElementBuilder
BeanElementBuilder interface that should be implemented by downstream language specific implementations.| Modifier and Type | Field and Description |
|---|---|
protected ConfigurationMetadataBuilder<?> |
metadataBuilder |
protected VisitorContext |
visitorContext |
EMPTY_ELEMENT_ARRAYCLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBEREMPTY| Modifier | Constructor and Description |
|---|---|
protected |
AbstractBeanDefinitionBuilder(Element originatingElement,
ClassElement beanType,
ConfigurationMetadataBuilder<?> metadataBuilder,
VisitorContext visitorContext)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract <T extends Annotation> |
annotate(AnnotationMetadata annotationMetadata,
AnnotationValue<T> annotationValue)
Add an annotation to the given metadata.
|
protected abstract <T extends Annotation> |
annotate(AnnotationMetadata annotationMetadata,
String annotationType,
Consumer<AnnotationValueBuilder<T>> consumer)
Add an annotation to the given metadata.
|
<T extends Annotation> |
annotate(AnnotationValue<T> annotationValue)
Annotate this element with the given annotation type.
|
<T extends Annotation> |
annotate(String annotationType,
Consumer<AnnotationValueBuilder<T>> consumer)
Annotate this element with the given annotation type.
|
BeanClassWriter |
build()
Build the bean definition writer.
|
protected boolean |
configureBeanVisitor(BeanDefinitionVisitor beanDefinitionWriter)
Configure the bean visitor for this builder.
|
protected abstract BeanDefinitionVisitor |
createAopWriter(BeanDefinitionWriter beanDefinitionWriter,
AnnotationMetadata annotationMetadata)
Creates the AOP writer.
|
protected abstract BiConsumer<TypedElement,MethodElement> |
createAroundMethodVisitor(BeanDefinitionVisitor aopProxyWriter)
Creates the around method visitor.
|
protected BeanDefinitionVisitor |
createBeanDefinitionWriter() |
protected abstract AbstractBeanDefinitionBuilder |
createChildBean(FieldElement producerField)
Creates a child bean for the given producer field.
|
protected abstract AbstractBeanDefinitionBuilder |
createChildBean(MethodElement producerMethod)
Creates a child bean for the given producer method.
|
BeanElementBuilder |
createWith(MethodElement element)
Specifies the bean will created with the given method element.
|
protected void |
finalizeAndWriteBean(ClassWriterOutputVisitor classWriterOutputVisitor,
BeanDefinitionVisitor beanDefinitionWriter)
Finish the given bean and write it to the output.
|
AnnotationMetadata |
getAnnotationMetadata()
Supplies the metadata.
|
ClassElement |
getBeanType() |
List<AbstractBeanDefinitionBuilder> |
getChildBeans()
Any child bean definitions.
|
String |
getName() |
Object |
getNativeType()
Returns the native underlying type.
|
Element |
getOriginatingElement() |
protected BeanParameterElement[] |
getParameters() |
protected BeanParameterElement[] |
initBeanParameters(ParameterElement[] constructorParameters)
Initialize the bean parameters.
|
BeanElementBuilder |
inject()
Dependency inject this bean.
|
BeanElementBuilder |
intercept(AnnotationValue<?>... annotationValue)
Intercept the bean.
|
protected boolean |
isIntercepted()
Is the bean to be built intercepted?
|
boolean |
isProtected() |
boolean |
isPublic() |
<E extends MemberElement> |
produceBeans(ElementQuery<E> methodsOrFields,
Consumer<BeanElementBuilder> childBeanBuilder)
Produce additional beans from the given methods.
|
protected abstract void |
removeAnnotation(AnnotationMetadata annotationMetadata,
String annotationType)
Remove an annotation for the given name.
|
BeanElementBuilder |
removeAnnotation(String annotationType)
Removes an annotation of the given type from the element.
|
protected abstract <T extends Annotation> |
removeAnnotationIf(AnnotationMetadata annotationMetadata,
Predicate<AnnotationValue<T>> predicate)
Remove an annotation if it matches the given condition.
|
<T extends Annotation> |
removeAnnotationIf(Predicate<AnnotationValue<T>> predicate)
Removes all annotations that pass the given predicate.
|
protected abstract void |
removeStereotype(AnnotationMetadata annotationMetadata,
String annotationType)
Remove a stereotype from the given metadata.
|
BeanElementBuilder |
removeStereotype(String annotationType)
Removes a stereotype of the given name from the element.
|
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.
|
protected void |
visitInterceptedMethods(BiConsumer<TypedElement,MethodElement> consumer)
Visit the intercepted methods of this type.
|
BeanElementBuilder |
withConstructor(Consumer<BeanConstructorElement> constructorElement)
Allows configuring the bean constructor.
|
BeanElementBuilder |
withFields(ElementQuery<FieldElement> fields,
Consumer<BeanFieldElement> beanFields)
Allows configuring fields of the bean.
|
BeanElementBuilder |
withMethods(ElementQuery<MethodElement> methods,
Consumer<BeanMethodElement> beanMethods)
Allows configuring methods of the bean.
|
BeanElementBuilder |
withParameters(Consumer<BeanParameterElement[]> parameters)
Allows configuring the parameters for the current constructor.
|
static void |
writeBeanDefinitionBuilders(ClassWriterOutputVisitor classWriterOutputVisitor,
List<AbstractBeanDefinitionBuilder> beanDefinitionBuilders) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitannotate, annotate, annotate, getDeclaringElement, getProducingElement, produceBeans, qualifier, qualifier, removeAnnotation, removeStereotype, scope, scopegetDescription, getDescription, getDocumentation, getModifiers, getSimpleName, isAbstract, isFinal, isPackagePrivate, isPrivate, isStaticbooleanValue, 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, synthesizeDeclaredAnnotationsByTypegetAnnotationValuesByName, getAnnotationValuesByStereotype, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresentisDeclaredNonNull, isDeclaredNullable, isNonNull, isNullableprotected final ConfigurationMetadataBuilder<?> metadataBuilder
protected final VisitorContext visitorContext
protected AbstractBeanDefinitionBuilder(Element originatingElement, ClassElement beanType, ConfigurationMetadataBuilder<?> metadataBuilder, VisitorContext visitorContext)
originatingElement - The originating elementbeanType - The bean typemetadataBuilder - the metadata buildervisitorContext - the visitor contextpublic BeanElementBuilder intercept(AnnotationValue<?>... annotationValue)
BeanElementBuilderintercept in interface BeanElementBuilderannotationValue - The annotation to intercept@Internal public static void writeBeanDefinitionBuilders(ClassWriterOutputVisitor classWriterOutputVisitor, List<AbstractBeanDefinitionBuilder> beanDefinitionBuilders) throws IOException
IOExceptionprotected boolean isIntercepted()
public BeanElementBuilder inject()
BeanElementBuilderinject in interface BeanElementBuilderpublic List<AbstractBeanDefinitionBuilder> getChildBeans()
@NonNull public Element getOriginatingElement()
getOriginatingElement in interface BeanElementBuilder@NonNull public ClassElement getBeanType()
getBeanType in interface BeanElementBuilderprotected final BeanParameterElement[] initBeanParameters(@NonNull ParameterElement[] constructorParameters)
constructorParameters - The parameters to use.@NonNull public AnnotationMetadata getAnnotationMetadata()
AnnotationMetadataProviderAnnotationMetadata.EMPTY_METADATA.getAnnotationMetadata in interface AnnotationMetadataProviderAnnotationMetadata@NonNull public BeanElementBuilder createWith(@NonNull MethodElement element)
BeanElementBuilderClassElement.getPrimaryConstructor().
Note that the method can be a one of the following:
createWith in interface BeanElementBuilderelement - The element@NonNull public BeanElementBuilder typed(ClassElement... types)
BeanElementBuildertyped in interface BeanElementBuildertypes - 1 or more types to expose@NonNull public BeanElementBuilder typeArguments(@NonNull ClassElement... types)
BeanElementBuildertypeArguments in interface BeanElementBuildertypeArguments in interface ConfigurableElementtypes - The types@NonNull public BeanElementBuilder typeArgumentsForType(ClassElement type, @NonNull ClassElement... types)
BeanElementBuildertypeArgumentsForType in interface BeanElementBuildertype - The type or interface. If null, results in a no-optypes - The typespublic BeanElementBuilder withConstructor(Consumer<BeanConstructorElement> constructorElement)
BeanElementBuilderwithConstructor in interface BeanElementBuilderconstructorElement - The constructor element@NonNull public BeanElementBuilder withMethods(@NonNull ElementQuery<MethodElement> methods, @NonNull Consumer<BeanMethodElement> beanMethods)
BeanElementBuilderwithMethods in interface BeanElementBuildermethods - The ElementQuery to locate selected methods.beanMethods - A consumer that receives each BeanMethodElement@NonNull public BeanElementBuilder withFields(@NonNull ElementQuery<FieldElement> fields, @NonNull Consumer<BeanFieldElement> beanFields)
BeanElementBuilderwithFields in interface BeanElementBuilderfields - The ElementQuery to locate fields.beanFields - The bean fields@NonNull public BeanElementBuilder withParameters(Consumer<BeanParameterElement[]> parameters)
BeanElementBuilderwithParameters in interface BeanElementBuilderparameters - The parameters@NonNull protected BeanParameterElement[] getParameters()
public boolean isProtected()
isProtected in interface Elementpublic boolean isPublic()
@NonNull public Object getNativeType()
ElementgetNativeType in interface Element@NonNull public <T extends Annotation> BeanElementBuilder annotate(@NonNull String annotationType, @NonNull Consumer<AnnotationValueBuilder<T>> consumer)
Elementannotate in interface BeanElementBuilderannotate in interface ElementT - The annotation generic typeannotationType - The annotation typeconsumer - A function that receives the AnnotationValueBuilderpublic <T extends Annotation> Element annotate(AnnotationValue<T> annotationValue)
Elementpublic BeanElementBuilder removeAnnotation(@NonNull String annotationType)
ElementIf 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.
removeAnnotation in interface BeanElementBuilderremoveAnnotation in interface ElementannotationType - The annotation typepublic <T extends Annotation> BeanElementBuilder removeAnnotationIf(@NonNull Predicate<AnnotationValue<T>> predicate)
ElementremoveAnnotationIf in interface BeanElementBuilderremoveAnnotationIf in interface ElementT - The annotation generic typepredicate - The predicatepublic BeanElementBuilder removeStereotype(@NonNull String annotationType)
ElementremoveStereotype in interface BeanElementBuilderremoveStereotype in interface ElementannotationType - The annotation typepublic <E extends MemberElement> BeanElementBuilder produceBeans(ElementQuery<E> methodsOrFields, Consumer<BeanElementBuilder> childBeanBuilder)
BeanElementBuilderproduceBeans in interface BeanElementBuilderE - A type variable tomethodsOrFields - The ElementQuery representing the methods or fieldschildBeanBuilder - Configure the child bean builder@NonNull protected abstract AbstractBeanDefinitionBuilder createChildBean(FieldElement producerField)
producerField - The producer fieldprotected void visitInterceptedMethods(BiConsumer<TypedElement,MethodElement> consumer)
consumer - A consumer to handle the method@NonNull protected abstract AbstractBeanDefinitionBuilder createChildBean(MethodElement producerMethod)
producerMethod - The producer method@Nullable public BeanClassWriter build()
@NonNull protected abstract BiConsumer<TypedElement,MethodElement> createAroundMethodVisitor(BeanDefinitionVisitor aopProxyWriter)
aopProxyWriter - The AOP writer@NonNull protected abstract BeanDefinitionVisitor createAopWriter(BeanDefinitionWriter beanDefinitionWriter, AnnotationMetadata annotationMetadata)
beanDefinitionWriter - The bean definition writerannotationMetadata - The annotation metadataprotected void finalizeAndWriteBean(ClassWriterOutputVisitor classWriterOutputVisitor, BeanDefinitionVisitor beanDefinitionWriter) throws IOException
classWriterOutputVisitor - The outputbeanDefinitionWriter - The writerIOException - If an error occurredprotected boolean configureBeanVisitor(BeanDefinitionVisitor beanDefinitionWriter)
beanDefinitionWriter - The bean visitorprotected BeanDefinitionVisitor createBeanDefinitionWriter()
protected abstract <T extends Annotation> void annotate(AnnotationMetadata annotationMetadata, String annotationType, Consumer<AnnotationValueBuilder<T>> consumer)
T - The annotation generic typeannotationMetadata - The annotation metadataannotationType - the annotation typeconsumer - The builderprotected abstract <T extends Annotation> void annotate(@NonNull AnnotationMetadata annotationMetadata, @NonNull AnnotationValue<T> annotationValue)
T - The annotation generic typeannotationMetadata - The annotation metadataannotationValue - The valueprotected abstract void removeStereotype(AnnotationMetadata annotationMetadata, String annotationType)
annotationMetadata - The metadataannotationType - The stereotypeprotected abstract <T extends Annotation> void removeAnnotationIf(AnnotationMetadata annotationMetadata, Predicate<AnnotationValue<T>> predicate)
T - The annotation typeannotationMetadata - The metadatapredicate - The predicateprotected abstract void removeAnnotation(AnnotationMetadata annotationMetadata, String annotationType)
annotationMetadata - The metadataannotationType - The type