blob: 3035def7c90ff4cc26874baba5f0b3a1399edd62 [file] [log] [blame]
dpbd045fc52018-09-18 09:52:17 -07001/*
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
17package dagger.internal.codegen;
18
19import static com.google.common.collect.Iterables.getOnlyElement;
20import static java.util.stream.Collectors.joining;
21
22import com.google.common.collect.ImmutableSet;
23import dagger.model.BindingGraph.SubcomponentBuilderBindingEdge;
24import javax.lang.model.element.TypeElement;
25
26/** An implementation of {@link SubcomponentBuilderBindingEdge}. */
27final class SubcomponentBuilderBindingEdgeImpl implements SubcomponentBuilderBindingEdge {
28
29 private final ImmutableSet<TypeElement> declaringModules;
30
31 SubcomponentBuilderBindingEdgeImpl(Iterable<TypeElement> declaringModules) {
32 this.declaringModules = ImmutableSet.copyOf(declaringModules);
33 }
34
35 @Override
36 public ImmutableSet<TypeElement> declaringModules() {
37 return declaringModules;
38 }
39
40 @Override
41 public String toString() {
42 return "subcomponent declared by "
43 + (declaringModules.size() == 1
44 ? getOnlyElement(declaringModules).getQualifiedName()
45 : declaringModules.stream()
46 .map(TypeElement::getQualifiedName)
47 .collect(joining(", ", "{", "}")));
48 }
49}