Search in sources :

Example 6 with UsedByGeneratedCode

use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.

the class AbstractInitializableBeanDefinition method getBeanRegistrationsForField.

/**
 * Obtains all bean definitions 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
 */
@Internal
@UsedByGeneratedCode
protected final Object getBeanRegistrationsForField(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 resolveBeanRegistrations(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 7 with UsedByGeneratedCode

use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.

the class AbstractInitializableBeanDefinition method getValueForPath.

/**
 * Resolve a value for the given field of the given type and path.
 *
 * @param resolutionContext The resolution context
 * @param context           The bean context
 * @param propertyType      The required property type
 * @param propertyPath      The property path
 * @param <T1>              The generic type
 * @return An optional value
 */
@Internal
@UsedByGeneratedCode
protected final <T1> Optional<T1> getValueForPath(BeanResolutionContext resolutionContext, BeanContext context, Argument<T1> propertyType, String propertyPath) {
    if (context instanceof PropertyResolver) {
        PropertyResolver propertyResolver = (PropertyResolver) context;
        String valString = substituteWildCards(resolutionContext, propertyPath);
        return propertyResolver.getProperty(valString, ConversionContext.of(propertyType));
    }
    return Optional.empty();
}
Also used : PropertyResolver(io.micronaut.core.value.PropertyResolver) Internal(io.micronaut.core.annotation.Internal) UsedByGeneratedCode(io.micronaut.core.annotation.UsedByGeneratedCode)

Example 8 with UsedByGeneratedCode

use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.

the class AbstractInitializableBeanDefinition method getValueForConstructorArgument.

/**
 * Obtains a 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 qualifier         The qualifier
 * @return The resolved bean
 */
@Internal
@UsedByGeneratedCode
@Deprecated
protected final Object getValueForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex, Qualifier qualifier) {
    MethodReference constructorRef = (MethodReference) constructor;
    Argument<?> argument = constructorRef.arguments[argIndex];
    try (BeanResolutionContext.Path ignored = resolutionContext.getPath().pushConstructorResolve(this, argument)) {
        try {
            Object result = resolveValue(resolutionContext, context, constructorRef.annotationMetadata, argument, qualifier);
            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 9 with UsedByGeneratedCode

use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.

the class AbstractInitializableBeanDefinition method getBeansOfTypeForConstructorArgument.

/**
 * Obtains all bean definitions for a constructor argument at the given index.
 * <p>
 *
 * @param resolutionContext The resolution context
 * @param context           The context
 * @param argumentIndex     The argument index
 * @param genericType       The generic type
 * @param qualifier         The qualifier
 * @return The resolved bean
 */
@Internal
@UsedByGeneratedCode
protected final Collection<Object> getBeansOfTypeForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argumentIndex, Argument genericType, Qualifier qualifier) {
    MethodReference constructorMethodRef = (MethodReference) constructor;
    Argument argument = resolveArgument(context, argumentIndex, constructorMethodRef.arguments);
    try (BeanResolutionContext.Path ignored = resolutionContext.getPath().pushConstructorResolve(this, argument)) {
        return resolveBeansOfType(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 10 with UsedByGeneratedCode

use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.

the class AbstractInitializableBeanDefinition method findBeanForField.

/**
 * Obtains a an optional for the field at the given index and the argument 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 fieldIndex        The field index
 * @param genericType       The generic type
 * @param qualifier         The qualifier
 * @return The resolved bean
 */
@Internal
@UsedByGeneratedCode
protected final Optional findBeanForField(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 resolveOptionalBean(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)

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