use of io.quarkus.arc.processor.BeanInfo in project quarkus by quarkusio.
the class JsonbProcessor method processJsonbAdapters.
@BuildStep
void processJsonbAdapters(BuildProducer<UnremovableBeanBuildItem> unremovableBeans, BuildProducer<AutoAddScopeBuildItem> autoScopes) {
// An adapter with an injection point but no scope is @Singleton
autoScopes.produce(AutoAddScopeBuildItem.builder().implementsInterface(JSONB_ADAPTER_NAME).requiresContainerServices().defaultScope(BuiltinScope.SINGLETON).build());
// Make all adapters unremovable
unremovableBeans.produce(new UnremovableBeanBuildItem(new Predicate<BeanInfo>() {
@Override
public boolean test(BeanInfo bean) {
return bean.isClassBean() && bean.hasType(JSONB_ADAPTER_NAME);
}
}));
}
use of io.quarkus.arc.processor.BeanInfo in project quarkus by quarkusio.
the class AutoAddScopeProcessor method annotationTransformer.
@BuildStep
void annotationTransformer(List<AutoAddScopeBuildItem> autoScopes, CustomScopeAnnotationsBuildItem scopes, List<AutoInjectAnnotationBuildItem> autoInjectAnnotations, BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformers, BuildProducer<UnremovableBeanBuildItem> unremovableBeans, BeanArchiveIndexBuildItem beanArchiveIndex) throws Exception {
if (autoScopes.isEmpty()) {
return;
}
List<AutoAddScopeBuildItem> sortedAutoScopes = autoScopes.stream().sorted(Comparator.comparingInt(AutoAddScopeBuildItem::getPriority).reversed()).collect(Collectors.toList());
Set<DotName> containerAnnotationNames = autoInjectAnnotations.stream().flatMap(a -> a.getAnnotationNames().stream()).collect(Collectors.toSet());
containerAnnotationNames.add(DotNames.POST_CONSTRUCT);
containerAnnotationNames.add(DotNames.PRE_DESTROY);
containerAnnotationNames.add(DotNames.INJECT);
Set<DotName> unremovables = new HashSet<>();
annotationsTransformers.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public boolean appliesTo(Kind kind) {
return kind == Kind.CLASS;
}
@Override
public int getPriority() {
// Make sure this annotation transformer runs before all transformers with the default priority
return DEFAULT_PRIORITY + 1000;
}
@Override
public void transform(TransformationContext context) {
if (scopes.isScopeIn(context.getAnnotations())) {
// Skip classes annotated with a scope
return;
}
ClassInfo clazz = context.getTarget().asClass();
DotName scope = null;
Boolean requiresContainerServices = null;
String reason = null;
for (AutoAddScopeBuildItem autoScope : sortedAutoScopes) {
if (autoScope.isContainerServicesRequired()) {
if (requiresContainerServices == null) {
// Analyze the class hierarchy lazily
requiresContainerServices = requiresContainerServices(clazz, containerAnnotationNames, beanArchiveIndex.getIndex());
}
if (!requiresContainerServices) {
// Skip - no injection point detected
continue;
}
}
if (autoScope.test(clazz, context.getAnnotations(), beanArchiveIndex.getIndex())) {
if (scope != null) {
BiConsumer<DotName, String> consumer = autoScope.getScopeAlreadyAdded();
if (consumer != null) {
consumer.accept(scope, reason);
} else {
LOGGER.debugf("Scope %s was already added for reason: %s", scope, reason);
}
continue;
}
scope = autoScope.getDefaultScope();
reason = autoScope.getReason();
context.transform().add(scope).done();
if (autoScope.isUnremovable()) {
unremovables.add(clazz.name());
}
LOGGER.debugf("Automatically added scope %s to class %s: %s", scope, clazz, autoScope.getReason());
}
}
}
}));
if (!unremovables.isEmpty()) {
unremovableBeans.produce(new UnremovableBeanBuildItem(new Predicate<BeanInfo>() {
@Override
public boolean test(BeanInfo bean) {
return bean.isClassBean() && unremovables.contains(bean.getBeanClass());
}
}));
}
}
use of io.quarkus.arc.processor.BeanInfo in project quarkus by quarkusio.
the class LookupConditionsProcessor method suppressConditionsGenerators.
@BuildStep
void suppressConditionsGenerators(BuildProducer<SuppressConditionGeneratorBuildItem> generators, BeanArchiveIndexBuildItem beanArchiveIndex) {
IndexView index = beanArchiveIndex.getIndex();
generators.produce(new SuppressConditionGeneratorBuildItem(new Function<BeanInfo, Consumer<BytecodeCreator>>() {
@Override
public Consumer<BytecodeCreator> apply(BeanInfo bean) {
Optional<AnnotationTarget> maybeTarget = bean.getTarget();
if (maybeTarget.isPresent()) {
AnnotationTarget target = maybeTarget.get();
List<AnnotationInstance> ifPropertyList = findAnnotations(target, LOOK_UP_IF_PROPERTY, LOOK_UP_IF_CONTAINER, index);
List<AnnotationInstance> unlessPropertyList = findAnnotations(target, LOOK_UP_UNLESS_PROPERTY, LOOK_UP_UNLESS_PROPERTY_CONTAINER, index);
if (!ifPropertyList.isEmpty() || !unlessPropertyList.isEmpty()) {
return new Consumer<BytecodeCreator>() {
@Override
public void accept(BytecodeCreator suppressed) {
for (AnnotationInstance ifProperty : ifPropertyList) {
String propertyName = ifProperty.value(NAME).asString();
String expectedStringValue = ifProperty.value(STRING_VALUE).asString();
AnnotationValue lookupIfMissingValue = ifProperty.value(LOOKUP_IF_MISSING);
boolean lookupIfMissing = lookupIfMissingValue != null && lookupIfMissingValue.asBoolean();
ResultHandle result = suppressed.invokeStaticMethod(SUPPRESS_IF_PROPERTY, suppressed.load(propertyName), suppressed.load(expectedStringValue), suppressed.load(lookupIfMissing));
suppressed.ifTrue(result).trueBranch().returnValue(suppressed.load(true));
}
for (AnnotationInstance unlessProperty : unlessPropertyList) {
String propertyName = unlessProperty.value(NAME).asString();
String expectedStringValue = unlessProperty.value(STRING_VALUE).asString();
AnnotationValue lookupIfMissingValue = unlessProperty.value(LOOKUP_IF_MISSING);
boolean lookupIfMissing = lookupIfMissingValue != null && lookupIfMissingValue.asBoolean();
ResultHandle result = suppressed.invokeStaticMethod(SUPPRESS_UNLESS_PROPERTY, suppressed.load(propertyName), suppressed.load(expectedStringValue), suppressed.load(lookupIfMissing));
suppressed.ifTrue(result).trueBranch().returnValue(suppressed.load(true));
}
}
};
}
}
return null;
}
}));
}
use of io.quarkus.arc.processor.BeanInfo in project quarkus by quarkusio.
the class ArcDevConsoleProcessor method collectBeanInfo.
@BuildStep(onlyIf = IsDevelopment.class)
public DevConsoleTemplateInfoBuildItem collectBeanInfo(ValidationPhaseBuildItem validationPhaseBuildItem, CompletedApplicationClassPredicateBuildItem predicate) {
BeanDeploymentValidator.ValidationContext validationContext = validationPhaseBuildItem.getContext();
DevBeanInfos beanInfos = new DevBeanInfos();
for (BeanInfo bean : validationContext.beans()) {
beanInfos.addBean(DevBeanInfo.from(bean, predicate));
}
for (BeanInfo bean : validationContext.removedBeans()) {
beanInfos.addRemovedBean(DevBeanInfo.from(bean, predicate));
}
for (ObserverInfo observer : validationContext.get(BuildExtension.Key.OBSERVERS)) {
beanInfos.addObserver(DevObserverInfo.from(observer, predicate));
}
for (InterceptorInfo interceptor : validationContext.get(BuildExtension.Key.INTERCEPTORS)) {
beanInfos.addInterceptor(DevInterceptorInfo.from(interceptor, predicate));
}
Collection<InterceptorInfo> removedInterceptors = validationContext.get(BuildExtension.Key.REMOVED_INTERCEPTORS);
if (removedInterceptors != null) {
for (InterceptorInfo interceptor : removedInterceptors) {
beanInfos.addRemovedInterceptor(DevInterceptorInfo.from(interceptor, predicate));
}
}
for (DecoratorInfo decorator : validationContext.get(BuildExtension.Key.DECORATORS)) {
beanInfos.addDecorator(DevDecoratorInfo.from(decorator, predicate));
}
Collection<DecoratorInfo> removedDecorators = validationContext.get(BuildExtension.Key.REMOVED_DECORATORS);
if (removedDecorators != null) {
for (DecoratorInfo decorator : removedDecorators) {
beanInfos.addRemovedDecorator(DevDecoratorInfo.from(decorator, predicate));
}
}
beanInfos.sort();
return new DevConsoleTemplateInfoBuildItem("devBeanInfos", beanInfos);
}
use of io.quarkus.arc.processor.BeanInfo in project quarkus by quarkusio.
the class GrpcServerProcessor method validateBindableServices.
@BuildStep
void validateBindableServices(ValidationPhaseBuildItem validationPhase, BuildProducer<ValidationPhaseBuildItem.ValidationErrorBuildItem> errors) {
Type mutinyBeanType = Type.create(GrpcDotNames.MUTINY_BEAN, org.jboss.jandex.Type.Kind.CLASS);
Type mutinyServiceType = Type.create(GrpcDotNames.MUTINY_SERVICE, org.jboss.jandex.Type.Kind.CLASS);
Type bindableServiceType = Type.create(GrpcDotNames.BINDABLE_SERVICE, org.jboss.jandex.Type.Kind.CLASS);
Predicate<Set<Type>> predicate = new Predicate<>() {
@Override
public boolean test(Set<Type> types) {
return types.contains(bindableServiceType) || types.contains(mutinyServiceType);
}
};
for (BeanInfo bean : validationPhase.getContext().beans().classBeans().matchBeanTypes(predicate)) {
validateBindableService(bean, mutinyBeanType, errors);
}
// Validate the removed beans as well - detect beans not annotated with @GrpcService
for (BeanInfo bean : validationPhase.getContext().removedBeans().classBeans().matchBeanTypes(predicate)) {
validateBindableService(bean, mutinyBeanType, errors);
}
}
Aggregations