• 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 static com.google.common.collect.Iterables.getOnlyElement;
20 import static dagger.internal.codegen.extension.DaggerStreams.presentValues;
21 import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
22 import static java.util.stream.Collectors.joining;
23 
24 import com.google.common.collect.ImmutableSet;
25 import dagger.model.BindingGraph.SubcomponentCreatorBindingEdge;
26 import javax.lang.model.element.TypeElement;
27 
28 /** An implementation of {@link SubcomponentCreatorBindingEdge}. */
29 public final class SubcomponentCreatorBindingEdgeImpl implements SubcomponentCreatorBindingEdge {
30 
31   private final ImmutableSet<SubcomponentDeclaration> subcomponentDeclarations;
32 
SubcomponentCreatorBindingEdgeImpl( ImmutableSet<SubcomponentDeclaration> subcomponentDeclarations)33   SubcomponentCreatorBindingEdgeImpl(
34       ImmutableSet<SubcomponentDeclaration> subcomponentDeclarations) {
35     this.subcomponentDeclarations = subcomponentDeclarations;
36   }
37 
38   @Override
declaringModules()39   public ImmutableSet<TypeElement> declaringModules() {
40     return subcomponentDeclarations.stream()
41         .map(SubcomponentDeclaration::contributingModule)
42         .flatMap(presentValues())
43         .collect(toImmutableSet());
44   }
45 
46   @Override
toString()47   public String toString() {
48     return "subcomponent declared by "
49         + (subcomponentDeclarations.size() == 1
50             ? getOnlyElement(declaringModules()).getQualifiedName()
51             : declaringModules().stream()
52                 .map(TypeElement::getQualifiedName)
53                 .collect(joining(", ", "{", "}")));
54   }
55 }
56