1 /* 2 * Copyright (C) 2014 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 package dagger.producers; 17 18 import dagger.internal.Beta; 19 import com.google.common.util.concurrent.ListenableFuture; 20 import java.lang.annotation.Documented; 21 import java.lang.annotation.Target; 22 23 import static java.lang.annotation.ElementType.METHOD; 24 25 /** 26 * Annotates methods of a producer module to create a production binding. If the method returns 27 * a {@link ListenableFuture}, then the parameter type of the future is bound to the value that the 28 * future provides; otherwise, the return type is bound to the returned value. The production 29 * component will pass dependencies to the method as parameters. 30 * 31 * @author Jesse Beder 32 */ 33 @Documented 34 @Target(METHOD) 35 @Beta 36 public @interface Produces { 37 /** The type of binding into which the return type of the annotated method contributes. */ 38 enum Type { 39 /** 40 * The method is the only one which can produce the value for the specified type. This is the 41 * default behavior. 42 */ 43 UNIQUE, 44 45 /** 46 * The method's resulting type forms the generic type argument of a {@code Set<T>}, and the 47 * returned value or future is contributed to the set. The {@code Set<T>} produced from the 48 * accumulation of values will be immutable. 49 */ 50 SET, 51 52 /** 53 * Like {@link #SET}, except the method's return type is either {@code Set<T>} or 54 * {@code Set<ListenableFuture<T>>}, where any values are contributed to the set. An example use 55 * is to provide a default empty set binding, which is otherwise not possible using 56 * {@link #SET}. 57 */ 58 SET_VALUES, 59 60 /** 61 * The method's return type forms the type argument for the value of a 62 * {@code Map<K, Producer<V>>}, and the combination of the annotated key and the returned value 63 * is contributed to the map as a key/value pair. The {@code Map<K, Producer<V>>} produced from 64 * the accumulation of values will be immutable. 65 */ 66 MAP; 67 } 68 type()69 Type type() default Type.UNIQUE; 70 } 71