Package com.google.inject.internal
Class ProvidesMethodScanner
- java.lang.Object
-
- com.google.inject.spi.ModuleAnnotatedMethodScanner
-
- com.google.inject.internal.ProvidesMethodScanner
-
final class ProvidesMethodScanner extends ModuleAnnotatedMethodScanner
AModuleAnnotatedMethodScanner
that handles the ,ProvidesIntoSet
,ProvidesIntoMap
andProvidesIntoOptional
annotations.This is the default scanner used by ProviderMethodsModule and handles all the built in annotations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ProvidesMethodScanner.AnnotationOrError
private static class
ProvidesMethodScanner.TypeAndValue<T>
-
Field Summary
Fields Modifier and Type Field Description private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>>
ANNOTATIONS
(package private) static ProvidesMethodScanner
INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description private
ProvidesMethodScanner()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<? extends java.lang.Class<? extends java.lang.annotation.Annotation>>
annotationClasses()
Returns the annotations this should scan for.private static ProvidesMethodScanner.AnnotationOrError
findMapKeyAnnotation(Binder binder, java.lang.reflect.Method method)
<T> Key<T>
prepareMethod(Binder binder, java.lang.annotation.Annotation annotation, Key<T> key, InjectionPoint injectionPoint)
Prepares a method for binding.(package private) static ProvidesMethodScanner.TypeAndValue<?>
typeAndValueOfMapKey(java.lang.annotation.Annotation mapKeyAnnotation)
-
-
-
Field Detail
-
INSTANCE
static final ProvidesMethodScanner INSTANCE
-
ANNOTATIONS
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>> ANNOTATIONS
-
-
Method Detail
-
annotationClasses
public java.util.Set<? extends java.lang.Class<? extends java.lang.annotation.Annotation>> annotationClasses()
Description copied from class:ModuleAnnotatedMethodScanner
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.- Specified by:
annotationClasses
in classModuleAnnotatedMethodScanner
-
prepareMethod
public <T> Key<T> prepareMethod(Binder binder, java.lang.annotation.Annotation annotation, Key<T> key, InjectionPoint injectionPoint)
Description copied from class:ModuleAnnotatedMethodScanner
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
ModuleAnnotatedMethodScanner.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.- Specified by:
prepareMethod
in classModuleAnnotatedMethodScanner
-
findMapKeyAnnotation
private static ProvidesMethodScanner.AnnotationOrError findMapKeyAnnotation(Binder binder, java.lang.reflect.Method method)
-
typeAndValueOfMapKey
static ProvidesMethodScanner.TypeAndValue<?> typeAndValueOfMapKey(java.lang.annotation.Annotation mapKeyAnnotation)
-
-