• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.hilt.android;
18 
19 import static java.lang.annotation.RetentionPolicy.RUNTIME;
20 
21 import dagger.internal.Beta;
22 import java.lang.annotation.ElementType;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.Target;
25 
26 /**
27  * An escape hatch for when a Hilt entry point usage needs to be called before the singleton
28  * component is available in a Hilt test.
29  *
30  * <p>Warning: Please see documentation for more details:
31  * https://dagger.dev/hilt/early-entry-point
32  *
33  * <p>Usage:
34  *
35  * <p>To enable an existing entry point to be called early in a Hilt test, replace its
36  * {@link dagger.hilt.EntryPoint} annotation with {@link EarlyEntryPoint}. (Note that,
37  * {@link EarlyEntryPoint} is only allowed on entry points installed in the
38  * {@link dagger.hilt.components.SingletonComponent}).
39  *
40  * <pre><code>
41  * @EarlyEntryPoint  // <- This replaces @EntryPoint
42  * @InstallIn(SingletonComponent.class)
43  * interface FooEntryPoint {
44  *   Foo getFoo();
45  * }
46  * </code></pre>
47  *
48  * <p>Then, replace any of the corresponding usages of {@link dagger.hilt.EntryPoints} with
49  * {@link EarlyEntryPoints}, as shown below:
50  *
51  * <pre><code>
52  * // EarlyEntryPoints.get() must be used with entry points annotated with @EarlyEntryPoint
53  * // This entry point can now be called at any point during a test, e.g. in Application.onCreate().
54  * Foo foo = EarlyEntryPoints.get(appContext, FooEntryPoint.class).getFoo();
55  * </code></pre>
56  */
57 @Beta
58 @Retention(RUNTIME) // Needs to be runtime for checks in EntryPoints and EarlyEntryPoints.
59 @Target(ElementType.TYPE)
60 public @interface EarlyEntryPoint {}
61