• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.processor.internal.uninstallmodules;
18 
19 import com.google.common.collect.ImmutableList;
20 import com.squareup.javapoet.AnnotationSpec;
21 import dagger.hilt.processor.internal.ClassNames;
22 import dagger.hilt.processor.internal.Processors;
23 import java.io.IOException;
24 import javax.annotation.processing.ProcessingEnvironment;
25 import javax.lang.model.element.TypeElement;
26 
27 /**
28  * Generates an {@link dagger.hilt.android.internal.uninstallmodules.AggregatedUninstallModules}
29  * annotation.
30  */
31 final class AggregatedUninstallModulesGenerator {
32 
33   private final ProcessingEnvironment env;
34   private final TypeElement testElement;
35   private final ImmutableList<TypeElement> uninstallModuleElements;
36 
AggregatedUninstallModulesGenerator( TypeElement testElement, ImmutableList<TypeElement> uninstallModuleElements, ProcessingEnvironment env)37   AggregatedUninstallModulesGenerator(
38       TypeElement testElement,
39       ImmutableList<TypeElement> uninstallModuleElements,
40       ProcessingEnvironment env) {
41     this.testElement = testElement;
42     this.uninstallModuleElements = uninstallModuleElements;
43     this.env = env;
44   }
45 
generate()46   void generate() throws IOException {
47     Processors.generateAggregatingClass(
48         ClassNames.AGGREGATED_UNINSTALL_MODULES_PACKAGE,
49         aggregatedUninstallModulesAnnotation(),
50         testElement,
51         getClass(),
52         env);
53   }
54 
aggregatedUninstallModulesAnnotation()55   private AnnotationSpec aggregatedUninstallModulesAnnotation() {
56     AnnotationSpec.Builder builder =
57         AnnotationSpec.builder(ClassNames.AGGREGATED_UNINSTALL_MODULES);
58     builder.addMember("test", "$S", testElement.getQualifiedName());
59     uninstallModuleElements.stream()
60         .map(TypeElement::getQualifiedName)
61         .forEach(uninstallModule -> builder.addMember("uninstallModules", "$S", uninstallModule));
62     return builder.build();
63   }
64 }
65