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 androidx.room.compiler.processing.XTypeElement; 20 import com.google.common.collect.ImmutableList; 21 import com.squareup.javapoet.AnnotationSpec; 22 import dagger.hilt.processor.internal.ClassNames; 23 import dagger.hilt.processor.internal.Processors; 24 25 /** 26 * Generates an {@link dagger.hilt.android.internal.uninstallmodules.AggregatedUninstallModules} 27 * annotation. 28 */ 29 final class AggregatedUninstallModulesGenerator { 30 31 private final XTypeElement testElement; 32 private final ImmutableList<XTypeElement> uninstallModuleElements; 33 AggregatedUninstallModulesGenerator( XTypeElement testElement, ImmutableList<XTypeElement> uninstallModuleElements)34 AggregatedUninstallModulesGenerator( 35 XTypeElement testElement, 36 ImmutableList<XTypeElement> uninstallModuleElements) { 37 this.testElement = testElement; 38 this.uninstallModuleElements = uninstallModuleElements; 39 } 40 generate()41 void generate() { 42 Processors.generateAggregatingClass( 43 ClassNames.AGGREGATED_UNINSTALL_MODULES_PACKAGE, 44 aggregatedUninstallModulesAnnotation(), 45 testElement, 46 getClass()); 47 } 48 aggregatedUninstallModulesAnnotation()49 private AnnotationSpec aggregatedUninstallModulesAnnotation() { 50 AnnotationSpec.Builder builder = 51 AnnotationSpec.builder(ClassNames.AGGREGATED_UNINSTALL_MODULES); 52 builder.addMember("test", "$S", testElement.getQualifiedName()); 53 uninstallModuleElements.stream() 54 .map(XTypeElement::getQualifiedName) 55 .forEach(uninstallModule -> builder.addMember("uninstallModules", "$S", uninstallModule)); 56 return builder.build(); 57 } 58 } 59