|
20 | 20 | import com.google.inject.Key;
|
21 | 21 | import java.lang.annotation.Annotation;
|
22 | 22 | import java.util.Set;
|
| 23 | +import javax.annotation.Nullable; |
23 | 24 |
|
24 | 25 | /**
|
25 | 26 | * Allows extensions to scan modules for annotated methods and bind those methods as providers,
|
@@ -53,7 +54,45 @@ public abstract class ModuleAnnotatedMethodScanner {
|
53 | 54 | * <p>If {@code injectionPoint} represents an {@code abstract} method, {@code null} must be
|
54 | 55 | * returned from this method. This scanner can use {@code binder} to bind alternative bindings in
|
55 | 56 | * place of the abstract method.
|
| 57 | + * |
| 58 | + * @deprecated Prefer overriding the overload that takes `Object moduleInstance` instead. If not |
| 59 | + * overridden, that method will invoke this one to aid in backwards compatibility. |
| 60 | + */ |
| 61 | + @Deprecated |
| 62 | + public <T> Key<T> prepareMethod( |
| 63 | + Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint) { |
| 64 | + throw new IllegalStateException( |
| 65 | + "'prepareMethod' not implemented, one override must be implemented."); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Prepares a method for binding. This {@code key} parameter is the key discovered from looking at |
| 70 | + * the binding annotation and return value of the method. Implementations can modify the key to |
| 71 | + * instead bind to another key. For example, Multibinder may want to change |
| 72 | + * {@code @ProvidesIntoSet String provideFoo()} to bind into a unique Key within the multibinder |
| 73 | + * instead of binding {@code String}. |
| 74 | + * |
| 75 | + * <p>The injection point and annotation are provided in case the implementation wants to set the |
| 76 | + * key based on the property of the annotation or if any additional preparation is needed for any |
| 77 | + * of the dependencies. The annotation is guaranteed to be an instance of one the classes returned |
| 78 | + * by {@link #annotationClasses}. |
| 79 | + * |
| 80 | + * <p>Returning null will cause Guice to skip this method, so that it is not bound to any key. |
| 81 | + * |
| 82 | + * <p>If {@code injectionPoint} represents an {@code abstract} method, {@code null} must be |
| 83 | + * returned from this method. This scanner can use {@code binder} to bind alternative bindings in |
| 84 | + * place of the abstract method. |
| 85 | + * |
| 86 | + * <p>The {@code moduleInstance} parameter contains the Module instance that is currently being |
| 87 | + * scanned, which may be null if the methods were discovered on Module class objects (as opposed |
| 88 | + * to module instances). |
56 | 89 | */
|
57 |
| - public abstract <T> Key<T> prepareMethod( |
58 |
| - Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint); |
| 90 | + public <T> Key<T> prepareMethod( |
| 91 | + Binder binder, |
| 92 | + Annotation annotation, |
| 93 | + Key<T> key, |
| 94 | + InjectionPoint injectionPoint, |
| 95 | + @Nullable Object moduleInstance) { |
| 96 | + return prepareMethod(binder, annotation, key, injectionPoint); |
| 97 | + } |
59 | 98 | }
|
0 commit comments