• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Dagger Authors.
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 dagger.model;
18 
19 /** Represents the different kinds of {@link Binding}s that can exist in a binding graph. */
20 public enum BindingKind {
21   /** A binding for an {@link javax.inject.Inject}-annotated constructor. */
22   INJECTION,
23 
24   /** A binding for a {@link dagger.Provides}-annotated method. */
25   PROVISION,
26 
27   /**
28    * A binding for an {@link javax.inject.Inject}-annotated constructor that contains at least one
29    * {@link dagger.assisted.Assisted}-annotated parameter.
30    */
31   ASSISTED_INJECTION,
32 
33   /** A binding for an {@link dagger.assisted.AssistedFactory}-annotated type. */
34   ASSISTED_FACTORY,
35 
36   /**
37    * An implicit binding for a {@link dagger.Component}- or {@link
38    * dagger.producers.ProductionComponent}-annotated type.
39    */
40   COMPONENT,
41 
42   /**
43    * A binding for a provision method on a component's {@linkplain dagger.Component#dependencies()
44    * dependency}.
45    */
46   COMPONENT_PROVISION,
47 
48   /**
49    * A binding for an instance of a component's {@linkplain dagger.Component#dependencies()
50    * dependency}.
51    */
52   COMPONENT_DEPENDENCY,
53 
54   /** A binding for a {@link dagger.MembersInjector} of a type. */
55   MEMBERS_INJECTOR,
56 
57   /**
58    * A binding for a subcomponent creator (a {@linkplain dagger.Subcomponent.Builder builder} or
59    * {@linkplain dagger.Subcomponent.Factory factory}).
60    *
61    * @since 2.22 (previously named {@code SUBCOMPONENT_BUILDER})
62    */
63   SUBCOMPONENT_CREATOR,
64 
65   /** A binding for a {@link dagger.BindsInstance}-annotated builder method. */
66   BOUND_INSTANCE,
67 
68   /** A binding for a {@link dagger.producers.Produces}-annotated method. */
69   PRODUCTION,
70 
71   /**
72    * A binding for a production method on a production component's {@linkplain
73    * dagger.producers.ProductionComponent#dependencies()} dependency} that returns a {@link
74    * com.google.common.util.concurrent.ListenableFuture} or {@link
75    * com.google.common.util.concurrent.FluentFuture}. Methods on production component dependencies
76    * that don't return a future are considered {@linkplain #COMPONENT_PROVISION component provision
77    * bindings}.
78    */
79   COMPONENT_PRODUCTION,
80 
81   /**
82    * A synthetic binding for a multibound set that depends on individual multibinding {@link
83    * #PROVISION} or {@link #PRODUCTION} contributions.
84    */
85   MULTIBOUND_SET,
86 
87   /**
88    * A synthetic binding for a multibound map that depends on the individual multibinding {@link
89    * #PROVISION} or {@link #PRODUCTION} contributions.
90    */
91   MULTIBOUND_MAP,
92 
93   /**
94    * A synthetic binding for {@code Optional} of a type or a {@link javax.inject.Provider}, {@link
95    * dagger.Lazy}, or {@code Provider} of {@code Lazy} of a type. Generated by a {@link
96    * dagger.BindsOptionalOf} declaration.
97    */
98   OPTIONAL,
99 
100   /**
101    * A binding for {@link dagger.Binds}-annotated method that that delegates from requests for one
102    * key to another.
103    */
104   // TODO(dpb,ronshapiro): This name is confusing and could use work. Not all usages of @Binds
105   // bindings are simple delegations and we should have a name that better reflects that
106   DELEGATE,
107 
108   /** A binding for a members injection method on a component. */
109   MEMBERS_INJECTION,
110   ;
111 
112   /**
113    * Returns {@code true} if this is a kind of multibinding (not a contribution to a multibinding,
114    * but the multibinding itself).
115    */
isMultibinding()116   public boolean isMultibinding() {
117     switch (this) {
118       case MULTIBOUND_MAP:
119       case MULTIBOUND_SET:
120         return true;
121 
122       default:
123         return false;
124     }
125   }
126 }
127