Search in sources :

Example 6 with MutableAnnotationMetadata

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

the class BeanDefinitionWriter method pushInvokeGetBeanForSetter.

private void pushInvokeGetBeanForSetter(GeneratorAdapter injectMethodVisitor, String setterName, ParameterElement entry) {
    // load 'this'
    injectMethodVisitor.loadThis();
    // 1st argument load BeanResolutionContext
    injectMethodVisitor.loadArg(0);
    // 2nd argument load BeanContext
    injectMethodVisitor.loadArg(1);
    // 3rd argument the method name
    injectMethodVisitor.push(setterName);
    AnnotationMetadata annotationMetadata;
    if (entry.getAnnotationMetadata() instanceof MutableAnnotationMetadata) {
        annotationMetadata = ((MutableAnnotationMetadata) entry.getAnnotationMetadata()).clone();
        removeAnnotations(annotationMetadata, PropertySource.class.getName(), Property.class.getName());
    } else {
        annotationMetadata = entry.getAnnotationMetadata();
    }
    // 4th argument the argument
    if (keepConfPropInjectPoints) {
        resolveMethodArgument(injectMethodVisitor, currentMethodIndex, 0);
    } else {
        pushCreateArgument(beanFullClassName, beanDefinitionType, classWriter, injectMethodVisitor, entry.getName(), entry.getGenericType(), annotationMetadata, entry.getGenericType().getTypeArguments(), new HashMap<>(), loadTypeMethods);
    }
    // push qualifier
    pushQualifier(injectMethodVisitor, entry.getGenericType(), injectMethodVisitor::dup);
    pushInvokeMethodOnSuperClass(injectMethodVisitor, GET_BEAN_FOR_SETTER);
    // cast the return value to the correct type
    pushCastToType(injectMethodVisitor, entry);
}
Also used : MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) Property(io.micronaut.context.annotation.Property) EachProperty(io.micronaut.context.annotation.EachProperty) MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) DefaultAnnotationMetadata(io.micronaut.inject.annotation.DefaultAnnotationMetadata) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) PropertySource(io.micronaut.context.annotation.PropertySource)

Example 7 with MutableAnnotationMetadata

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

the class BeanDefinitionWriter method pushInvokeGetBeansOfTypeForSetter.

private void pushInvokeGetBeansOfTypeForSetter(GeneratorAdapter injectMethodVisitor, String setterName, ParameterElement entry) {
    // load 'this'
    injectMethodVisitor.loadThis();
    // 1st argument load BeanResolutionContext
    injectMethodVisitor.loadArg(0);
    // 2nd argument load BeanContext
    injectMethodVisitor.loadArg(1);
    // 3rd argument the method name
    injectMethodVisitor.push(setterName);
    AnnotationMetadata annotationMetadata;
    if (entry.getAnnotationMetadata() instanceof MutableAnnotationMetadata) {
        annotationMetadata = ((MutableAnnotationMetadata) entry.getAnnotationMetadata()).clone();
        removeAnnotations(annotationMetadata, PropertySource.class.getName(), Property.class.getName());
    } else {
        annotationMetadata = entry.getAnnotationMetadata();
    }
    // 4th argument the argument
    ClassElement genericType = entry.getGenericType();
    if (keepConfPropInjectPoints) {
        resolveMethodArgument(injectMethodVisitor, currentMethodIndex, 0);
    } else {
        pushCreateArgument(beanFullClassName, beanDefinitionType, classWriter, injectMethodVisitor, entry.getName(), genericType, annotationMetadata, genericType.getTypeArguments(), new HashMap<>(), loadTypeMethods);
    }
    int thisArgument = injectMethodVisitor.newLocal(Type.getType(Argument.class));
    injectMethodVisitor.storeLocal(thisArgument);
    injectMethodVisitor.loadLocal(thisArgument);
    if (!resolveArgumentGenericType(injectMethodVisitor, genericType)) {
        injectMethodVisitor.loadLocal(thisArgument);
        resolveFirstTypeArgument(injectMethodVisitor);
        resolveInnerTypeArgumentIfNeeded(injectMethodVisitor, genericType);
    } else {
        injectMethodVisitor.push((String) null);
    }
    // push qualifier
    pushQualifier(injectMethodVisitor, genericType, () -> injectMethodVisitor.loadLocal(thisArgument));
    pushInvokeMethodOnSuperClass(injectMethodVisitor, GET_BEANS_OF_TYPE_FOR_SETTER);
    // cast the return value to the correct type
    pushCastToType(injectMethodVisitor, entry);
}
Also used : MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) Argument(io.micronaut.core.type.Argument) DefaultArgument(io.micronaut.core.type.DefaultArgument) ClassElement(io.micronaut.inject.ast.ClassElement) Property(io.micronaut.context.annotation.Property) EachProperty(io.micronaut.context.annotation.EachProperty) MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) DefaultAnnotationMetadata(io.micronaut.inject.annotation.DefaultAnnotationMetadata) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) AbstractConstructorInjectionPoint(io.micronaut.context.AbstractConstructorInjectionPoint) ConstructorInjectionPoint(io.micronaut.inject.ConstructorInjectionPoint) PropertySource(io.micronaut.context.annotation.PropertySource)

Aggregations

MutableAnnotationMetadata (io.micronaut.inject.annotation.MutableAnnotationMetadata)7 EachProperty (io.micronaut.context.annotation.EachProperty)6 Property (io.micronaut.context.annotation.Property)6 PropertySource (io.micronaut.context.annotation.PropertySource)6 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)4 DefaultAnnotationMetadata (io.micronaut.inject.annotation.DefaultAnnotationMetadata)4 AbstractConstructorInjectionPoint (io.micronaut.context.AbstractConstructorInjectionPoint)1 NonNull (io.micronaut.core.annotation.NonNull)1 Argument (io.micronaut.core.type.Argument)1 DefaultArgument (io.micronaut.core.type.DefaultArgument)1 ConstructorInjectionPoint (io.micronaut.inject.ConstructorInjectionPoint)1 ClassElement (io.micronaut.inject.ast.ClassElement)1