use of io.micronaut.inject.ast.beans.BeanElementBuilder in project micronaut-core by micronaut-projects.
the class AbstractBeanDefinitionBuilder method produceBeans.
@Override
public <E extends MemberElement> BeanElementBuilder produceBeans(ElementQuery<E> methodsOrFields, Consumer<BeanElementBuilder> childBeanBuilder) {
methodsOrFields = methodsOrFields.onlyConcrete().onlyInstance().modifiers((modifiers) -> modifiers.contains(ElementModifier.PUBLIC));
final List<E> enclosedElements = this.beanType.getEnclosedElements(methodsOrFields);
for (E enclosedElement : enclosedElements) {
if (enclosedElement instanceof FieldElement) {
FieldElement fe = (FieldElement) enclosedElement;
final ClassElement type = fe.getGenericField().getType();
if (type.isPublic() && !type.isPrimitive()) {
return addChildBean(fe, childBeanBuilder);
}
}
if (enclosedElement instanceof MethodElement && !(enclosedElement instanceof ConstructorElement)) {
MethodElement me = (MethodElement) enclosedElement;
final ClassElement type = me.getGenericReturnType().getType();
if (type.isPublic() && !type.isPrimitive()) {
return addChildBean(me, childBeanBuilder);
}
}
}
return this;
}
use of io.micronaut.inject.ast.beans.BeanElementBuilder in project micronaut-core by micronaut-projects.
the class TestBeanFactoryDefiningVisitor method visitClass.
@Override
public void visitClass(ClassElement element, VisitorContext context) {
if (element.hasAnnotation(Prototype.class)) {
context.getClassElement(TestBeanProducer.class).ifPresent((producer) -> {
final BeanElementBuilder beanElementBuilder = element.addAssociatedBean(producer);
final ElementQuery<MethodElement> query = ElementQuery.ALL_METHODS.annotated((am) -> am.hasAnnotation(TestProduces.class));
beanElementBuilder.produceBeans(query);
final ElementQuery<FieldElement> fields = ElementQuery.ALL_FIELDS.annotated((am) -> am.hasAnnotation(TestProduces.class));
beanElementBuilder.produceBeans(fields);
});
}
}
Aggregations