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.processor.internal.generatesrootinput; 18 19 import androidx.room.compiler.processing.JavaPoetExtKt; 20 import androidx.room.compiler.processing.XFiler.Mode; 21 import androidx.room.compiler.processing.XProcessingEnv; 22 import androidx.room.compiler.processing.XTypeElement; 23 import com.squareup.javapoet.AnnotationSpec; 24 import com.squareup.javapoet.JavaFile; 25 import com.squareup.javapoet.TypeSpec; 26 import dagger.hilt.processor.internal.ClassNames; 27 import dagger.hilt.processor.internal.Processors; 28 29 /** Generates resource files for {@link GeneratesRootInputs}. */ 30 final class GeneratesRootInputPropagatedDataGenerator { 31 private final XProcessingEnv processingEnv; 32 private final XTypeElement element; 33 GeneratesRootInputPropagatedDataGenerator(XProcessingEnv processingEnv, XTypeElement element)34 GeneratesRootInputPropagatedDataGenerator(XProcessingEnv processingEnv, XTypeElement element) { 35 this.processingEnv = processingEnv; 36 this.element = element; 37 } 38 generate()39 void generate() { 40 TypeSpec.Builder generator = TypeSpec.classBuilder(Processors.getFullEnclosedName(element)); 41 42 JavaPoetExtKt.addOriginatingElement(generator, element) 43 .addAnnotation( 44 AnnotationSpec.builder(ClassNames.GENERATES_ROOT_INPUT_PROPAGATED_DATA) 45 .addMember("value", "$T.class", element.getClassName()) 46 .build()) 47 .addJavadoc( 48 "Generated class to get the list of annotations that generate input for root.\n"); 49 50 Processors.addGeneratedAnnotation(generator, processingEnv, getClass()); 51 JavaFile javaFile = 52 JavaFile.builder(GeneratesRootInputs.AGGREGATING_PACKAGE, generator.build()).build(); 53 processingEnv.getFiler().write(javaFile, Mode.Isolating); 54 } 55 } 56