| dpb | d045fc5 | 2018-09-18 09:52:17 -0700 | [diff] [blame] | 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; |
| 18 | |
| 19 | import static com.google.common.collect.Iterables.getOnlyElement; |
| 20 | import static java.util.stream.Collectors.joining; |
| 21 | |
| 22 | import com.google.common.collect.ImmutableSet; |
| 23 | import dagger.model.BindingGraph.SubcomponentBuilderBindingEdge; |
| 24 | import javax.lang.model.element.TypeElement; |
| 25 | |
| 26 | /** An implementation of {@link SubcomponentBuilderBindingEdge}. */ |
| 27 | final 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 | } |