• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.internal.codegen;
18 
19 import com.google.auto.value.AutoValue;
20 import dagger.model.Key;
21 
22 /**
23  * The framework class and binding key for a resolved dependency of a binding. If a binding has
24  * several dependencies for a key, then only one instance of this class will represent them all.
25  *
26  * <p>In the following example, the binding {@code provideFoo()} has two dependency requests:
27  *
28  * <ol>
29  *   <li>{@code Bar bar}
30  *   <li>{@code Provider<Bar> barProvider}
31  * </ol>
32  *
33  * But they both can be satisfied with the same instance of {@code Provider<Bar>}. So one instance
34  * of {@code FrameworkDependency} will be used for both. Its {@link #key()} will be for {@code Bar},
35  * and its {@link #frameworkType()} will be {@link FrameworkType#PROVIDER}.
36  *
37  * <pre><code>
38  *   {@literal @Provides} static Foo provideFoo(Bar bar, {@literal Provider<Bar>} barProvider) {
39  *     return new Foo(…);
40  *   }
41  * </code></pre>
42  */
43 @AutoValue
44 abstract class FrameworkDependency {
45 
46   /** The fully-resolved key shared by all the dependency requests. */
key()47   abstract Key key();
48 
49   /** The type of the framework dependency. */
frameworkType()50   abstract FrameworkType frameworkType();
51 
52   /** The framework class to use for this dependency. */
frameworkClass()53   final Class<?> frameworkClass() {
54     return frameworkType().frameworkClass();
55   }
56 
57   /** Returns a new instance with the given key and type. */
create(Key key, FrameworkType frameworkType)58   static FrameworkDependency create(Key key, FrameworkType frameworkType) {
59     return new AutoValue_FrameworkDependency(key, frameworkType);
60   }
61 }
62