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.plugin.root 18 19 import com.squareup.javapoet.AnnotationSpec 20 import com.squareup.javapoet.ClassName 21 import com.squareup.javapoet.JavaFile 22 import com.squareup.javapoet.TypeSpec 23 import dagger.hilt.processor.internal.root.ir.AggregatedElementProxyIr 24 import java.io.File 25 import javax.lang.model.element.Modifier 26 27 internal class AggregatedElementProxyGenerator( 28 private val outputDir: File, 29 ) { 30 generatenull31 fun generate(aggregatedElementProxy: AggregatedElementProxyIr) { 32 val typeSpec = TypeSpec.classBuilder(aggregatedElementProxy.fqName) 33 .addAnnotation( 34 AnnotationSpec.builder(AGGREGATED_ELEMENT_PROXY_ANNOTATION) 35 .addMember("value", "\$T.class", aggregatedElementProxy.value) 36 .build() 37 ) 38 .addModifiers(Modifier.PUBLIC, Modifier.FINAL) 39 .build() 40 JavaFile.builder(aggregatedElementProxy.fqName.packageName(), typeSpec) 41 .build() 42 .writeTo(outputDir) 43 } 44 45 companion object { 46 val AGGREGATED_ELEMENT_PROXY_ANNOTATION = 47 ClassName.get("dagger.hilt.android.internal.legacy", "AggregatedElementProxy") 48 } 49 } 50