Class ModuleAnnotatedMethodScanner
- java.lang.Object
-
- com.google.inject.spi.ModuleAnnotatedMethodScanner
-
public abstract class ModuleAnnotatedMethodScanner extends Object
Allows extensions to scan modules for annotated methods and bind those methods as providers, similar to@Provides
methods.- Since:
- 4.0
-
-
Constructor Summary
Constructors Constructor Description ModuleAnnotatedMethodScanner()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract Set<? extends Class<? extends Annotation>>
annotationClasses()
Returns the annotations this should scan for.<T> Key<T>
prepareMethod(Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint)
Deprecated.Prefer overriding the overload that takes `Object moduleInstance` instead.<T> Key<T>
prepareMethod(Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint, Object moduleInstance)
Prepares a method for binding.
-
-
-
Method Detail
-
annotationClasses
public abstract Set<? extends Class<? extends Annotation>> annotationClasses()
Returns the annotations this should scan for. Every method in the module that has one of these annotations will create a Provider binding, with the return value of the binding being what's provided and the parameters of the method being dependencies of the provider.
-
prepareMethod
@Deprecated public <T> Key<T> prepareMethod(Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint)
Deprecated.Prefer overriding the overload that takes `Object moduleInstance` instead. If not overridden, that method will invoke this one to aid in backwards compatibility.Prepares a method for binding. Thiskey
parameter is the key discovered from looking at the binding annotation and return value of the method. Implementations can modify the key to instead bind to another key. For example, Multibinder may want to change@ProvidesIntoSet String provideFoo()
to bind into a unique Key within the multibinder instead of bindingString
.The injection point and annotation are provided in case the implementation wants to set the key based on the property of the annotation or if any additional preparation is needed for any of the dependencies. The annotation is guaranteed to be an instance of one the classes returned by
annotationClasses()
.Returning null will cause Guice to skip this method, so that it is not bound to any key.
If
injectionPoint
represents anabstract
method,null
must be returned from this method. This scanner can usebinder
to bind alternative bindings in place of the abstract method.
-
prepareMethod
public <T> Key<T> prepareMethod(Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint, @Nullable Object moduleInstance)
Prepares a method for binding. Thiskey
parameter is the key discovered from looking at the binding annotation and return value of the method. Implementations can modify the key to instead bind to another key. For example, Multibinder may want to change@ProvidesIntoSet String provideFoo()
to bind into a unique Key within the multibinder instead of bindingString
.The injection point and annotation are provided in case the implementation wants to set the key based on the property of the annotation or if any additional preparation is needed for any of the dependencies. The annotation is guaranteed to be an instance of one the classes returned by
annotationClasses()
.Returning null will cause Guice to skip this method, so that it is not bound to any key.
If
injectionPoint
represents anabstract
method,null
must be returned from this method. This scanner can usebinder
to bind alternative bindings in place of the abstract method.The
moduleInstance
parameter contains the Module instance that is currently being scanned, which may be null if the methods were discovered on Module class objects (as opposed to module instances).
-
-