xref: /aosp_15_r20/external/dagger2/java/dagger/model/BindingKind.java (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
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 {@code Component}- or {@code ProductionComponent}-annotated type.
38    */
39   COMPONENT,
40 
41   /**
42    * A binding for a provision method on a component's {@linkplain dagger.Component#dependencies()
43    * dependency}.
44    */
45   COMPONENT_PROVISION,
46 
47   /**
48    * A binding for an instance of a component's {@linkplain dagger.Component#dependencies()
49    * dependency}.
50    */
51   COMPONENT_DEPENDENCY,
52 
53   /** A binding for a {@link dagger.MembersInjector} of a type. */
54   MEMBERS_INJECTOR,
55 
56   /**
57    * A binding for a subcomponent creator (a {@linkplain dagger.Subcomponent.Builder builder} or
58    * {@linkplain dagger.Subcomponent.Factory factory}).
59    *
60    * @since 2.22 (previously named {@code SUBCOMPONENT_BUILDER})
61    */
62   SUBCOMPONENT_CREATOR,
63 
64   /** A binding for a {@link dagger.BindsInstance}-annotated builder method. */
65   BOUND_INSTANCE,
66 
67   /** A binding for a {@code Produces}-annotated method. */
68   PRODUCTION,
69 
70   /**
71    * A binding for a production method on a production component's
72    * {@code ProductionComponent#dependencies()} that returns a {@code ListenableFuture} or
73    * {@code FluentFuture}. Methods on production component dependencies
74    * that don't return a future are considered {@linkplain #COMPONENT_PROVISION component provision
75    * bindings}.
76    */
77   COMPONENT_PRODUCTION,
78 
79   /**
80    * A synthetic binding for a multibound set that depends on individual multibinding {@link
81    * #PROVISION} or {@link #PRODUCTION} contributions.
82    */
83   MULTIBOUND_SET,
84 
85   /**
86    * A synthetic binding for a multibound map that depends on the individual multibinding {@link
87    * #PROVISION} or {@link #PRODUCTION} contributions.
88    */
89   MULTIBOUND_MAP,
90 
91   /**
92    * A synthetic binding for {@code Optional} of a type or a {@link javax.inject.Provider}, {@link
93    * dagger.Lazy}, or {@code Provider} of {@code Lazy} of a type. Generated by a {@link
94    * dagger.BindsOptionalOf} declaration.
95    */
96   OPTIONAL,
97 
98   /**
99    * A binding for {@link dagger.Binds}-annotated method that delegates from requests for one
100    * key to another.
101    */
102   // TODO(dpb,ronshapiro): This name is confusing and could use work. Not all usages of @Binds
103   // bindings are simple delegations and we should have a name that better reflects that
104   DELEGATE,
105 
106   /** A binding for a members injection method on a component. */
107   MEMBERS_INJECTION,
108   ;
109 
110   /**
111    * Returns {@code true} if this is a kind of multibinding (not a contribution to a multibinding,
112    * but the multibinding itself).
113    */
isMultibinding()114   public boolean isMultibinding() {
115     switch (this) {
116       case MULTIBOUND_MAP:
117       case MULTIBOUND_SET:
118         return true;
119 
120       default:
121         return false;
122     }
123   }
124 }
125