Search in sources :

Example 1 with MutableAnnotationMetadata

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

the class BeanDefinitionWriter method pushInvokeGetPropertyPlaceholderValueForField.

private void pushInvokeGetPropertyPlaceholderValueForField(GeneratorAdapter injectMethodVisitor, FieldElement fieldElement, String value) {
    // load 'this'
    injectMethodVisitor.loadThis();
    // 1st argument load BeanResolutionContext
    injectMethodVisitor.loadArg(0);
    // 2nd argument load BeanContext
    injectMethodVisitor.loadArg(1);
    // 3rd argument the method index
    MutableAnnotationMetadata mutableAnnotationMetadata = ((MutableAnnotationMetadata) fieldElement.getAnnotationMetadata()).clone();
    removeAnnotations(mutableAnnotationMetadata, PropertySource.class.getName(), Property.class.getName());
    if (keepConfPropInjectPoints) {
        resolveFieldArgument(injectMethodVisitor, currentFieldIndex);
    } else {
        pushCreateArgument(beanFullClassName, beanDefinitionType, classWriter, injectMethodVisitor, fieldElement.getName(), fieldElement.getGenericType(), mutableAnnotationMetadata, fieldElement.getGenericType().getTypeArguments(), new HashMap<>(), loadTypeMethods);
    }
    // 4th property value
    injectMethodVisitor.push(value);
    pushInvokeMethodOnSuperClass(injectMethodVisitor, GET_PROPERTY_PLACEHOLDER_VALUE_FOR_FIELD);
    // cast the return value to the correct type
    pushCastToType(injectMethodVisitor, fieldElement.getType());
}
Also used : MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) Property(io.micronaut.context.annotation.Property) EachProperty(io.micronaut.context.annotation.EachProperty) PropertySource(io.micronaut.context.annotation.PropertySource)

Example 2 with MutableAnnotationMetadata

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

the class BeanDefinitionWriter method pushInvokeGetPropertyValueForSetter.

private void pushInvokeGetPropertyValueForSetter(GeneratorAdapter injectMethodVisitor, String setterName, ParameterElement entry, String value) {
    // 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);
    }
    // 5th property value
    injectMethodVisitor.push(value);
    // 6 cli property name
    injectMethodVisitor.push(getCliPrefix(entry.getName()));
    pushInvokeMethodOnSuperClass(injectMethodVisitor, GET_PROPERTY_VALUE_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 3 with MutableAnnotationMetadata

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

the class BeanDefinitionWriter method pushInvokeGetPropertyPlaceholderValueForSetter.

private void pushInvokeGetPropertyPlaceholderValueForSetter(GeneratorAdapter injectMethodVisitor, String setterName, ParameterElement entry, String value) {
    // 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);
    // 4th argument the argument
    AnnotationMetadata annotationMetadata;
    if (entry.getAnnotationMetadata() instanceof MutableAnnotationMetadata) {
        annotationMetadata = ((MutableAnnotationMetadata) entry.getAnnotationMetadata()).clone();
        removeAnnotations(annotationMetadata, PropertySource.class.getName(), Property.class.getName());
    } else {
        annotationMetadata = entry.getAnnotationMetadata();
    }
    if (keepConfPropInjectPoints) {
        resolveMethodArgument(injectMethodVisitor, currentMethodIndex, 0);
    } else {
        pushCreateArgument(beanFullClassName, beanDefinitionType, classWriter, injectMethodVisitor, entry.getName(), entry.getGenericType(), annotationMetadata, entry.getGenericType().getTypeArguments(), new HashMap<>(), loadTypeMethods);
    }
    // 5th property value
    injectMethodVisitor.push(value);
    // 6 cli property name
    injectMethodVisitor.push(getCliPrefix(entry.getName()));
    pushInvokeMethodOnSuperClass(injectMethodVisitor, GET_PROPERTY_PLACEHOLDER_VALUE_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 4 with MutableAnnotationMetadata

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

the class ReflectParameterElement method annotate.

@NonNull
@Override
public <T extends Annotation> Element annotate(@NonNull String annotationType, @NonNull Consumer<AnnotationValueBuilder<T>> consumer) {
    if (annotationMetadata == AnnotationMetadata.EMPTY_METADATA) {
        final MutableAnnotationMetadata mutableAnnotationMetadata = new MutableAnnotationMetadata();
        this.annotationMetadata = mutableAnnotationMetadata;
        AnnotationValueBuilder<T> builder = AnnotationValue.builder(annotationType);
        consumer.accept(builder);
        mutableAnnotationMetadata.addDeclaredAnnotation(annotationType, builder.build().getValues());
    } else {
        AnnotationValueBuilder<T> builder = AnnotationValue.builder(annotationType);
        consumer.accept(builder);
        this.annotationMetadata = DefaultAnnotationMetadata.mutateMember(annotationMetadata, annotationType, builder.build().getValues());
    }
    return this;
}
Also used : MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) NonNull(io.micronaut.core.annotation.NonNull)

Example 5 with MutableAnnotationMetadata

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

the class BeanDefinitionWriter method pushInvokeGetPropertyValueForField.

private void pushInvokeGetPropertyValueForField(GeneratorAdapter injectMethodVisitor, FieldElement fieldElement, String value) {
    // load 'this'
    injectMethodVisitor.loadThis();
    // 1st argument load BeanResolutionContext
    injectMethodVisitor.loadArg(0);
    // 2nd argument load BeanContext
    injectMethodVisitor.loadArg(1);
    // 3rd argument the method index
    MutableAnnotationMetadata mutableAnnotationMetadata = ((MutableAnnotationMetadata) fieldElement.getAnnotationMetadata()).clone();
    removeAnnotations(mutableAnnotationMetadata, PropertySource.class.getName(), Property.class.getName());
    if (keepConfPropInjectPoints) {
        resolveFieldArgument(injectMethodVisitor, currentFieldIndex);
    } else {
        pushCreateArgument(beanFullClassName, beanDefinitionType, classWriter, injectMethodVisitor, fieldElement.getName(), fieldElement.getGenericType(), mutableAnnotationMetadata, fieldElement.getGenericType().getTypeArguments(), new HashMap<>(), loadTypeMethods);
    }
    // 4th property value
    injectMethodVisitor.push(value);
    // 5th cli property name
    injectMethodVisitor.push(getCliPrefix(fieldElement.getName()));
    pushInvokeMethodOnSuperClass(injectMethodVisitor, GET_PROPERTY_VALUE_FOR_FIELD);
    // cast the return value to the correct type
    pushCastToType(injectMethodVisitor, fieldElement.getType());
}
Also used : MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) Property(io.micronaut.context.annotation.Property) EachProperty(io.micronaut.context.annotation.EachProperty) 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