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