1 /*
2  * Copyright (C) 2020 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.componentgenerator;
18 
19 import dagger.Binds;
20 import dagger.Module;
21 import dagger.internal.codegen.base.ClearableCache;
22 import dagger.internal.codegen.base.SourceFileGenerator;
23 import dagger.internal.codegen.binding.BindingGraph;
24 import dagger.internal.codegen.binding.ComponentDescriptor;
25 import dagger.multibindings.IntoSet;
26 
27 /** Provides bindings needed to generated the component. */
28 @Module(subcomponents = TopLevelImplementationComponent.class)
29 public interface ComponentGeneratorModule {
30 
31   @Binds
componentGenerator(ComponentGenerator generator)32   abstract SourceFileGenerator<BindingGraph> componentGenerator(ComponentGenerator generator);
33 
34   // The HjarSourceFileGenerator wrapper first generates the entire TypeSpec before stripping out
35   // things that aren't needed for the hjar. However, this can be really expensive for the component
36   // because it is usually the most expensive file to generate, and most of its content is not
37   // needed in the hjar. Thus, instead of wrapping the ComponentGenerator in HjarSourceFileGenerator
38   // we provide a completely separate processing step, ComponentHjarProcessingStep, and generator,
39   // ComponentHjarGenerator, for when generating hjars for components, which can avoid generating
40   // the parts of the component that would have been stripped out by the HjarSourceFileGenerator.
41   @Binds
componentHjarGenerator( ComponentHjarGenerator hjarGenerator)42   abstract SourceFileGenerator<ComponentDescriptor> componentHjarGenerator(
43       ComponentHjarGenerator hjarGenerator);
44 
45   @Binds
46   @IntoSet
componentImplementationFactory(ComponentImplementationFactory cache)47   ClearableCache componentImplementationFactory(ComponentImplementationFactory cache);
48 }
49