1 /* 2 * Copyright (C) 2018 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.internal.codegen; 18 19 import dagger.Module; 20 import dagger.Provides; 21 import dagger.internal.codegen.base.SourceFileGenerator; 22 import dagger.internal.codegen.binding.MembersInjectionBinding; 23 import dagger.internal.codegen.binding.ProductionBinding; 24 import dagger.internal.codegen.binding.ProvisionBinding; 25 import dagger.internal.codegen.compileroption.CompilerOptions; 26 import dagger.internal.codegen.writing.FactoryGenerator; 27 import dagger.internal.codegen.writing.HjarSourceFileGenerator; 28 import dagger.internal.codegen.writing.MembersInjectorGenerator; 29 import dagger.internal.codegen.writing.ModuleGenerator; 30 import dagger.internal.codegen.writing.ModuleProxies.ModuleConstructorProxyGenerator; 31 import dagger.internal.codegen.writing.ProducerFactoryGenerator; 32 import javax.lang.model.element.TypeElement; 33 34 @Module 35 abstract class SourceFileGeneratorsModule { 36 37 @Provides factoryGenerator( FactoryGenerator generator, CompilerOptions compilerOptions)38 static SourceFileGenerator<ProvisionBinding> factoryGenerator( 39 FactoryGenerator generator, CompilerOptions compilerOptions) { 40 return hjarWrapper(generator, compilerOptions); 41 } 42 43 @Provides producerFactoryGenerator( ProducerFactoryGenerator generator, CompilerOptions compilerOptions)44 static SourceFileGenerator<ProductionBinding> producerFactoryGenerator( 45 ProducerFactoryGenerator generator, CompilerOptions compilerOptions) { 46 return hjarWrapper(generator, compilerOptions); 47 } 48 49 @Provides membersInjectorGenerator( MembersInjectorGenerator generator, CompilerOptions compilerOptions)50 static SourceFileGenerator<MembersInjectionBinding> membersInjectorGenerator( 51 MembersInjectorGenerator generator, CompilerOptions compilerOptions) { 52 return hjarWrapper(generator, compilerOptions); 53 } 54 55 @Provides 56 @ModuleGenerator moduleConstructorProxyGenerator( ModuleConstructorProxyGenerator generator, CompilerOptions compilerOptions)57 static SourceFileGenerator<TypeElement> moduleConstructorProxyGenerator( 58 ModuleConstructorProxyGenerator generator, CompilerOptions compilerOptions) { 59 return hjarWrapper(generator, compilerOptions); 60 } 61 hjarWrapper( SourceFileGenerator<T> generator, CompilerOptions compilerOptions)62 private static <T> SourceFileGenerator<T> hjarWrapper( 63 SourceFileGenerator<T> generator, CompilerOptions compilerOptions) { 64 return compilerOptions.headerCompilation() 65 ? HjarSourceFileGenerator.wrap(generator) 66 : generator; 67 } 68 } 69