Search in sources :

Example 11 with UsedByGeneratedCode

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);
}
Also used : DefaultArgument(io.micronaut.core.type.DefaultArgument) Argument(io.micronaut.core.type.Argument) AbstractEnvironmentAnnotationMetadata(io.micronaut.inject.annotation.AbstractEnvironmentAnnotationMetadata) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) Internal(io.micronaut.core.annotation.Internal) UsedByGeneratedCode(io.micronaut.core.annotation.UsedByGeneratedCode)

Example 12 with UsedByGeneratedCode

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);
        }
    }
}
Also used : DependencyInjectionException(io.micronaut.context.exceptions.DependencyInjectionException) NoSuchBeanException(io.micronaut.context.exceptions.NoSuchBeanException) BeanInstantiationException(io.micronaut.context.exceptions.BeanInstantiationException) ValidatedBeanDefinition(io.micronaut.inject.ValidatedBeanDefinition) Internal(io.micronaut.core.annotation.Internal) UsedByGeneratedCode(io.micronaut.core.annotation.UsedByGeneratedCode)

Example 13 with UsedByGeneratedCode

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);
    }
}
Also used : DefaultArgument(io.micronaut.core.type.DefaultArgument) Argument(io.micronaut.core.type.Argument) Internal(io.micronaut.core.annotation.Internal) UsedByGeneratedCode(io.micronaut.core.annotation.UsedByGeneratedCode)

Example 14 with UsedByGeneratedCode

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());
}
Also used : BeanRegistration(io.micronaut.context.BeanRegistration) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) DefaultBeanContext(io.micronaut.context.DefaultBeanContext) AnnotationMetadataHierarchy(io.micronaut.inject.annotation.AnnotationMetadataHierarchy) Internal(io.micronaut.core.annotation.Internal) NonNull(io.micronaut.core.annotation.NonNull) UsedByGeneratedCode(io.micronaut.core.annotation.UsedByGeneratedCode)

Aggregations

Internal (io.micronaut.core.annotation.Internal)14 UsedByGeneratedCode (io.micronaut.core.annotation.UsedByGeneratedCode)14 Argument (io.micronaut.core.type.Argument)8 DefaultArgument (io.micronaut.core.type.DefaultArgument)8 BeanInstantiationException (io.micronaut.context.exceptions.BeanInstantiationException)3 DependencyInjectionException (io.micronaut.context.exceptions.DependencyInjectionException)3 NoSuchBeanException (io.micronaut.context.exceptions.NoSuchBeanException)3 ValidatedBeanDefinition (io.micronaut.inject.ValidatedBeanDefinition)3 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)2 BeanRegistration (io.micronaut.context.BeanRegistration)1 DefaultBeanContext (io.micronaut.context.DefaultBeanContext)1 AnnotationClassValue (io.micronaut.core.annotation.AnnotationClassValue)1 AnnotationUtil (io.micronaut.core.annotation.AnnotationUtil)1 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 NonNull (io.micronaut.core.annotation.NonNull)1 ReflectionUtils (io.micronaut.core.reflect.ReflectionUtils)1 ArrayUtils (io.micronaut.core.util.ArrayUtils)1 CollectionUtils (io.micronaut.core.util.CollectionUtils)1 PropertyResolver (io.micronaut.core.value.PropertyResolver)1 AbstractEnvironmentAnnotationMetadata (io.micronaut.inject.annotation.AbstractEnvironmentAnnotationMetadata)1