xref: /aosp_15_r20/external/dagger2/java/dagger/spi/model/BindingKind.java (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
1 /*
2  * Copyright (C) 2021 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.spi.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 {@code ProductionComponent}-annotated
38    * 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 {@code Produces}-annotated method. */
69   PRODUCTION,
70 
71   /**
72    * A binding for a production method on a production component's
73    * {@code ProductionComponent#dependencies()} that returns a {@code ListenableFuture} or
74    * {@code FluentFuture}. Methods on production component dependencies
75    * that don't return a future are considered component provision 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 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