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 17package com.google.inject.spi; 18 19import com.google.inject.Binding; 20 21/** 22 * No-op visitor for subclassing. All interface methods simply delegate to {@link 23 * #visitOther(Binding)}, returning its result. 24 * 25 * @param <V> any type to be returned by the visit method. Use {@link Void} with 26 * {@code return null} if no return type is needed. 27 * 28 * @author jessewilson@google.com (Jesse Wilson) 29 * @since 2.0 30 */ 31public abstract class DefaultBindingTargetVisitor<T, V> implements BindingTargetVisitor<T, V> { 32 33 /** 34 * Default visit implementation. Returns {@code null}. 35 */ 36 protected V visitOther(Binding<? extends T> binding) { 37 return null; 38 } 39 40 public V visit(InstanceBinding<? extends T> instanceBinding) { 41 return visitOther(instanceBinding); 42 } 43 44 public V visit(ProviderInstanceBinding<? extends T> providerInstanceBinding) { 45 return visitOther(providerInstanceBinding); 46 } 47 48 public V visit(ProviderKeyBinding<? extends T> providerKeyBinding) { 49 return visitOther(providerKeyBinding); 50 } 51 52 public V visit(LinkedKeyBinding<? extends T> linkedKeyBinding) { 53 return visitOther(linkedKeyBinding); 54 } 55 56 public V visit(ExposedBinding<? extends T> exposedBinding) { 57 return visitOther(exposedBinding); 58 } 59 60 public V visit(UntargettedBinding<? extends T> untargettedBinding) { 61 return visitOther(untargettedBinding); 62 } 63 64 public V visit(ConstructorBinding<? extends T> constructorBinding) { 65 return visitOther(constructorBinding); 66 } 67 68 public V visit(ConvertedConstantBinding<? extends T> convertedConstantBinding) { 69 return visitOther(convertedConstantBinding); 70 } 71 72 @SuppressWarnings("unchecked") 73 public V visit(ProviderBinding<? extends T> providerBinding) { 74 // TODO(cushon): remove raw (Binding) cast when we don't care about javac 6 anymore 75 return visitOther((Binding<? extends T>) (Binding) providerBinding); 76 } 77} 78