15d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin/*
25d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Copyright (C) 2014 Google Inc.
35d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
45d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Licensed under the Apache License, Version 2.0 (the "License");
55d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * you may not use this file except in compliance with the License.
65d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * You may obtain a copy of the License at
75d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
85d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * http://www.apache.org/licenses/LICENSE-2.0
95d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
105d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Unless required by applicable law or agreed to in writing, software
115d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * distributed under the License is distributed on an "AS IS" BASIS,
125d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * See the License for the specific language governing permissions and
145d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * limitations under the License.
155d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin */
165d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinpackage dagger.producers;
175d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
185d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport dagger.internal.Beta;
195d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport com.google.common.util.concurrent.ListenableFuture;
205d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport java.lang.annotation.Documented;
215d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport java.lang.annotation.Target;
225d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
235d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinimport static java.lang.annotation.ElementType.METHOD;
245d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
255d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin/**
265d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * Annotates methods of a producer module to create a production binding. If the method returns
275d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * a {@link ListenableFuture}, then the parameter type of the future is bound to the value that the
285d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * future provides; otherwise, the return type is bound to the returned value. The production
295d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * component will pass dependencies to the method as parameters.
305d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin *
315d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin * @author Jesse Beder
325d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin */
335d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin@Documented
345d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin@Target(METHOD)
355d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin@Beta
365d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffinpublic @interface Produces {
375d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  /** The type of binding into which the return type of the annotated method contributes. */
385d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  enum Type {
395d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    /**
405d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * The method is the only one which can produce the value for the specified type. This is the
415d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * default behavior.
425d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     */
435d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    UNIQUE,
445d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
455d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    /**
465d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * The method's resulting type forms the generic type argument of a {@code Set<T>}, and the
475d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * returned value or future is contributed to the set. The {@code Set<T>} produced from the
485d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * accumulation of values will be immutable.
495d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     */
505d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    SET,
515d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
525d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    /**
535d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * Like {@link #SET}, except the method's return type is either {@code Set<T>} or
545d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * {@code Set<ListenableFuture<T>>}, where any values are contributed to the set. An example use
555d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * is to provide a default empty set binding, which is otherwise not possible using
565d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * {@link #SET}.
575d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     */
585d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    SET_VALUES,
595d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
605d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    /**
615d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * The method's return type forms the type argument for the value of a
625d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * {@code Map<K, Producer<V>>}, and the combination of the annotated key and the returned value
635d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * is contributed to the map as a key/value pair. The {@code Map<K, Producer<V>>} produced from
645d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     * the accumulation of values will be immutable.
655d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin     */
665d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin    MAP;
675d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  }
685d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin
695d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin  Type type() default Type.UNIQUE;
705d3207ac2713386ed61c6ca8f0356e8f093a62e1Paul Duffin}
71