1 /*
2  * Copyright (C) 2015 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.inject.spi;
18 
19 import com.google.inject.Binder;
20 import com.google.inject.Key;
21 import java.lang.annotation.Annotation;
22 import java.util.Set;
23 
24 /**
25  * Allows extensions to scan modules for annotated methods and bind those methods as providers,
26  * similar to {@code @Provides} methods.
27  *
28  * @since 4.0
29  */
30 public abstract class ModuleAnnotatedMethodScanner {
31 
32   /**
33    * Returns the annotations this should scan for. Every method in the module that has one of these
34    * annotations will create a Provider binding, with the return value of the binding being what's
35    * provided and the parameters of the method being dependencies of the provider.
36    */
annotationClasses()37   public abstract Set<? extends Class<? extends Annotation>> annotationClasses();
38 
39   /**
40    * Prepares a method for binding. This {@code key} parameter is the key discovered from looking at
41    * the binding annotation and return value of the method. Implementations can modify the key to
42    * instead bind to another key. For example, Multibinder may want to change {@code @SetProvides
43    * String provideFoo()} to bind into a unique Key within the multibinder instead of binding {@code
44    * String}.
45    *
46    * <p>The injection point and annotation are provided in case the implementation wants to set the
47    * key based on the property of the annotation or if any additional preparation is needed for any
48    * of the dependencies. The annotation is guaranteed to be an instance of one the classes returned
49    * by {@link #annotationClasses}.
50    */
prepareMethod( Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint)51   public abstract <T> Key<T> prepareMethod(
52       Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint);
53 }
54