blob: 57ede84438ff3b61bf011dae270d3ba4f282297c [file] [log] [blame]
limpbizkit76c24b12008-12-25 04:32:41 +00001/*
2 * Copyright (C) 2007 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;
limpbizkit5ae41eb2009-06-06 17:51:27 +000020import com.google.inject.Key;
limpbizkit76c24b12008-12-25 04:32:41 +000021import com.google.inject.spi.BindingTargetVisitor;
22import com.google.inject.spi.Dependency;
23import com.google.inject.spi.UntargettedBinding;
24
limpbizkit5ae41eb2009-06-06 17:51:27 +000025final class UntargettedBindingImpl<T> extends BindingImpl<T> implements UntargettedBinding<T> {
limpbizkit76c24b12008-12-25 04:32:41 +000026
limpbizkit5ae41eb2009-06-06 17:51:27 +000027 UntargettedBindingImpl(InjectorImpl injector, Key<T> key, Object source) {
limpbizkit76c24b12008-12-25 04:32:41 +000028 super(injector, key, source, new InternalFactory<T>() {
29 public T get(Errors errors, InternalContext context, Dependency<?> dependency) {
30 throw new AssertionError();
31 }
32 }, Scoping.UNSCOPED);
33 }
34
35 public UntargettedBindingImpl(Object source, Key<T> key, Scoping scoping) {
36 super(source, key, scoping);
37 }
38
limpbizkit8996e802008-12-28 01:44:29 +000039 public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
limpbizkit03b81a62009-03-18 05:34:39 +000040 return visitor.visit(this);
limpbizkit76c24b12008-12-25 04:32:41 +000041 }
42
43 public BindingImpl<T> withScoping(Scoping scoping) {
44 return new UntargettedBindingImpl<T>(getSource(), getKey(), scoping);
45 }
46
47 public BindingImpl<T> withKey(Key<T> key) {
48 return new UntargettedBindingImpl<T>(getSource(), key, getScoping());
49 }
50
limpbizkit03b81a62009-03-18 05:34:39 +000051 public void applyTo(Binder binder) {
52 getScoping().applyTo(binder.withSource(getSource()).bind(getKey()));
53 }
54
limpbizkit76c24b12008-12-25 04:32:41 +000055 @Override public String toString() {
56 return new ToStringBuilder(UntargettedBinding.class)
57 .add("key", getKey())
58 .add("source", getSource())
59 .toString();
60 }
61}