• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.BindsInstance;
20 import dagger.Module;
21 import dagger.Provides;
22 import dagger.Subcomponent;
23 import dagger.internal.codegen.binding.BindingGraph;
24 import dagger.internal.codegen.writing.ComponentImplementation;
25 import dagger.internal.codegen.writing.ComponentImplementation.ChildComponentImplementationFactory;
26 import dagger.internal.codegen.writing.ComponentRequestRepresentations;
27 import dagger.internal.codegen.writing.ComponentRequirementExpressions;
28 import dagger.internal.codegen.writing.ParentComponent;
29 import dagger.internal.codegen.writing.PerComponentImplementation;
30 import java.util.Optional;
31 import javax.inject.Provider;
32 
33 /**
34  * A subcomponent that injects all objects that are responsible for creating a single {@link
35  * ComponentImplementation} instance. Each child {@link ComponentImplementation} will have its own
36  * instance of {@link CurrentImplementationSubcomponent}.
37  */
38 @Subcomponent(
39     modules = CurrentImplementationSubcomponent.ChildComponentImplementationFactoryModule.class)
40 @PerComponentImplementation
41 // This only needs to be public because the type is referenced by generated component.
42 public interface CurrentImplementationSubcomponent {
componentImplementation()43   ComponentImplementation componentImplementation();
44 
45   /** A module to bind the {@link ChildComponentImplementationFactory}. */
46   @Module
47   interface ChildComponentImplementationFactoryModule {
48     @Provides
provideChildComponentImplementationFactory( CurrentImplementationSubcomponent.Builder currentImplementationSubcomponentBuilder, Provider<ComponentImplementation> componentImplementation, Provider<ComponentRequestRepresentations> componentRequestRepresentations, Provider<ComponentRequirementExpressions> componentRequirementExpressions)49     static ChildComponentImplementationFactory provideChildComponentImplementationFactory(
50         CurrentImplementationSubcomponent.Builder currentImplementationSubcomponentBuilder,
51         Provider<ComponentImplementation> componentImplementation,
52         Provider<ComponentRequestRepresentations> componentRequestRepresentations,
53         Provider<ComponentRequirementExpressions> componentRequirementExpressions) {
54       return childGraph ->
55           currentImplementationSubcomponentBuilder
56               .bindingGraph(childGraph)
57               .parentImplementation(Optional.of(componentImplementation.get()))
58               .parentRequestRepresentations(Optional.of(componentRequestRepresentations.get()))
59               .parentRequirementExpressions(Optional.of(componentRequirementExpressions.get()))
60               .build()
61               .componentImplementation();
62     }
63   }
64 
65   /** Returns the builder for {@link CurrentImplementationSubcomponent}. */
66   @Subcomponent.Builder
67   interface Builder {
68     @BindsInstance
bindingGraph(BindingGraph bindingGraph)69     Builder bindingGraph(BindingGraph bindingGraph);
70 
71     @BindsInstance
parentImplementation( @arentComponent Optional<ComponentImplementation> parentImplementation)72     Builder parentImplementation(
73         @ParentComponent Optional<ComponentImplementation> parentImplementation);
74 
75     @BindsInstance
parentRequestRepresentations( @arentComponent Optional<ComponentRequestRepresentations> parentRequestRepresentations)76     Builder parentRequestRepresentations(
77         @ParentComponent Optional<ComponentRequestRepresentations> parentRequestRepresentations);
78 
79     @BindsInstance
parentRequirementExpressions( @arentComponent Optional<ComponentRequirementExpressions> parentRequirementExpressions)80     Builder parentRequirementExpressions(
81         @ParentComponent Optional<ComponentRequirementExpressions> parentRequirementExpressions);
82 
build()83     CurrentImplementationSubcomponent build();
84   }
85 }
86