• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.hilt;
18 
19 import static java.lang.annotation.ElementType.TYPE;
20 import static java.lang.annotation.RetentionPolicy.CLASS;
21 
22 import dagger.hilt.internal.definecomponent.DefineComponentNoParent;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.Target;
25 
26 /**
27  * Defines a Hilt component.
28  *
29  * <p>Example defining a root component, {@code ParentComponent}:
30  *
31  * <pre><code>
32  *   {@literal @}ParentScoped
33  *   {@literal @}DefineComponent
34  *   interface ParentComponent {}
35  * </code></pre>
36  *
37  * <p>Example defining a child component, {@code ChildComponent}:
38  *
39  * <pre><code>
40  *   {@literal @}ChildScoped
41  *   {@literal @}DefineComponent(parent = ParentComponent.class)
42  *   interface ChildComponent {}
43  * </code></pre>
44  */
45 @Retention(CLASS)
46 @Target(TYPE)
47 @GeneratesRootInput
48 public @interface DefineComponent {
49   /** Returns the parent of this component, if it exists. */
parent()50   Class<?> parent() default DefineComponentNoParent.class;
51 
52   /**
53    * Defines a builder for a Hilt component.
54    *
55    * <pre><code>
56    *   {@literal @}DefineComponent.Builder
57    *   interface ParentComponentBuilder {
58    *     ParentComponentBuilder seedData(SeedData seed);
59    *     ParentComponent build();
60    *   }
61    * </code></pre>
62    */
63   // TODO(bcorso): Consider making this a top-level class to hint that it doesn't need to be nested.
64   @Retention(CLASS)
65   @Target(TYPE)
66   @GeneratesRootInput
67   public @interface Builder {}
68 }
69