sameb | e18906a | 2015-02-02 14:07:53 -0800 | [diff] [blame] | 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; |
sameb | e18906a | 2015-02-02 14:07:53 -0800 | [diff] [blame] | 21 | |
| 22 | import java.lang.annotation.Annotation; |
| 23 | import 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 McCann | bac730f | 2015-04-21 16:21:01 -0700 | [diff] [blame^] | 28 | * |
| 29 | * @since 4.0 |
sameb | e18906a | 2015-02-02 14:07:53 -0800 | [diff] [blame] | 30 | */ |
| 31 | public abstract class ModuleAnnotatedMethodScanner { |
sameb | e18906a | 2015-02-02 14:07:53 -0800 | [diff] [blame] | 32 | |
| 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 | } |