use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method getBeanForMethodArgument.
/**
* Obtains a bean definition for the method 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 methodIndex The method index
* @param argIndex The argument index
* @param qualifier The qualifier
* @return The resolved bean
*/
@Internal
@SuppressWarnings("WeakerAccess")
@UsedByGeneratedCode
protected final Object getBeanForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex, Qualifier qualifier) {
MethodReference methodRef = methodInjection[methodIndex];
Argument argument = resolveArgument(context, argIndex, methodRef.arguments);
try (BeanResolutionContext.Path ignored = resolutionContext.getPath().pushMethodArgumentResolve(this, methodRef.methodName, argument, methodRef.arguments, methodRef.requiresReflection)) {
return resolveBean(resolutionContext, context, argument, qualifier, true);
}
}
use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method getPropertyPlaceholderValueForConstructorArgument.
/**
* 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
* @return The resolved bean
*/
@Internal
@UsedByGeneratedCode
protected final Object getPropertyPlaceholderValueForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex, String propertyValue) {
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, null, true);
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 getBeansOfTypeForMethodArgument.
/**
* Obtains all bean definitions for a method argument at the given index.
* <p>
*
* @param resolutionContext The resolution context
* @param context The context
* @param methodIndex The method index
* @param argumentIndex The argument index
* @param genericType The generic type
* @param qualifier The qualifier
* @return The resolved bean
*/
@Internal
@UsedByGeneratedCode
protected final Collection<Object> getBeansOfTypeForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argumentIndex, Argument genericType, Qualifier qualifier) {
MethodReference methodRef = methodInjection[methodIndex];
Argument argument = resolveArgument(context, argumentIndex, methodRef.arguments);
try (BeanResolutionContext.Path ignored = resolutionContext.getPath().pushMethodArgumentResolve(this, methodRef.methodName, argument, methodRef.arguments, methodRef.requiresReflection)) {
return resolveBeansOfType(resolutionContext, context, argument, resolveEnvironmentArgument(context, genericType), qualifier);
}
}
use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method getStreamOfTypeForField.
/**
* Obtains a bean definition 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 Stream getStreamOfTypeForField(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 resolveStreamOfType(resolutionContext, context, argument, resolveEnvironmentArgument(context, genericType), qualifier);
}
}
use of io.micronaut.core.annotation.UsedByGeneratedCode in project micronaut-core by micronaut-projects.
the class AnnotationMetadataWriter method instantiateNewMetadataHierarchy.
/**
* Writes out the byte code necessary to instantiate the given {@link AnnotationMetadataHierarchy}.
*
* @param owningType The owning type
* @param classWriter The declaring class writer
* @param generatorAdapter The generator adapter
* @param hierarchy The annotation metadata
* @param defaultsStorage The annotation defaults
* @param loadTypeMethods The generated load type methods
*/
@Internal
@UsedByGeneratedCode
public static void instantiateNewMetadataHierarchy(Type owningType, ClassWriter classWriter, GeneratorAdapter generatorAdapter, AnnotationMetadataHierarchy hierarchy, Map<String, Integer> defaultsStorage, Map<String, GeneratorAdapter> loadTypeMethods) {
if (hierarchy.isEmpty()) {
generatorAdapter.getStatic(Type.getType(AnnotationMetadata.class), "EMPTY_METADATA", Type.getType(AnnotationMetadata.class));
return;
}
List<AnnotationMetadata> notEmpty = CollectionUtils.iterableToList(hierarchy).stream().filter(h -> !h.isEmpty()).collect(Collectors.toList());
if (notEmpty.size() == 1) {
pushNewAnnotationMetadataOrReference(owningType, classWriter, generatorAdapter, defaultsStorage, loadTypeMethods, notEmpty.get(0));
return;
}
generatorAdapter.visitTypeInsn(NEW, TYPE_DEFAULT_ANNOTATION_METADATA_HIERARCHY.getInternalName());
generatorAdapter.visitInsn(DUP);
pushNewArray(generatorAdapter, AnnotationMetadata.class, 2);
pushStoreInArray(generatorAdapter, 0, 2, () -> {
final AnnotationMetadata rootMetadata = hierarchy.getRootMetadata();
pushNewAnnotationMetadataOrReference(owningType, classWriter, generatorAdapter, defaultsStorage, loadTypeMethods, rootMetadata);
});
pushStoreInArray(generatorAdapter, 1, 2, () -> {
final AnnotationMetadata declaredMetadata = hierarchy.getDeclaredMetadata();
pushNewAnnotationMetadataOrReference(owningType, classWriter, generatorAdapter, defaultsStorage, loadTypeMethods, declaredMetadata);
});
// invoke the constructor
generatorAdapter.invokeConstructor(TYPE_DEFAULT_ANNOTATION_METADATA_HIERARCHY, CONSTRUCTOR_ANNOTATION_METADATA_HIERARCHY);
}
Aggregations