use of io.micronaut.inject.BeanConfiguration in project micronaut-core by micronaut-projects.
the class AbstractBeanContextConditional method isEnabled.
@Override
public boolean isEnabled(@NonNull BeanContext context, @Nullable BeanResolutionContext resolutionContext) {
AnnotationMetadata annotationMetadata = getAnnotationMetadata();
Condition condition = annotationMetadata.hasStereotype(Requires.class) ? new RequiresCondition(annotationMetadata) : null;
DefaultConditionContext<AbstractBeanContextConditional> conditionContext = new DefaultConditionContext<>((DefaultBeanContext) context, this, resolutionContext);
boolean enabled = condition == null || condition.matches(conditionContext);
if (LOG.isDebugEnabled() && !enabled) {
if (this instanceof BeanConfiguration) {
LOG.debug(this + " will not be loaded due to failing conditions:");
} else {
LOG.debug("Bean [" + this + "] will not be loaded due to failing conditions:");
}
for (Failure failure : conditionContext.getFailures()) {
LOG.debug("* {}", failure.getMessage());
}
}
return enabled;
}
use of io.micronaut.inject.BeanConfiguration in project micronaut-core by micronaut-projects.
the class DefaultBeanContext method readAllBeanDefinitionClasses.
private void readAllBeanDefinitionClasses() {
List<BeanDefinitionReference> contextScopeBeans = new ArrayList<>(20);
List<BeanDefinitionReference> processedBeans = new ArrayList<>(10);
List<BeanDefinitionReference> parallelBeans = new ArrayList<>(10);
List<BeanDefinitionReference> beanDefinitionReferences = resolveBeanDefinitionReferences();
beanDefinitionsClasses.addAll(beanDefinitionReferences);
Set<BeanConfiguration> configurationsDisabled = new HashSet<>();
for (BeanConfiguration bc : beanConfigurations.values()) {
if (!bc.isEnabled(this)) {
configurationsDisabled.add(bc);
}
}
reference: for (BeanDefinitionReference beanDefinitionReference : beanDefinitionReferences) {
for (BeanConfiguration disableConfiguration : configurationsDisabled) {
if (disableConfiguration.isWithin(beanDefinitionReference)) {
beanDefinitionsClasses.remove(beanDefinitionReference);
continue reference;
}
}
final AnnotationMetadata annotationMetadata = beanDefinitionReference.getAnnotationMetadata();
Class[] indexes = annotationMetadata.classValues(INDEXES_TYPE);
if (indexes.length > 0) {
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < indexes.length; i++) {
Class indexedType = indexes[i];
resolveTypeIndex(indexedType).add(beanDefinitionReference);
}
} else {
if (annotationMetadata.hasStereotype(ADAPTER_TYPE)) {
final Class aClass = annotationMetadata.classValue(ADAPTER_TYPE, AnnotationMetadata.VALUE_MEMBER).orElse(null);
if (indexedTypes.contains(aClass)) {
resolveTypeIndex(aClass).add(beanDefinitionReference);
}
}
}
if (isEagerInit(beanDefinitionReference)) {
contextScopeBeans.add(beanDefinitionReference);
} else if (annotationMetadata.hasDeclaredStereotype(PARALLEL_TYPE)) {
parallelBeans.add(beanDefinitionReference);
}
if (beanDefinitionReference.requiresMethodProcessing()) {
processedBeans.add(beanDefinitionReference);
}
}
beanDefinitionReferences = null;
beanConfigurationsList = null;
initializeEventListeners();
initializeContext(contextScopeBeans, processedBeans, parallelBeans);
}
Aggregations