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.android; 18 19 import dagger.hilt.GeneratesRootInput; 20 import java.lang.annotation.ElementType; 21 import java.lang.annotation.Target; 22 23 /** 24 * Marks an Android component class to be setup for injection with the standard Hilt Dagger Android 25 * components. Currently, this supports activities, fragments, views, services, and broadcast 26 * receivers. 27 * 28 * <p>This annotation will generate a base class that the annotated class should extend, either 29 * directly or via the Hilt Gradle Plugin. This base class will take care of injecting members into 30 * the Android class as well as handling instantiating the proper Hilt components at the right point 31 * in the lifecycle. The name of the base class will be "Hilt_<annotated class name>". 32 * 33 * <p>Example usage (with the Hilt Gradle Plugin): 34 * 35 * <pre><code> 36 * {@literal @}AndroidEntryPoint 37 * public final class FooActivity extends FragmentActivity { 38 * {@literal @}Inject Foo foo; 39 * 40 * {@literal @}Override 41 * public void onCreate(Bundle savedInstanceState) { 42 * super.onCreate(savedInstanceState); // The foo field is injected in super.onCreate() 43 * } 44 * } 45 * </code></pre> 46 * 47 * <p>Example usage (without the Hilt Gradle Plugin): 48 * 49 * <pre><code> 50 * {@literal @}AndroidEntryPoint(FragmentActivity.class) 51 * public final class FooActivity extends Hilt_FooActivity { 52 * {@literal @}Inject Foo foo; 53 * 54 * {@literal @}Override 55 * public void onCreate(Bundle savedInstanceState) { 56 * super.onCreate(savedInstanceState); // The foo field is injected in super.onCreate() 57 * } 58 * } 59 * </code></pre> 60 * 61 * @see HiltAndroidApp 62 */ 63 @Target({ElementType.TYPE}) 64 @GeneratesRootInput 65 public @interface AndroidEntryPoint { 66 67 /** 68 * The base class for the generated Hilt class. When applying the Hilt Gradle Plugin this value 69 * is not necessary and will be inferred from the current superclass. 70 */ value()71 Class<?> value() default Void.class; 72 } 73