Class ConfigurableAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation,P>
- java.lang.Object
-
- org.int4.dirk.extensions.assisted.ConfigurableAssistedAnnotationStrategy<A,P>
-
- Type Parameters:
A- the argument annotation typeP- the provider type
- All Implemented Interfaces:
AssistedAnnotationStrategy<P>
public class ConfigurableAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation,P> extends java.lang.Object implements AssistedAnnotationStrategy<P>
An implementation ofAssistedAnnotationStrategywhich can be configured with custom annotations and which extract argument names via the given argument annotation or determines them by parameter, field or method name.
-
-
Constructor Summary
Constructors Constructor Description ConfigurableAssistedAnnotationStrategy(java.lang.Class<? extends java.lang.annotation.Annotation> assisted, java.lang.Class<A> argument, java.util.function.Function<java.lang.reflect.AnnotatedElement,java.lang.String> argumentNameGetter, java.lang.annotation.Annotation inject, java.lang.Class<P> provider, java.util.function.Function<P,java.lang.Object> providerGetter)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class<? extends java.lang.annotation.Annotation>assistedAnnotationClass()Returns theClassof the marker annotation to indicate a producer should be provided by the assisted injection extension.java.lang.StringdetermineArgumentName(java.lang.reflect.AccessibleObject accessibleObject)Determines the name of the argument given an argument annotation and anAccessibleObject.java.lang.StringdetermineArgumentName(java.lang.reflect.Parameter parameter)Determines the name of the argument given an argument annotation and aParameter.java.lang.annotation.AnnotationinjectAnnotation()Returns the inject annotation supported by the associated injector.booleanisArgument(java.lang.reflect.AnnotatedElement annotatedElement)Checks if the givenAnnotatedElementis annotated as an argument.java.lang.Class<P>providerClass()Returns theClassof the provider type that can be used with the associated injector.java.lang.Objectprovision(P provider)Return the result of calling the given providerP.
-
-
-
Constructor Detail
-
ConfigurableAssistedAnnotationStrategy
public ConfigurableAssistedAnnotationStrategy(java.lang.Class<? extends java.lang.annotation.Annotation> assisted, java.lang.Class<A> argument, java.util.function.Function<java.lang.reflect.AnnotatedElement,java.lang.String> argumentNameGetter, java.lang.annotation.Annotation inject, java.lang.Class<P> provider, java.util.function.Function<P,java.lang.Object> providerGetter)Constructs a new instance.- Parameters:
assisted- an assisted annotationClassto use as marker annotation, cannot benullargument- an argument annotationClassto use to mark arguments, cannot benullargumentNameGetter- a getterFunctionto extract the argument name from an argument annotation, cannot benullinject- an injectAnnotationsupported by the associated injector to mark producers with, cannot benullprovider- a provider class supported by the associated injector to use for producer fields, cannot benullproviderGetter- a getterFunctionto extract the value from the provider class, cannot benull
-
-
Method Detail
-
assistedAnnotationClass
public java.lang.Class<? extends java.lang.annotation.Annotation> assistedAnnotationClass()
Description copied from interface:AssistedAnnotationStrategyReturns theClassof the marker annotation to indicate a producer should be provided by the assisted injection extension.- Specified by:
assistedAnnotationClassin interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Returns:
- an annotation
Classfor the assisted annotation, nevernull
-
isArgument
public boolean isArgument(java.lang.reflect.AnnotatedElement annotatedElement)
Description copied from interface:AssistedAnnotationStrategyChecks if the givenAnnotatedElementis annotated as an argument.- Specified by:
isArgumentin interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Parameters:
annotatedElement- anAnnotatedElement, cannot benull- Returns:
trueif the element was annotated as an argument, otherwisefalse
-
determineArgumentName
public java.lang.String determineArgumentName(java.lang.reflect.AccessibleObject accessibleObject)
Description copied from interface:AssistedAnnotationStrategyDetermines the name of the argument given an argument annotation and anAccessibleObject. TheAccessibleObjectprovided is either a method or a field.Returning
null, although allowed, is considered a fatal problem and will result in an exception indicating the argument name must be provided somehow.- Specified by:
determineArgumentNamein interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Parameters:
accessibleObject- anAccessibleObject, cannot benull- Returns:
- an argument name, never
null
-
determineArgumentName
public java.lang.String determineArgumentName(java.lang.reflect.Parameter parameter) throws MissingArgumentExceptionDescription copied from interface:AssistedAnnotationStrategyDetermines the name of the argument given an argument annotation and aParameter.Returning
null, although allowed, is considered a fatal problem and will result in an exception indicating the argument name must be provided somehow.- Specified by:
determineArgumentNamein interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Parameters:
parameter- aParameter, cannot benull- Returns:
- an argument name, never
null - Throws:
MissingArgumentException- when argument name could not be determined
-
injectAnnotation
public java.lang.annotation.Annotation injectAnnotation()
Description copied from interface:AssistedAnnotationStrategyReturns the inject annotation supported by the associated injector.- Specified by:
injectAnnotationin interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Returns:
- an inject annotation supported by the associated injector, never
null
-
providerClass
public java.lang.Class<P> providerClass()
Description copied from interface:AssistedAnnotationStrategyReturns theClassof the provider type that can be used with the associated injector.- Specified by:
providerClassin interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Returns:
- a provider
Classsupported by the associated injector, nevernull
-
provision
public java.lang.Object provision(P provider)
Description copied from interface:AssistedAnnotationStrategyReturn the result of calling the given providerP.- Specified by:
provisionin interfaceAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>- Parameters:
provider- a providerP, cannot benull- Returns:
- a result of calling the given provider, can be
null
-
-