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.components.SingletonComponent; 26 import java.lang.annotation.Retention; 27 import javax.inject.Inject; 28 import javax.inject.Qualifier; 29 import javax.inject.Scope; 30 31 /** 32 * Subcomponent used to verify that subcomponents are correctly installed in shared test components. 33 */ 34 public abstract class UsesComponentTestClasses { 35 /** Qualifier for test bindings. */ 36 @Qualifier 37 public @interface UsesComponentQualifier {} 38 39 @UsesComponentTestSubcomponentScoped 40 public static class Foo { 41 final int id; 42 43 @Inject Foo(int id)44 Foo(int id) { 45 this.id = id; 46 } 47 } 48 49 @Scope 50 @Retention(RUNTIME) 51 public @interface UsesComponentTestSubcomponentScoped {} 52 53 @UsesComponentTestSubcomponentScoped 54 @DefineComponent(parent = SingletonComponent.class) 55 public interface UsesComponentTestSubcomponent { 56 @DefineComponent.Builder 57 interface Builder { 58 @BindsInstance id(int id)59 Builder id(int id); 60 build()61 UsesComponentTestSubcomponent build(); 62 } 63 } 64 65 @EntryPoint 66 @InstallIn(SingletonComponent.class) 67 public interface UsesComponentTestSubcomponentBuilderEntryPoint { mySubcomponentBuilder()68 UsesComponentTestSubcomponent.Builder mySubcomponentBuilder(); 69 } 70 71 @EntryPoint 72 @InstallIn(UsesComponentTestSubcomponent.class) 73 public interface FooEntryPoint { foo()74 Foo foo(); 75 } 76 UsesComponentTestClasses()77 private UsesComponentTestClasses() {} 78 } 79