use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method containsValueForMethodArgument.
/**
* Obtains a value for the given method argument.
*
* @param resolutionContext The resolution context
* @param context The bean context
* @param methodIndex The method index
* @param argIndex The argument index
* @param isValuePrefix Is value prefix in cases when beans are requested
* @return The value
*/
@Internal
@UsedByGeneratedCode
@Deprecated
protected final boolean containsValueForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex, boolean isValuePrefix) {
MethodReference methodRef = methodInjection[methodIndex];
AnnotationMetadata parentAnnotationMetadata = methodRef.annotationMetadata;
Argument argument = methodRef.arguments[argIndex];
return resolveContainsValue(resolutionContext, context, parentAnnotationMetadata, argument, isValuePrefix);
}
use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method getPropertyValueForConstructorArgument.
/**
* Obtains a property value for a bean definition for a constructor at the given index
* <p>
* Warning: this method is used by internal generated code and should not be called by user code.
*
* @param resolutionContext The resolution context
* @param context The context
* @param argIndex The argument index
* @param propertyValue The property value
* @param cliProperty The cli property
* @return The resolved bean
*/
@Internal
@UsedByGeneratedCode
protected final Object getPropertyValueForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex, String propertyValue, String cliProperty) {
MethodReference constructorRef = (MethodReference) constructor;
Argument<?> argument = constructorRef.arguments[argIndex];
try (BeanResolutionContext.Path ignored = resolutionContext.getPath().pushConstructorResolve(this, argument)) {
try {
Object result = resolvePropertyValue(resolutionContext, context, argument, propertyValue, cliProperty, false);
if (this instanceof ValidatedBeanDefinition) {
((ValidatedBeanDefinition) this).validateBeanArgument(resolutionContext, getConstructor(), argument, argIndex, result);
}
return result;
} catch (NoSuchBeanException | BeanInstantiationException e) {
throw new DependencyInjectionException(resolutionContext, argument, e);
}
}
}
use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method getBeanRegistrationForField.
/**
* Obtains a bean registration for a field injection point.
* <p>
* Warning: this method is used by internal generated code and should not be called by user code.
*
* @param resolutionContext The resolution context
* @param context The context
* @param fieldIndex The field index
* @param genericType The generic type
* @param qualifier The qualifier
* @return The resolved bean registration
*/
@Internal
@UsedByGeneratedCode
protected final BeanRegistration<?> getBeanRegistrationForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex, Argument genericType, Qualifier qualifier) {
FieldReference fieldRef = fieldInjection[fieldIndex];
Argument argument = resolveEnvironmentArgument(context, fieldRef.argument);
try (BeanResolutionContext.Path ignored = resolutionContext.getPath().pushFieldResolve(this, argument, fieldRef.requiresReflection)) {
return resolveBeanRegistration(resolutionContext, context, argument, resolveEnvironmentArgument(context, genericType), qualifier);
}
}
use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class ConstructorInterceptorChain method instantiate.
/**
* Internal methods that handles the logic of instantiating a bean that has constructor interception applied.
*
* @param resolutionContext The resolution context
* @param beanContext The bean context
* @param interceptors The interceptors. Can be null and if so should be resolved from the context.
* @param definition The definition
* @param constructor The bean constructor
* @param additionalProxyConstructorParametersCount The additional proxy constructor parameters count
* @param parameters The resolved parameters
* @param <T1> The bean type
* @return The instantiated bean
* @since 3.0.0
*/
@Internal
@UsedByGeneratedCode
@NonNull
public static <T1> T1 instantiate(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanContext beanContext, @Nullable List<BeanRegistration<Interceptor<T1, T1>>> interceptors, @NonNull BeanDefinition<T1> definition, @NonNull BeanConstructor<T1> constructor, int additionalProxyConstructorParametersCount, @NonNull Object... parameters) {
if (interceptors == null) {
final AnnotationMetadataHierarchy hierarchy = new AnnotationMetadataHierarchy(definition.getAnnotationMetadata(), constructor.getAnnotationMetadata());
final Collection<AnnotationValue<?>> annotationValues = resolveInterceptorValues(hierarchy, InterceptorKind.AROUND_CONSTRUCT);
final Collection<BeanRegistration<Interceptor<?, ?>>> resolved = ((DefaultBeanContext) beanContext).getBeanRegistrations(resolutionContext, Interceptor.ARGUMENT, Qualifiers.byInterceptorBindingValues(annotationValues));
interceptors = new ArrayList(resolved);
}
final InterceptorRegistry interceptorRegistry = beanContext.getBean(InterceptorRegistry.ARGUMENT);
final Interceptor<T1, T1>[] resolvedInterceptors = interceptorRegistry.resolveConstructorInterceptors(constructor, interceptors);
return Objects.requireNonNull(new ConstructorInterceptorChain<T1>(definition, constructor, resolvedInterceptors, additionalProxyConstructorParametersCount, parameters).proceed(), "Constructor interceptor chain illegally returned null for constructor: " + constructor.getDescription());
}
Aggregations