Class ConfigurableAssistedAnnotationStrategy<A extends java.lang.annotation.Annotation,​P>

  • Type Parameters:
    A - the argument annotation type
    P - 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 of AssistedAnnotationStrategy which 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 the Class of the marker annotation to indicate a producer should be provided by the assisted injection extension.
      java.lang.String determineArgumentName​(java.lang.reflect.AccessibleObject accessibleObject)
      Determines the name of the argument given an argument annotation and an AccessibleObject.
      java.lang.String determineArgumentName​(java.lang.reflect.Parameter parameter)
      Determines the name of the argument given an argument annotation and a Parameter.
      java.lang.annotation.Annotation injectAnnotation()
      Returns the inject annotation supported by the associated injector.
      boolean isArgument​(java.lang.reflect.AnnotatedElement annotatedElement)
      Checks if the given AnnotatedElement is annotated as an argument.
      java.lang.Class<P> providerClass()
      Returns the Class of the provider type that can be used with the associated injector.
      java.lang.Object provision​(P provider)
      Return the result of calling the given provider P.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 annotation Class to use as marker annotation, cannot be null
        argument - an argument annotation Class to use to mark arguments, cannot be null
        argumentNameGetter - a getter Function to extract the argument name from an argument annotation, cannot be null
        inject - an inject Annotation supported by the associated injector to mark producers with, cannot be null
        provider - a provider class supported by the associated injector to use for producer fields, cannot be null
        providerGetter - a getter Function to extract the value from the provider class, cannot be null
    • Method Detail

      • assistedAnnotationClass

        public java.lang.Class<? extends java.lang.annotation.Annotation> assistedAnnotationClass()
        Description copied from interface: AssistedAnnotationStrategy
        Returns the Class of the marker annotation to indicate a producer should be provided by the assisted injection extension.
        Specified by:
        assistedAnnotationClass in interface AssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>
        Returns:
        an annotation Class for the assisted annotation, never null
      • isArgument

        public boolean isArgument​(java.lang.reflect.AnnotatedElement annotatedElement)
        Description copied from interface: AssistedAnnotationStrategy
        Checks if the given AnnotatedElement is annotated as an argument.
        Specified by:
        isArgument in interface AssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>
        Parameters:
        annotatedElement - an AnnotatedElement, cannot be null
        Returns:
        true if the element was annotated as an argument, otherwise false
      • determineArgumentName

        public java.lang.String determineArgumentName​(java.lang.reflect.AccessibleObject accessibleObject)
        Description copied from interface: AssistedAnnotationStrategy
        Determines the name of the argument given an argument annotation and an AccessibleObject. The AccessibleObject provided 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:
        determineArgumentName in interface AssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>
        Parameters:
        accessibleObject - an AccessibleObject, cannot be null
        Returns:
        an argument name, never null
      • determineArgumentName

        public java.lang.String determineArgumentName​(java.lang.reflect.Parameter parameter)
                                               throws MissingArgumentException
        Description copied from interface: AssistedAnnotationStrategy
        Determines the name of the argument given an argument annotation and a Parameter.

        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:
        determineArgumentName in interface AssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>
        Parameters:
        parameter - a Parameter, cannot be null
        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: AssistedAnnotationStrategy
        Returns the inject annotation supported by the associated injector.
        Specified by:
        injectAnnotation in interface AssistedAnnotationStrategy<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: AssistedAnnotationStrategy
        Returns the Class of the provider type that can be used with the associated injector.
        Specified by:
        providerClass in interface AssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>
        Returns:
        a provider Class supported by the associated injector, never null
      • provision

        public java.lang.Object provision​(P provider)
        Description copied from interface: AssistedAnnotationStrategy
        Return the result of calling the given provider P.
        Specified by:
        provision in interface AssistedAnnotationStrategy<A extends java.lang.annotation.Annotation>
        Parameters:
        provider - a provider P, cannot be null
        Returns:
        a result of calling the given provider, can be null