1 /* 2 * Copyright (C) 2015 Google, Inc. 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 package dagger.internal.codegen; 17 18 import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; 19 import com.google.common.collect.ImmutableSet; 20 import com.google.common.collect.SetMultimap; 21 import dagger.producers.ProductionComponent; 22 import java.lang.annotation.Annotation; 23 import java.util.Set; 24 import javax.annotation.processing.Messager; 25 import javax.lang.model.element.Element; 26 import javax.lang.model.element.TypeElement; 27 28 import static javax.lang.model.util.ElementFilter.typesIn; 29 30 /** 31 * A processing step that is responsible for generating a special module for a 32 * {@link ProductionComponent}. 33 */ 34 final class MonitoringModuleProcessingStep implements ProcessingStep { 35 private final Messager messager; 36 private final MonitoringModuleGenerator monitoringModuleGenerator; 37 MonitoringModuleProcessingStep( Messager messager, MonitoringModuleGenerator monitoringModuleGenerator)38 MonitoringModuleProcessingStep( 39 Messager messager, MonitoringModuleGenerator monitoringModuleGenerator) { 40 this.messager = messager; 41 this.monitoringModuleGenerator = monitoringModuleGenerator; 42 } 43 44 @Override annotations()45 public Set<? extends Class<? extends Annotation>> annotations() { 46 return ImmutableSet.of(ProductionComponent.class); 47 } 48 49 @Override process( SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation)50 public Set<Element> process( 51 SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) { 52 for (TypeElement element : typesIn(elementsByAnnotation.get(ProductionComponent.class))) { 53 try { 54 monitoringModuleGenerator.generate(element); 55 } catch (SourceFileGenerationException e) { 56 e.printMessageTo(messager); 57 } 58 } 59 return ImmutableSet.of(); 60 } 61 } 62