blob: 3c90825740e8ce5d3026cb22797a149bd6afc179 [file] [log] [blame]
samebe18906a2015-02-02 14:07:53 -08001/**
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
17package com.google.inject.spi;
18
19import com.google.inject.Binder;
20import com.google.inject.Key;
samebe18906a2015-02-02 14:07:53 -080021
22import java.lang.annotation.Annotation;
23import java.util.Set;
24
25/**
26 * Allows extensions to scan modules for annotated methods and bind those methods
27 * as providers, similar to {@code @Provides} methods.
Ben McCannbac730f2015-04-21 16:21:01 -070028 *
29 * @since 4.0
samebe18906a2015-02-02 14:07:53 -080030 */
31public abstract class ModuleAnnotatedMethodScanner {
samebe18906a2015-02-02 14:07:53 -080032
33 /**
34 * Returns the annotations this should scan for. Every method in the module that has one of these
35 * annotations will create a Provider binding, with the return value of the binding being what's
36 * provided and the parameters of the method being dependencies of the provider.
37 */
38 public abstract Set<? extends Class<? extends Annotation>> annotationClasses();
39
40 /**
41 * Prepares a method for binding. This {@code key} parameter is the key discovered from looking at
42 * the binding annotation and return value of the method. Implementations can modify the key to
43 * instead bind to another key. For example, Multibinder may want to change
44 * {@code @SetProvides String provideFoo()} to bind into a unique Key within the multibinder
45 * instead of binding {@code String}.
46 *
47 * <p>The injection point and annotation are provided in case the implementation wants to set the
48 * key based on the property of the annotation or if any additional preparation is needed for any
49 * of the dependencies. The annotation is guaranteed to be an instance of one the classes returned
50 * by {@link #annotationClasses}.
51 */
52 public abstract <T> Key<T> prepareMethod(Binder binder, Annotation annotation, Key<T> key,
53 InjectionPoint injectionPoint);
54
55}