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 static androidx.room.compiler.processing.XElementKt.isTypeElement; 20 import static dagger.internal.codegen.xprocessing.XElements.asTypeElement; 21 22 import androidx.room.compiler.processing.XElement; 23 import androidx.room.compiler.processing.XProcessingEnv; 24 import com.google.common.collect.ImmutableSet; 25 import com.squareup.javapoet.ClassName; 26 import dagger.hilt.processor.internal.BaseProcessingStep; 27 import dagger.hilt.processor.internal.ClassNames; 28 import dagger.hilt.processor.internal.ProcessorErrors; 29 import dagger.internal.codegen.xprocessing.XElements; 30 31 /** 32 * Processes the annotations annotated with {@link dagger.hilt.GeneratesRootInput} which generate 33 * input for components and should be processed before component creation. 34 */ 35 public final class GeneratesRootInputProcessingStep extends BaseProcessingStep { GeneratesRootInputProcessingStep(XProcessingEnv env)36 public GeneratesRootInputProcessingStep(XProcessingEnv env) { 37 super(env); 38 } 39 40 @Override annotationClassNames()41 protected ImmutableSet<ClassName> annotationClassNames() { 42 return ImmutableSet.of(ClassNames.GENERATES_ROOT_INPUT); 43 } 44 45 @Override processEach(ClassName annotation, XElement element)46 public void processEach(ClassName annotation, XElement element) { 47 ProcessorErrors.checkState( 48 isTypeElement(element) && asTypeElement(element).isAnnotationClass(), 49 element, 50 "%s should only annotate other annotations. However, it was found annotating %s", 51 annotation.simpleName(), 52 XElements.toStableString(element)); 53 54 new GeneratesRootInputPropagatedDataGenerator(processingEnv(), asTypeElement(element)) 55 .generate(); 56 } 57 } 58