• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.squareup.javapoet.AnnotationSpec;
20 import com.squareup.javapoet.JavaFile;
21 import com.squareup.javapoet.TypeSpec;
22 import dagger.hilt.processor.internal.ClassNames;
23 import dagger.hilt.processor.internal.Processors;
24 import java.io.IOException;
25 import javax.annotation.processing.ProcessingEnvironment;
26 import javax.lang.model.element.Element;
27 
28 /** Generates resource files for {@link GeneratesRootInputs}. */
29 final class GeneratesRootInputPropagatedDataGenerator {
30   private final ProcessingEnvironment processingEnv;
31   private final Element element;
32 
GeneratesRootInputPropagatedDataGenerator(ProcessingEnvironment processingEnv, Element element)33   GeneratesRootInputPropagatedDataGenerator(ProcessingEnvironment processingEnv, Element element) {
34     this.processingEnv = processingEnv;
35     this.element = element;
36   }
37 
generate()38   void generate() throws IOException {
39     TypeSpec.Builder generator =
40         TypeSpec.classBuilder(Processors.getFullEnclosedName(element))
41             .addOriginatingElement(element)
42             .addAnnotation(
43                 AnnotationSpec.builder(ClassNames.GENERATES_ROOT_INPUT_PROPAGATED_DATA)
44                     .addMember("value", "$T.class", element)
45                     .build())
46             .addJavadoc(
47                 "Generated class to"
48                     + "get the list of annotations that generate input for root.\n");
49 
50     Processors.addGeneratedAnnotation(generator, processingEnv, getClass());
51 
52     JavaFile.builder(GeneratesRootInputs.AGGREGATING_PACKAGE, generator.build())
53         .build()
54         .writeTo(processingEnv.getFiler());
55   }
56 }
57