1b71955639ab617e0a4115b1439c8b9982227a018sberlin/**
2b71955639ab617e0a4115b1439c8b9982227a018sberlin * Copyright (C) 2011 Google Inc.
3b71955639ab617e0a4115b1439c8b9982227a018sberlin *
4b71955639ab617e0a4115b1439c8b9982227a018sberlin * Licensed under the Apache License, Version 2.0 (the "License");
5b71955639ab617e0a4115b1439c8b9982227a018sberlin * you may not use this file except in compliance with the License.
6b71955639ab617e0a4115b1439c8b9982227a018sberlin * You may obtain a copy of the License at
7b71955639ab617e0a4115b1439c8b9982227a018sberlin *
8b71955639ab617e0a4115b1439c8b9982227a018sberlin * http://www.apache.org/licenses/LICENSE-2.0
9b71955639ab617e0a4115b1439c8b9982227a018sberlin *
10b71955639ab617e0a4115b1439c8b9982227a018sberlin * Unless required by applicable law or agreed to in writing, software
11b71955639ab617e0a4115b1439c8b9982227a018sberlin * distributed under the License is distributed on an "AS IS" BASIS,
12b71955639ab617e0a4115b1439c8b9982227a018sberlin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b71955639ab617e0a4115b1439c8b9982227a018sberlin * See the License for the specific language governing permissions and
14b71955639ab617e0a4115b1439c8b9982227a018sberlin * limitations under the License.
15b71955639ab617e0a4115b1439c8b9982227a018sberlin */
16b71955639ab617e0a4115b1439c8b9982227a018sberlin
17b71955639ab617e0a4115b1439c8b9982227a018sberlinpackage com.google.inject.grapher;
18b71955639ab617e0a4115b1439c8b9982227a018sberlin
19b71955639ab617e0a4115b1439c8b9982227a018sberlinimport com.google.common.collect.Lists;
20b71955639ab617e0a4115b1439c8b9982227a018sberlinimport com.google.inject.Binding;
21b71955639ab617e0a4115b1439c8b9982227a018sberlinimport com.google.inject.spi.ProviderBinding;
22b71955639ab617e0a4115b1439c8b9982227a018sberlinimport java.util.List;
23b71955639ab617e0a4115b1439c8b9982227a018sberlin
24b71955639ab617e0a4115b1439c8b9982227a018sberlin/**
25b71955639ab617e0a4115b1439c8b9982227a018sberlin * Alias creator that creates an alias for each {@link ProviderBinding}. These {@link Binding}s
26b71955639ab617e0a4115b1439c8b9982227a018sberlin * arise from an {@link InjectionPoint} for the {@link Provider} interface. Since this isn't
27b71955639ab617e0a4115b1439c8b9982227a018sberlin * very interesting information, we don't render this binding on the graph, and just alias the two
28b71955639ab617e0a4115b1439c8b9982227a018sberlin * nodes.
29b71955639ab617e0a4115b1439c8b9982227a018sberlin *
30b71955639ab617e0a4115b1439c8b9982227a018sberlin * @author bojand@google.com (Bojan Djordjevic)
31b71955639ab617e0a4115b1439c8b9982227a018sberlin */
32b71955639ab617e0a4115b1439c8b9982227a018sberlinfinal class ProviderAliasCreator implements AliasCreator {
33b71955639ab617e0a4115b1439c8b9982227a018sberlin  @Override public Iterable<Alias> createAliases(Iterable<Binding<?>> bindings) {
34b71955639ab617e0a4115b1439c8b9982227a018sberlin    List<Alias> aliases = Lists.newArrayList();
35b71955639ab617e0a4115b1439c8b9982227a018sberlin    for (Binding<?> binding : bindings) {
36b71955639ab617e0a4115b1439c8b9982227a018sberlin      if (binding instanceof ProviderBinding) {
37b71955639ab617e0a4115b1439c8b9982227a018sberlin        aliases.add(new Alias(NodeId.newTypeId(binding.getKey()),
38b71955639ab617e0a4115b1439c8b9982227a018sberlin            NodeId.newTypeId(((ProviderBinding<?>) binding).getProvidedKey())));
39b71955639ab617e0a4115b1439c8b9982227a018sberlin      }
40b71955639ab617e0a4115b1439c8b9982227a018sberlin    }
41b71955639ab617e0a4115b1439c8b9982227a018sberlin    return aliases;
42b71955639ab617e0a4115b1439c8b9982227a018sberlin  }
43b71955639ab617e0a4115b1439c8b9982227a018sberlin}
44