• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.writing;
18 
19 import static com.google.common.base.Preconditions.checkNotNull;
20 
21 import com.squareup.javapoet.ClassName;
22 import dagger.assisted.Assisted;
23 import dagger.assisted.AssistedFactory;
24 import dagger.assisted.AssistedInject;
25 import dagger.internal.codegen.binding.ComponentRequirement;
26 import dagger.internal.codegen.binding.ContributionBinding;
27 import dagger.internal.codegen.javapoet.Expression;
28 
29 /**
30  * A binding expression for instances bound with {@link dagger.BindsInstance} and instances of
31  * {@linkplain dagger.Component#dependencies() component} and {@linkplain
32  * dagger.producers.ProductionComponent#dependencies() production component dependencies}.
33  */
34 final class ComponentRequirementRequestRepresentation extends RequestRepresentation {
35   private final ComponentRequirement componentRequirement;
36   private final ComponentRequirementExpressions componentRequirementExpressions;
37 
38   @AssistedInject
ComponentRequirementRequestRepresentation( @ssisted ContributionBinding binding, @Assisted ComponentRequirement componentRequirement, ComponentRequirementExpressions componentRequirementExpressions)39   ComponentRequirementRequestRepresentation(
40       @Assisted ContributionBinding binding,
41       @Assisted ComponentRequirement componentRequirement,
42       ComponentRequirementExpressions componentRequirementExpressions) {
43     this.componentRequirement = checkNotNull(componentRequirement);
44     this.componentRequirementExpressions = componentRequirementExpressions;
45   }
46 
47   @Override
getDependencyExpression(ClassName requestingClass)48   Expression getDependencyExpression(ClassName requestingClass) {
49     return Expression.create(
50         componentRequirement.type(),
51         componentRequirementExpressions.getExpression(componentRequirement, requestingClass));
52   }
53 
54   @AssistedFactory
55   static interface Factory {
create( ContributionBinding binding, ComponentRequirement componentRequirement)56     ComponentRequirementRequestRepresentation create(
57         ContributionBinding binding, ComponentRequirement componentRequirement);
58   }
59 }
60