• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.internal.codegen;
18 
19 import com.google.auto.common.MoreElements;
20 import com.google.common.collect.ImmutableSet;
21 import dagger.producers.ProductionComponent;
22 import dagger.producers.ProductionSubcomponent;
23 import java.lang.annotation.Annotation;
24 import java.util.Set;
25 import javax.annotation.processing.Messager;
26 import javax.inject.Inject;
27 import javax.lang.model.element.TypeElement;
28 
29 /**
30  * A processing step that is responsible for generating a special module for a {@link
31  * ProductionComponent} or {@link ProductionSubcomponent}.
32  */
33 final class MonitoringModuleProcessingStep extends TypeCheckingProcessingStep<TypeElement> {
34   private final Messager messager;
35   private final MonitoringModuleGenerator monitoringModuleGenerator;
36 
37   @Inject
MonitoringModuleProcessingStep( Messager messager, MonitoringModuleGenerator monitoringModuleGenerator)38   MonitoringModuleProcessingStep(
39       Messager messager, MonitoringModuleGenerator monitoringModuleGenerator) {
40     super(MoreElements::asType);
41     this.messager = messager;
42     this.monitoringModuleGenerator = monitoringModuleGenerator;
43   }
44 
45   @Override
annotations()46   public Set<? extends Class<? extends Annotation>> annotations() {
47     return ImmutableSet.of(ProductionComponent.class, ProductionSubcomponent.class);
48   }
49 
50   @Override
process( TypeElement element, ImmutableSet<Class<? extends Annotation>> annotations)51   protected void process(
52       TypeElement element, ImmutableSet<Class<? extends Annotation>> annotations) {
53       monitoringModuleGenerator.generate(MoreElements.asType(element), messager);
54   }
55 }
56