blob: 6f70d03519b6d33615dc85d3290c09b1ede5e007 [file] [log] [blame]
limpbizkit76c24b12008-12-25 04:32:41 +00001/**
2 * Copyright (C) 2008 Google Inc.
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 com.google.inject.internal;
18
limpbizkit03b81a62009-03-18 05:34:39 +000019import com.google.inject.Binder;
limpbizkit76c24b12008-12-25 04:32:41 +000020import com.google.inject.Injector;
21import com.google.inject.Key;
sberlind9c913a2011-06-26 21:02:54 +000022import com.google.common.base.Objects;
23import com.google.common.collect.ImmutableSet;
limpbizkit76c24b12008-12-25 04:32:41 +000024import com.google.inject.spi.BindingTargetVisitor;
25import com.google.inject.spi.Dependency;
26import com.google.inject.spi.ExposedBinding;
limpbizkitc3f92842008-12-30 19:43:47 +000027import com.google.inject.spi.PrivateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000028import java.util.Set;
29
limpbizkit5ae41eb2009-06-06 17:51:27 +000030public final class ExposedBindingImpl<T> extends BindingImpl<T> implements ExposedBinding<T> {
limpbizkit76c24b12008-12-25 04:32:41 +000031
limpbizkitc3f92842008-12-30 19:43:47 +000032 private final PrivateElements privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000033
limpbizkit5ae41eb2009-06-06 17:51:27 +000034 public ExposedBindingImpl(InjectorImpl injector, Object source, Key<T> key,
limpbizkitc3f92842008-12-30 19:43:47 +000035 InternalFactory<T> factory, PrivateElements privateElements) {
limpbizkit76c24b12008-12-25 04:32:41 +000036 super(injector, key, source, factory, Scoping.UNSCOPED);
limpbizkitc3f92842008-12-30 19:43:47 +000037 this.privateElements = privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000038 }
39
limpbizkit8996e802008-12-28 01:44:29 +000040 public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
limpbizkit03b81a62009-03-18 05:34:39 +000041 return visitor.visit(this);
limpbizkit76c24b12008-12-25 04:32:41 +000042 }
43
44 public Set<Dependency<?>> getDependencies() {
45 return ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class)));
46 }
47
limpbizkitc3f92842008-12-30 19:43:47 +000048 public PrivateElements getPrivateElements() {
49 return privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000050 }
51
limpbizkit76c24b12008-12-25 04:32:41 +000052 @Override public String toString() {
sberlind9c913a2011-06-26 21:02:54 +000053 return Objects.toStringHelper(ExposedBinding.class)
limpbizkit76c24b12008-12-25 04:32:41 +000054 .add("key", getKey())
limpbizkit76c24b12008-12-25 04:32:41 +000055 .add("source", getSource())
limpbizkitc3f92842008-12-30 19:43:47 +000056 .add("privateElements", privateElements)
limpbizkit76c24b12008-12-25 04:32:41 +000057 .toString();
58 }
limpbizkit03b81a62009-03-18 05:34:39 +000059
60 public void applyTo(Binder binder) {
61 throw new UnsupportedOperationException("This element represents a synthetic binding.");
62 }
sberlin@gmail.com7bcec882010-06-24 01:03:26 +000063
64 // Purposely does not override equals/hashcode, because exposed bindings are only equal to
65 // themselves right now -- that is, there cannot be "duplicate" exposed bindings.
limpbizkit76c24b12008-12-25 04:32:41 +000066}