Search in sources :

Example 31 with ParameterElement

use of io.micronaut.inject.ast.ParameterElement in project micronaut-core by micronaut-projects.

the class BeanDefinitionWriter method applyConfigurationInjectionIfNecessary.

private void applyConfigurationInjectionIfNecessary(MethodElement constructor) {
    final boolean isRecordConfig = isRecordConfig(constructor);
    if (isRecordConfig || constructor.hasAnnotation(ConfigurationInject.class)) {
        final List<String> injectionTypes = Arrays.asList(Property.class.getName(), Value.class.getName(), Parameter.class.getName(), AnnotationUtil.QUALIFIER, AnnotationUtil.INJECT);
        if (isRecordConfig) {
            final List<PropertyElement> beanProperties = constructor.getDeclaringType().getBeanProperties();
            final ParameterElement[] parameters = constructor.getParameters();
            if (beanProperties.size() == parameters.length) {
                for (int i = 0; i < parameters.length; i++) {
                    ParameterElement parameter = parameters[i];
                    final PropertyElement bp = beanProperties.get(i);
                    final AnnotationMetadata beanPropertyMetadata = bp.getAnnotationMetadata();
                    AnnotationMetadata annotationMetadata = parameter.getAnnotationMetadata();
                    if (injectionTypes.stream().noneMatch(beanPropertyMetadata::hasStereotype)) {
                        processConfigurationConstructorParameter(parameter, annotationMetadata);
                    }
                    if (annotationMetadata.hasStereotype(ANN_CONSTRAINT)) {
                        setValidated(true);
                    }
                }
            } else {
                processConfigurationInjectionConstructor(constructor, injectionTypes);
            }
        } else {
            processConfigurationInjectionConstructor(constructor, injectionTypes);
        }
    }
}
Also used : ConfigurationInject(io.micronaut.context.annotation.ConfigurationInject) AbstractConstructorInjectionPoint(io.micronaut.context.AbstractConstructorInjectionPoint) ConstructorInjectionPoint(io.micronaut.inject.ConstructorInjectionPoint) MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) DefaultAnnotationMetadata(io.micronaut.inject.annotation.DefaultAnnotationMetadata) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Value(io.micronaut.context.annotation.Value) Parameter(io.micronaut.context.annotation.Parameter) ParameterElement(io.micronaut.inject.ast.ParameterElement) Property(io.micronaut.context.annotation.Property) EachProperty(io.micronaut.context.annotation.EachProperty) PropertyElement(io.micronaut.inject.ast.PropertyElement)

Example 32 with ParameterElement

use of io.micronaut.inject.ast.ParameterElement in project micronaut-core by micronaut-projects.

the class BeanDefinitionWriter method visitExecutableMethod.

/**
 * Visit a method that is to be made executable allow invocation of said method without reflection.
 *
 * @param declaringType                    The declaring type of the method. Either a Class or a string representing the
 *                                         name of the type
 * @param methodElement                    The method element
 * @param interceptedProxyClassName        The intercepted proxy class name
 * @param interceptedProxyBridgeMethodName The intercepted proxy bridge method name
 * @return The index of a new method.
 */
public int visitExecutableMethod(TypedElement declaringType, MethodElement methodElement, String interceptedProxyClassName, String interceptedProxyBridgeMethodName) {
    AnnotationMetadata annotationMetadata = methodElement.getAnnotationMetadata();
    DefaultAnnotationMetadata.contributeDefaults(this.annotationMetadata, annotationMetadata);
    for (ParameterElement parameterElement : methodElement.getSuspendParameters()) {
        DefaultAnnotationMetadata.contributeDefaults(this.annotationMetadata, parameterElement.getAnnotationMetadata());
        DefaultAnnotationMetadata.contributeRepeatable(this.annotationMetadata, parameterElement.getGenericType());
    }
    if (executableMethodsDefinitionWriter == null) {
        executableMethodsDefinitionWriter = new ExecutableMethodsDefinitionWriter(beanDefinitionName, getBeanDefinitionReferenceClassName(), originatingElements);
    }
    return executableMethodsDefinitionWriter.visitExecutableMethod(declaringType, methodElement, interceptedProxyClassName, interceptedProxyBridgeMethodName);
}
Also used : ParameterElement(io.micronaut.inject.ast.ParameterElement) MutableAnnotationMetadata(io.micronaut.inject.annotation.MutableAnnotationMetadata) DefaultAnnotationMetadata(io.micronaut.inject.annotation.DefaultAnnotationMetadata) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata)

Aggregations

ParameterElement (io.micronaut.inject.ast.ParameterElement)32 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)13 ClassElement (io.micronaut.inject.ast.ClassElement)13 Type (org.objectweb.asm.Type)13 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)13 DefaultAnnotationMetadata (io.micronaut.inject.annotation.DefaultAnnotationMetadata)12 MethodElement (io.micronaut.inject.ast.MethodElement)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AbstractConstructorInjectionPoint (io.micronaut.context.AbstractConstructorInjectionPoint)7 Label (org.objectweb.asm.Label)7 Argument (io.micronaut.core.type.Argument)6 ConstructorInjectionPoint (io.micronaut.inject.ConstructorInjectionPoint)6 MutableAnnotationMetadata (io.micronaut.inject.annotation.MutableAnnotationMetadata)6 TypedElement (io.micronaut.inject.ast.TypedElement)6 Map (java.util.Map)6 AnnotationMetadataReference (io.micronaut.inject.annotation.AnnotationMetadataReference)5 FieldElement (io.micronaut.inject.ast.FieldElement)5 HashMap (java.util.HashMap)5 ClassWriter (org.objectweb.asm.ClassWriter)5