• 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.binding;
18 
19 import dagger.internal.codegen.base.ElementFormatter;
20 import dagger.internal.codegen.model.BindingGraph.DependencyEdge;
21 import dagger.internal.codegen.model.DaggerElement;
22 import dagger.internal.codegen.model.DependencyRequest;
23 
24 /** An implementation of {@link DependencyEdge}. */
25 final class DependencyEdgeImpl implements DependencyEdge {
26 
27   private final DependencyRequest dependencyRequest;
28   private final boolean entryPoint;
29 
DependencyEdgeImpl(DependencyRequest dependencyRequest, boolean entryPoint)30   DependencyEdgeImpl(DependencyRequest dependencyRequest, boolean entryPoint) {
31     this.dependencyRequest = dependencyRequest;
32     this.entryPoint = entryPoint;
33   }
34 
35   @Override
dependencyRequest()36   public DependencyRequest dependencyRequest() {
37     return dependencyRequest;
38   }
39 
40   @Override
isEntryPoint()41   public boolean isEntryPoint() {
42     return entryPoint;
43   }
44 
45   @Override
toString()46   public String toString() {
47     String string =
48         dependencyRequest
49             .requestElement()
50             .map(DaggerElement::xprocessing)
51             .map(ElementFormatter::elementToString)
52             .orElseGet(
53                 () ->
54                     "synthetic request for "
55                         + dependencyRequest.kind().format(dependencyRequest.key()));
56     return entryPoint ? string + " (entry point)" : string;
57   }
58 }
59