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.BindsInstance; 22 import dagger.hilt.DefineComponent; 23 import dagger.hilt.EntryPoint; 24 import dagger.hilt.InstallIn; 25 import dagger.hilt.android.EarlyEntryPointHiltAndroidTestRuntimeClasses.MySubcomponentScoped; 26 import dagger.hilt.android.EarlyEntryPointHiltAndroidTestRuntimeTest.Bar; 27 import dagger.hilt.android.EarlyEntryPointHiltAndroidTestRuntimeTest.Foo; 28 import dagger.hilt.components.SingletonComponent; 29 import java.lang.annotation.Retention; 30 import javax.inject.Scope; 31 32 /** Classes for {@link EarlyEntryPointHiltAndroidTestRuntimeTest}. */ 33 public final class EarlyEntryPointHiltAndroidTestRuntimeClasses { EarlyEntryPointHiltAndroidTestRuntimeClasses()34 private EarlyEntryPointHiltAndroidTestRuntimeClasses() {} 35 36 // @EarlyEntryPoint cannot be nested in tests, so we've separated it out into this class. 37 @EarlyEntryPoint 38 @InstallIn(SingletonComponent.class) 39 interface EarlyFooEntryPoint { foo()40 Foo foo(); 41 } 42 43 // @EarlyEntryPoint cannot be nested in tests, so we've separated it out into this class. 44 @EarlyEntryPoint 45 @InstallIn(SingletonComponent.class) 46 interface EarlyMySubcomponentBuilderEntryPoint { mySubcomponentBuilder()47 MySubcomponent.Builder mySubcomponentBuilder(); 48 } 49 50 @Scope 51 @Retention(RUNTIME) 52 public @interface MySubcomponentScoped {} 53 54 @MySubcomponentScoped 55 @DefineComponent(parent = SingletonComponent.class) 56 public interface MySubcomponent { 57 @DefineComponent.Builder 58 interface Builder { 59 @BindsInstance id(int id)60 Builder id(int id); 61 build()62 MySubcomponent build(); 63 } 64 } 65 66 // This needs to be defined outside the test so that it gets installed in the early component. 67 @EntryPoint 68 @InstallIn(SingletonComponent.class) 69 interface MySubcomponentBuilderEntryPoint { mySubcomponentBuilder()70 MySubcomponent.Builder mySubcomponentBuilder(); 71 } 72 73 // This needs to be defined outside the test so that it gets installed in the early component. 74 @EntryPoint 75 @InstallIn(MySubcomponent.class) 76 interface BarEntryPoint { bar()77 Bar bar(); 78 } 79 } 80