Class BeanInjectionUtils
java.lang.Object
io.micronaut.inject.utils.BeanInjectionUtils
Utility methods for creating
BeanDefinitionInjectionPoint instances.- Since:
- 5.1.0
- Author:
- Denis Stepanov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateConstructorDefinition(MethodElement constructorElement, AnnotationMetadata annotationMetadata, VisitorContext visitorContext, boolean requiresReflection) Creates aConstructorDefinitionusing the provided annotation metadata.createConstructorDefinition(MethodElement constructorElement, VisitorContext visitorContext) Creates aConstructorDefinitionfor the supplied constructor.createConstructorDefinition(MethodElement constructorElement, VisitorContext visitorContext, boolean requiresReflection) Creates aConstructorDefinitionfor the supplied constructor.static FieldDefinition<ClassElement, FieldElement> createFieldDefinition(ClassElement beanType, FieldElement fieldElement, boolean requiresReflection, VisitorContext visitorContext) Creates aFieldDefinitiondescribing injection for the supplied field.static MethodDefinition<ClassElement, MethodElement> createMethodDefinition(ClassElement beanType, MethodElement methodElement, AnnotationMetadata annotationMetadata, boolean requiresReflection, VisitorContext visitorContext) Creates aMethodDefinitiondescribing injection for the supplied method.createValueInjectionPoint(ClassElement beanType, ClassElement genericType, AnnotationMetadata annotationMetadata, boolean requiresReflection, String name, VisitorContext visitorContext) static Optional<MethodElement> findBeanConstructor(ClassElement classElement) Finds the constructor a bean of the given type is instantiated with.getInjectionPoint(ClassElement beanType, ClassElement genericType, AnnotationMetadata annotationMetadata, String parameterName, VisitorContext visitorContext) Resolves the appropriateBeanDefinitionInjectionPointfor the given element.static voidvalidateBeanConstructor(ClassElement classElement) Validates that a constructor selected for injection can be invoked.
-
Constructor Details
-
BeanInjectionUtils
public BeanInjectionUtils()
-
-
Method Details
-
createFieldDefinition
public static FieldDefinition<ClassElement, FieldElement> createFieldDefinition(ClassElement beanType, FieldElement fieldElement, boolean requiresReflection, VisitorContext visitorContext) Creates aFieldDefinitiondescribing injection for the supplied field.- Parameters:
beanType- The declaring bean typefieldElement- The field elementrequiresReflection- Whether reflective access is requiredvisitorContext- The visitor context- Returns:
- The field definition
-
createMethodDefinition
public static MethodDefinition<ClassElement, MethodElement> createMethodDefinition(ClassElement beanType, MethodElement methodElement, AnnotationMetadata annotationMetadata, boolean requiresReflection, VisitorContext visitorContext) Creates aMethodDefinitiondescribing injection for the supplied method.- Parameters:
beanType- The declaring bean typemethodElement- The method elementannotationMetadata- The method annotation metadatarequiresReflection- Whether reflective access is requiredvisitorContext- The visitor context- Returns:
- The method definition
-
createConstructorDefinition
public static ConstructorDefinition<ClassElement, MethodElement> createConstructorDefinition(MethodElement constructorElement, VisitorContext visitorContext) Creates aConstructorDefinitionfor the supplied constructor.- Parameters:
constructorElement- The constructor elementvisitorContext- The visitor context- Returns:
- The constructor definition
-
findBeanConstructor
Finds the constructor a bean of the given type is instantiated with.This is
ClassElement.getPrimaryConstructor()extended to private constructors, which that lookup never selects. A private constructor annotated withAnnotationUtil.INJECTorCreatortakes precedence over an unannotated accessible one when it is annotated withReflectiveAccess, and a type whose only constructor is private is instantiated with it only when it is annotated withReflectiveAccess. A private constructor is invoked with reflection, as private injected fields and methods are.- Parameters:
classElement- The bean type- Returns:
- The constructor, or a static creator method, if one is found
- Since:
- 5.2.1
-
validateBeanConstructor
Validates that a constructor selected for injection can be invoked.A private constructor is invoked with reflection, which has to be opted into with
ReflectiveAccess. Without itfindBeanConstructor(ClassElement)skips the constructor, so the injection the annotation asks for would silently not happen.- Parameters:
classElement- The bean type- Throws:
ProcessingException- if a constructor asks for injection but cannot be invoked- Since:
- 5.2.1
-
createConstructorDefinition
public static ConstructorDefinition<ClassElement, MethodElement> createConstructorDefinition(MethodElement constructorElement, VisitorContext visitorContext, boolean requiresReflection) Creates aConstructorDefinitionfor the supplied constructor.- Parameters:
constructorElement- The constructor elementvisitorContext- The visitor contextrequiresReflection- Whether reflective access is required- Returns:
- The constructor definition
-
createConstructorDefinition
public static ConstructorDefinition<ClassElement, MethodElement> createConstructorDefinition(MethodElement constructorElement, AnnotationMetadata annotationMetadata, VisitorContext visitorContext, boolean requiresReflection) Creates aConstructorDefinitionusing the provided annotation metadata.- Parameters:
constructorElement- The constructor elementannotationMetadata- The annotation metadatavisitorContext- The visitor contextrequiresReflection- Whether reflective access is required- Returns:
- The constructor definition
-
createValueInjectionPoint
public static BeanDefinitionInjectionPoint<ClassElement> createValueInjectionPoint(ClassElement beanType, ClassElement genericType, AnnotationMetadata annotationMetadata, boolean requiresReflection, String name, VisitorContext visitorContext) - Parameters:
beanType- The bean type declaring the injection pointgenericType- The injected typeannotationMetadata- The associated annotation metadatarequiresReflection- Whether reflective access is requiredname- The element namevisitorContext- The visitor context- Returns:
- The injection point
-
getInjectionPoint
public static BeanDefinitionInjectionPoint<ClassElement> getInjectionPoint(ClassElement beanType, ClassElement genericType, AnnotationMetadata annotationMetadata, String parameterName, VisitorContext visitorContext) Resolves the appropriateBeanDefinitionInjectionPointfor the given element.- Parameters:
beanType- The bean type declaring the injection pointgenericType- The injected typeannotationMetadata- The associated annotation metadataparameterName- The element namevisitorContext- The visitor context- Returns:
- The injection point
-