1 /* 2 * Copyright (C) 2007 Google Inc. 3 * Copyright (C) 2012 Square, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package dagger; 18 19 import dagger.internal.Beta; 20 import java.lang.annotation.Documented; 21 import java.lang.annotation.Retention; 22 import java.lang.annotation.Target; 23 24 import static java.lang.annotation.ElementType.METHOD; 25 import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 27 /** 28 * Annotates methods of a module to create a provider method binding. The 29 * method's return type is bound to its returned value. The object graph will 30 * pass dependencies to the method as parameters. 31 * 32 * @author Bob Lee 33 */ 34 @Documented @Target(METHOD) @Retention(RUNTIME) 35 public @interface Provides { 36 /** The type of binding into which the return type of the annotated method contributes. */ 37 enum Type { 38 /** 39 * The method is the only one which can produce the value for the specified return type. This 40 * is the default behavior. 41 */ 42 UNIQUE, 43 44 /** 45 * The method's return type forms the generic type argument of a {@code Set<T>}, and the 46 * returned value is contributed to the set. The object graph will pass dependencies to the 47 * method as parameters. The {@code Set<T>} produced from the accumulation of values will be 48 * immutable. 49 * 50 */ 51 SET, 52 53 /** 54 * Like {@link #SET}, except the method's return type is {@code Set<T>}, where any values are 55 * contributed to the set. An example use is to provide a default empty set binding, which is 56 * otherwise not possible using {@link #SET}. 57 * 58 */ 59 SET_VALUES, 60 61 /** 62 * The method's return type forms the type argument for the value of a 63 * {@code Map<K, Provider<V>>}, and the combination of the annotated key and the returned value 64 * is contributed to the map as a key/value pair. The {@code Map<K, Provider<V>>} produced from 65 * the accumulation of values will be immutable. 66 * 67 */ 68 @Beta 69 MAP; 70 } 71 type()72 Type type() default Type.UNIQUE; 73 } 74