Home | History | Annotate | Download | only in internal
      1 /**
      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 
     17 package com.google.inject.internal;
     18 
     19 import com.google.common.base.Objects;
     20 import com.google.common.collect.ImmutableSet;
     21 import com.google.inject.Binder;
     22 import com.google.inject.Injector;
     23 import com.google.inject.Key;
     24 import com.google.inject.spi.BindingTargetVisitor;
     25 import com.google.inject.spi.Dependency;
     26 import com.google.inject.spi.ExposedBinding;
     27 import com.google.inject.spi.PrivateElements;
     28 
     29 import java.util.Set;
     30 
     31 public final class ExposedBindingImpl<T> extends BindingImpl<T> implements ExposedBinding<T> {
     32 
     33   private final PrivateElements privateElements;
     34 
     35   public ExposedBindingImpl(InjectorImpl injector, Object source, Key<T> key,
     36       InternalFactory<T> factory, PrivateElements privateElements) {
     37     super(injector, key, source, factory, Scoping.UNSCOPED);
     38     this.privateElements = privateElements;
     39   }
     40 
     41   public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
     42     return visitor.visit(this);
     43   }
     44 
     45   public Set<Dependency<?>> getDependencies() {
     46     return ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class)));
     47   }
     48 
     49   public PrivateElements getPrivateElements() {
     50     return privateElements;
     51   }
     52 
     53   @Override public String toString() {
     54     return Objects.toStringHelper(ExposedBinding.class)
     55         .add("key", getKey())
     56         .add("source", getSource())
     57         .add("privateElements", privateElements)
     58         .toString();
     59   }
     60 
     61   public void applyTo(Binder binder) {
     62     throw new UnsupportedOperationException("This element represents a synthetic binding.");
     63   }
     64 
     65   // Purposely does not override equals/hashcode, because exposed bindings are only equal to
     66   // themselves right now -- that is, there cannot be "duplicate" exposed bindings.
     67 }
     68